package core:encoding/pem
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:
Index
Types (3)
Variables (0)
This section is empty.
Procedures (4)
Procedure Groups (0)
This section is empty.
Types
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, }
Constants
Variables
This section is empty.
Procedures
block_bytes ¶
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