module

Beryl::Encoding::PrivacyEnhancedMail

Reads PEM, the textual encoding of RFC 7468: blocks of base64 between -----BEGIN LABEL----- and -----END LABEL----- lines.

The reader takes the strict form of RFC 7468 §3 with the leniencies its §5.2 allows: text outside the blocks is ignored (so a file can carry comments or openssl x509 -text output), lines may end in LF or CRLF, and base64 lines may be of any length. Inside a block only base64 characters and whitespace may appear, and the END label must match the BEGIN label.

Beryl::Encoding::PEM.decode(File.read("chain.pem"), label: "CERTIFICATE") # => Array(Bytes)

Constants

LARGEST_TEXT_BYTESIZE = (4 * 1024) * 1024

The largest PEM text the reader takes, 4 MiB (the Mozilla root set is about 250 KB; a certificate chain a few KB).

Class methods

decode(text : String, *, label : String) : Array(Bytes)

Returns the bytes of every block labeled label in text, ignoring blocks with other labels.

Source
decode_blocks(text : String, *, largest_text_bytesize : Int32 = LARGEST_TEXT_BYTESIZE) : Array(Block)

Returns every block in text, in order. Raises MalformedEncoding for a block that is not well formed and LimitExceeded when the text is larger than LARGEST_TEXT_BYTESIZE.

Source
encode(bytes : Bytes, *, label : String) : String

Returns bytes as one PEM block labeled label, with 64-character lines (RFC 7468 §2).

Source

Nested types