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