Skip to main content

Crate tsumiki_pem

Crate tsumiki_pem 

Source
Expand description

§tsumiki-pem

PEM (Privacy Enhanced Mail) format handling for cryptographic data.

This crate implements RFC 7468 for encoding and decoding PEM format.

§What is PEM?

PEM is a text-based format for encoding binary data. It wraps base64-encoded data with boundary markers like:

-----BEGIN CERTIFICATE-----
MIIBkTCB+wIJAKHHCgVZU...
-----END CERTIFICATE-----

§Supported Labels

  • CERTIFICATE - X.509 certificates
  • PRIVATE KEY - PKCS#8 private keys
  • ENCRYPTED PRIVATE KEY - PKCS#8 encrypted private keys
  • RSA PRIVATE KEY - PKCS#1 RSA private keys
  • EC PRIVATE KEY - SEC1 EC private keys
  • PUBLIC KEY - X.509 SubjectPublicKeyInfo
  • RSA PUBLIC KEY - PKCS#1 RSA public keys

§Example

use std::str::FromStr;
use tsumiki_pem::{Pem, Label};

let pem_text = "-----BEGIN CERTIFICATE-----\nAAA=\n-----END CERTIFICATE-----";
let pem = Pem::from_str(pem_text)?;

assert_eq!(pem.label(), Label::Certificate);

§Decoding to Raw Bytes

use std::str::FromStr;
use tsumiki::decoder::Decoder;
use tsumiki_pem::Pem;

let pem_text = "-----BEGIN CERTIFICATE-----\nAAA=\n-----END CERTIFICATE-----";
let pem = Pem::from_str(pem_text)?;

// Decode to raw bytes
let bytes: Vec<u8> = pem.decode()?;

Modules§

error

Structs§

Pem
A PEM-encoded data structure.

Enums§

Label
PEM label identifying the type of data enclosed.

Traits§

FromPem
Trait for types that can be constructed from PEM format
ToPem
Trait for types that can be converted to PEM format

Functions§

parse_many
Parse multiple PEM blocks from a string.