Search results

There are no results.

std.crypto.pem

Parsing of Privacy-Enhanced Main (PEM) files.

This module provides types and methods for parsing PEM files as defined in RFC 7468.

Parsing is done using the PemFile type, which implements std.iter.Iter and supports parsing multiple PEM sections:

import std.crypto.pem (PemFile)
import std.io (Buffer)

let input = '
-----BEGIN PRIVATE KEY-----
aGVsbG8=
-----END PRIVATE KEY-----

-----BEGIN CERTIFICATE-----
aGVsbG8=
-----END CERTIFICATE-----
'

let parser = PemFile.new(Buffer.new(input))

parser.next # => Option.Some(Result.Ok(Item.PrivateKey(...)))
parser.next # => Option.Some(Result.Ok(Item.Certificate(...)))
parser.next # => Option.None

For more information, refer to the documentation of the PemFile type.

Constant-time parsing

The current implementation does not make use of constant-time operations (in the context of cryptography) for parsing, including the base64 encoded data found in PEM files. It's not clear if this matters either, as through timing attacks one should (in the worst case) only be able to derive the size of the base64 encoded data, not the actual data itself.

Classes

Item

A value/section parsed from a PEM file.

ParseError

An error produced while parsing a PEM file.

PemFile

A parser/iterator over the sections in a PEM file.