Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

pem

The pem module encodes and decodes PEM blocks using Go's encoding/pem package.

import "x/encoding/pem"

var block = pem.Block("MESSAGE", "Goblin", {"Source": "example"})
var encoded = block.encode()
var result = pem.decode(encoded)
print(result[0].label)
print(result[1])

Block

Block(label, data, headers={}) constructs a block. data accepts str or Bytes and header keys and values must be strings.

MemberTypeDescription
labelstrPEM block label such as CERTIFICATE
dataBytesDecoded block contents
headersdictOptional PEM headers
encode()BytesEncode the block, including delimiters

The member is named label, rather than Go's Block.Type, because type is a Goblin language keyword.

decode(data) returns [block, rest]. block is nil when no PEM block was found; rest contains all bytes after the decoded block, allowing repeated decoding of concatenated input.