core/encoding/pem
pem
Types
3Block
Block :: struct {
label: string,
data: [dynamic]u8,
}SourceBlock is a block of PEM encoded data.
Decode_Error
Decode_Error :: enum int {
None = 0,
Bad_Boundary = 1, // Invalid boundary line.
Bad_Label = 2, // Invalid label in BEGIN/END boundary line.
Bad_Data = 3, // Invalid base64 data.
Label_Mismatch = 4, // Label in END boundary line does not match.
Missing_End_Boundary = 5, // End of data without END boundary.
}SourceError
Error :: union {
runtime.Allocator_Error,
Decode_Error,
}SourceConstants
9LABEL_ATTRIBUTE_CERTIFICATE
LABEL_ATTRIBUTE_CERTIFICATE :: "ATTRIBUTE CERTIFICATE"SourceRFC 5755
LABEL_CERTIFICATE
LABEL_CERTIFICATE :: "CERTIFICATE"SourceRFC 5280
LABEL_CERTIFICATE_REQUEST
LABEL_CERTIFICATE_REQUEST :: "CERTIFICATE REQUEST"SourceRFC 2986
LABEL_CMS
LABEL_CMS :: "CMS"SourceRFC 5652
LABEL_ENCRYPTED_PRIVATE_KEY
LABEL_ENCRYPTED_PRIVATE_KEY :: "ENCRYPTED PRIVATE KEY"SourceRFC 5958
LABEL_PKCS7
LABEL_PKCS7 :: "PKCS7"SourceRFC 2315
LABEL_PRIVATE_KEY
LABEL_PRIVATE_KEY :: "PRIVATE KEY"SourceRFC 5208/ RFC 5958
LABEL_PUBLIC_KEY
LABEL_PUBLIC_KEY :: "PUBLIC KEY"SourceRFC 5280
LABEL_X509_CRL
LABEL_X509_CRL :: "X509_CRL"SourceRFC 5280
Procedures
4block_bytes
block_bytes :: proc(blk: ^Block) -> ([]u8)Sourceblock_bytes returns a slice to the Block's data.
block_delete
block_delete :: proc(blk: ^Block)Sourceblock_delete frees a Block returned from decode.
Note: No allocator is specified as decode uses the same allocator for everything.
decode
decode :: proc(data: []u8, allocator: mem.Allocator = context.allocator) -> (blk: ^Block, remaining: []u8, err: Error)Sourcedecode decodes the first encountered PEM block, returning the resulting block, remaining data, and nil if and only if (⟺) the process was successful.
Note: No PEM blocks will result in this procedure returning all nils, and is not considered an error.
encode
encode :: proc(label: string, data: []u8, newline: untyped boolean = false, allocator: mem.Allocator = context.allocator) -> (res: []u8, err: runtime.Allocator_Error)Sourceencode encodes the specified label and data into PEM format.