Documentation
¶
Overview ¶
Package armor implements OpenPGP ASCII Armor, see RFC 9580 §6. OpenPGP Armor is very similar to PEM except that it may carry a CRC24 checksum line before the end line. The checksum is optional and Decode never rejects a block because of it (RFC 9580 §6.1); Block.CRCValid reports whether a present checksum matches the decoded bytes.
Package armor decodes OpenPGP ASCII-armored blocks (RFC 4880/9580): PEM-like text with a BEGIN/END frame, optional headers, a base64 body and a CRC24 trailer. Only decoding is provided; malformed blocks are skipped and the decoder resumes at the next BEGIN line.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CRC24 ¶ added in v1.0.310
CRC24 returns the OpenPGP checksum of data, as specified in RFC 9580, section 6.1. It is the value carried by the armor checksum line.
Types ¶
type Block ¶
type Block struct {
Type string // The type, taken from the preamble (i.e. "RSA PRIVATE KEY").
Headers map[string]string // Optional headers.
Bytes []byte // The decoded bytes of the contents. Typically a DER encoded ASN.1 structure.
// CRC is the CRC24 checksum from the checksum line. It is meaningful
// only when HasCRC is set.
CRC uint32
// HasCRC reports whether the block had a well-formed checksum line: "="
// followed by four base64 characters. Decode accepts a block without it,
// with a malformed one (HasCRC is false) and with a wrong one (HasCRC is
// true and CRCValid is false), as RFC 9580 §6.1 asks; callers that want
// the checksum enforced check CRCValid.
HasCRC bool
}
A Block represents an OpenPGP armored structure.
The encoded form is:
-----BEGIN Type----- Headers base64-encoded Bytes '=' base64 encoded checksum (optional) -----END Type-----
where Headers is a possibly empty sequence of Key: Value lines.
func Decode ¶
Decode will find the next armored block in the input. It returns that block and the remainder of the input. If no armored data is found, p is nil and the whole of the input is returned in rest. A block whose framing or base64 data is malformed is skipped. The checksum line is optional and never causes a block to be skipped; see Block.HasCRC and Block.CRCValid.