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 #
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
enum 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
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 #
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 #
struct EncodeConfig {
pub mut:
// inner text wrap around
line_length int = 64
// line ending (alternatively '\r\n')
line_ending string = '\n'
}