Skip to content

crypto.pem #

fn 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.

fn 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.

fn new #

deprecated: use Block.new instead
fn new(block_type string) Block

new returns a new Block with the specified block_type

fn Block.new #

fn Block.new(block_type string) Block

Block.new returns a new Block with the specified block_type

fn (Header) str #

fn (header Header) str() string

str returns the string representation of the header

struct Block #

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

fn (Block) 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

fn (Block) free #

unsafe
fn (mut block Block) free()

free the resources taken by the Block block

fn (Block) 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()]

struct EncodeConfig #

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