encoding::pem +linux +x86_64

The PEM module implements RFC 7468, commonly known as the PEM format, which is widely used for cryptographic data formats.



// Undocumented types:
type b64stream;
type decoder;
type pemdecoder;
type pemencoder;


fn finish(*decoder) void;
fn newdecoder(io::handle) decoder;
fn newencoder(str, io::handle) (pemencoder | io::error);
fn next(*decoder) ((str, pemdecoder) | io::EOF | io::error);
fn strerror(io::error) const str;


type b64stream[link]

Show undocumented member
type b64stream = struct {
	stream: io::stream,
	in: *bufio::bufstream,

type decoder[link]

Show undocumented member
type decoder = struct {
	in: bufio::bufstream,
	label: strio::stream,
	buf: []u8,

type pemdecoder[link]

Show undocumented member
type pemdecoder = struct {
	stream: io::stream,
	in: *bufio::bufstream,
	b64_in: b64stream,
	b64: base64::decoder,
	// XXX: kind of dumb but it saves us some memory management problems
b64_ready: bool, };

type pemencoder[link]

Show undocumented member
type pemencoder = struct {
	stream: io::stream,
	out: io::handle,
	b64: base64::encoder,
	label: str,
	buf: [48]u8,
	ln: u8,


fn finish[link]

fn finish(dec: *decoder) void;

Frees state associated with this decoder.

fn newdecoder[link]

fn newdecoder(in: io::handle) decoder;

Creates a new PEM decoder. The caller must either read it until it returns io::EOF, or call finish to free state associated with the parser.

fn newencoder[link]

fn newencoder(label: str, s: io::handle) (pemencoder | io::error);

Creates a new PEM encoder stream. The stream has to be closed to write the trailer.

fn next[link]

fn next(dec: *decoder) ((str, pemdecoder) | io::EOF | io::error);

Finds the next PEM boundary in the stream, ignoring any non-PEM data, and returns the label and a pemdecoder from which the encoded data may be read, or io::EOF if no further PEM boundaries are found. The user must completely read the pemdecoder until it returns io::EOF before calling next again.

The label returned by this function is borrowed from the decoder state and does not contain "-----BEGIN " or "-----".

fn strerror[link]

fn strerror(err: io::error) const str;

Converts an I/O error returned from a PEM decoder into a human-friendly string.