Files
herolib/aiprompts/v_core/crypto/pem.md
2025-09-02 07:28:13 +02:00

2.7 KiB

module pem

Contents

decode

fn decode(data string) ?(Block, string)

decode reads data and returns the first parsed PEM Block along with the rest of the string. none is returned when a header is expected, but not present or when a start of '-----BEGIN' or end of '-----END' can't be found.

use decode_only if you do not need the unparsed rest of the string.

[Return to contents]

decode_only

fn decode_only(data string) ?Block

decode_only reads data and returns the first parsed PEM Block. none is returned when a header is expected, but not present or when a start of '-----BEGIN' or end of '-----END' can't be found.

use decode if you still need the unparsed rest of the string.

[Return to contents]

Block.new

fn Block.new(block_type string) Block

Block.new returns a new Block with the specified block_type

[Return to contents]

Header

enum Header {
	proctype
	contentdomain
	dekinfo
	origid_asymm
	origid_symm
	recipid_asymm
	recipid_symm
	cert
	issuercert
	micinfo
	keyinfo
	crl
}

Headers as described in RFC 1421 Section 9

[Return to contents]

str

fn (header Header) str() string

str returns the string representation of the header

[Return to contents]

Block

struct Block {
pub mut:
	// from preamble
	block_type string
	// optional headers
	headers map[string][]string
	// decoded contents
	data []u8
}

[Return to contents]

encode

fn (block Block) encode(config EncodeConfig) !string

encode encodes the given block into a string using the EncodeConfig. It returns an error if block_type is undefined or if a value in headers contains an invalid character ':'

default EncodeConfig values wrap lines at 64 bytes and use '\n' for newlines

[Return to contents]

free

fn (mut block Block) free()

free the resources taken by the Block block

[Return to contents]

header_by_key

fn (block Block) header_by_key(key Header) []string

header_by_key returns the selected key using the Header enum

same as block.headers[key.str()]

[Return to contents]

EncodeConfig

struct EncodeConfig {
pub mut:
	// inner text wrap around
	line_length int = 64
	// line ending (alternatively '\r\n')
	line_ending string = '\n'
}

[Return to contents]

Powered by vdoc. Generated on: 2 Sep 2025 07:18:17