Skip to main content

Crate tsumiki

Crate tsumiki 

Source
Expand description

§tsumiki

Core traits for encoding and decoding in the tsumiki PKI toolkit.

This crate defines the fundamental Decoder and Encoder traits that establish a type-safe conversion pattern used throughout tsumiki.

§Overview

The conversion pattern flows like this:

PEM → Vec<u8> → DER → ASN1Object → Certificate

Each step uses the Decoder trait to convert from one type to the next, and the Encoder trait to convert in the reverse direction.

§Type Safety

The traits use marker traits (DecodableFrom and EncodableTo) to ensure type safety at compile time. This prevents invalid conversions and catches errors early in the development process.

§Example

The following example demonstrates the decoding pattern. Note that specific implementations are provided by the der, asn1, and x509 crates:

use tsumiki::decoder::Decoder;
use tsumiki_der::Der;
use tsumiki_asn1::ASN1Object;

// Decode raw bytes to DER
let bytes = vec![0x30, 0x00];
let der: Der = bytes.decode().unwrap();

// Decode DER to ASN.1
let asn1: ASN1Object = der.decode().unwrap();

Encoding works in the reverse direction:

use tsumiki::encoder::Encoder;
use tsumiki_der::Der;
use tsumiki_asn1::ASN1Object;

// Encode ASN.1 to DER
let asn1 = ASN1Object::new(vec![]);
let der: Der = asn1.encode().unwrap();

// Encode DER to bytes
let bytes: Vec<u8> = der.encode().unwrap();

Modules§

decoder
Decoder trait for type-safe conversions.
encoder
Encoder trait for type-safe conversions.