Help us shape the future of Go! Take the 2026 Go Developer Survey

armor

package
v1.0.316 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

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.

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

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 added in v1.0.310

func (b *Block) CRCValid() bool

CRCValid reports whether the block has a checksum line and its value matches the CRC24 of Bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL