3.2 KiB
armor
import "github.com/effective-security/xpki/armor"
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
func CRC24
func CRC24(data []byte) uint32
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.
type Block
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.
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
}
func Decode
func Decode(data []byte) (p *Block, rest []byte)
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.
func (*Block) CRCValid
func (b *Block) CRCValid() bool
CRCValid reports whether the block has a checksum line and its value matches the CRC24 of Bytes.
Generated by gomarkdoc