1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 18:56:52 +03:00
fq/format/crypto/pem.jq
Mattias Wadman cae288e6be format,intepr: Refactor json, yaml, etc into formats also move out related functions
json, yaml, toml, xml, html, csv are now normal formats and most of them also particiate
in probing (not html and csv).

Also fixes a bunch of bugs in to/fromxml, to/fromjq etc.
2022-07-23 21:48:45 +02:00

20 lines
501 B
Plaintext

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