package core:encoding/pem

⌘K
Ctrl+K
or
/

    Overview

    Encodes and decodes PEM formatted data.

    decode only accepts the strict format of RFC 7468 (Figure 3): the base64 text is split into lines of exactly 64 characters, except the last, which may be shorter. Padding may only end the last line, and trailing bits must be zero. Inside a block, blank lines, whitespace other than line endings, and RFC 1421 headers are rejected. Labels must follow the RFC 7468 grammar, and the END label must match the BEGIN label. Lines may end in CRLF, CR or LF, and the newline after the END line is optional. Text before a block is skipped.

    See:

    Types

    Block ¶

    Block :: struct {
    	label: string,
    	data:  [dynamic]u8,
    }
     

    Block is a block of PEM encoded data.

    Related Procedures With Parameters

    Decode_Error ¶

    Decode_Error :: enum int {
    	None, 
    	Bad_Boundary,         // Invalid boundary line.
    	Bad_Label,            // Invalid label in BEGIN/END boundary line.
    	Bad_Data,             // Invalid base64 data.
    	Label_Mismatch,       // Label in END boundary line does not match.
    	Missing_End_Boundary, // End of data without END boundary.
    }

    Error ¶

    Error :: union {
    	runtime.Allocator_Error, 
    	Decode_Error, 
    }

    Related Procedures With Returns

    Constants

    LABEL_ATTRIBUTE_CERTIFICATE ¶

    LABEL_ATTRIBUTE_CERTIFICATE :: "ATTRIBUTE CERTIFICATE"
     

    RFC 5755

    LABEL_CERTIFICATE ¶

    LABEL_CERTIFICATE :: "CERTIFICATE"
     

    RFC 5280

    LABEL_CERTIFICATE_REQUEST ¶

    LABEL_CERTIFICATE_REQUEST :: "CERTIFICATE REQUEST"
     

    RFC 2986

    LABEL_CMS ¶

    LABEL_CMS :: "CMS"
     

    RFC 5652

    LABEL_ENCRYPTED_PRIVATE_KEY ¶

    LABEL_ENCRYPTED_PRIVATE_KEY :: "ENCRYPTED PRIVATE KEY"
     

    RFC 5958

    LABEL_PKCS7 ¶

    LABEL_PKCS7 :: "PKCS7"
     

    RFC 2315

    LABEL_PRIVATE_KEY ¶

    LABEL_PRIVATE_KEY :: "PRIVATE KEY"
     

    RFC 5208/ RFC 5958

    LABEL_PUBLIC_KEY ¶

    LABEL_PUBLIC_KEY :: "PUBLIC KEY"
     

    RFC 5280

    LABEL_X509_CRL ¶

    LABEL_X509_CRL :: "X509 CRL"
     

    RFC 5280

    Variables

    This section is empty.

    Procedures

    block_bytes ¶

    block_bytes :: proc(blk: ^Block) -> []u8 {…}
     

    block_bytes returns a slice to the Block's data.

    block_delete ¶

    block_delete :: proc(blk: ^Block) {…}
     

    block_delete frees a Block returned from decode.

    Note: No allocator is specified as decode uses the same allocator for everything.

    decode ¶

    @(require_results)
    decode :: proc(
    	data:      []u8, 
    	allocator := context.allocator, 
    ) -> (blk: ^Block, remaining: []u8, err: Error) {…}
     

    decode decodes the first encountered PEM block, returning the resulting block, remaining data, and nil iff the process was successful.

    Lines before the block that start with "-----BEGIN " but are not a valid boundary are skipped. If no valid block follows, the error from the first such line is returned.

    Note: No PEM blocks will result in this procedure returning all nils, and is not considered an error.

    encode ¶

    @(require_results)
    encode :: proc(
    	label:     string, 
    	data:      []u8, 
    	newline:   bool = true, 
    	allocator := context.allocator, 
    ) -> (res: []u8, err: Error) {…}
     

    encode encodes the specified label and data into PEM format. It returns .Bad_Label if the label does not follow the RFC 7468 label grammar. With newline set (the default), the output ends with a newline after the END line, as the strict format requires.

    Procedure Groups

    This section is empty.

    Source Files

    Generation Information

    Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-18 21:05:19.828955300 +0000 UTC