1
1
mirror of https://github.com/wader/fq.git synced 2024-11-29 23:27:12 +03:00
fq/format/crypto/pem.jq

20 lines
507 B
Plaintext
Raw Normal View History

# https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail
def from_pem:
( tobytes
| tostring
| capture("-----BEGIN(.*?)-----(?<s>.*?)-----END(.*?)-----"; "mg").s
| _from_base64({encoding: "std"})
) // error("no pem header or footer found");
def to_pem($label):
( tobytes
| _to_base64({encoding: "std"})
| ($label | if $label != "" then " " + $label end) as $label
| [ "-----BEGIN\($label)-----"
, .
, "-----END\($label)-----"
, ""
]
| join("\n")
);
def to_pem: to_pem("");