Popularity
2.9
Declining
Activity
5.9
-
53
6
10

Programming language: Rust
Tags: Encoding     ASN.1    
Latest version: v0.1.0
Add another 'ASN.1' Package

README

rust-asn1

Build Status Dependency Status

This is a Rust library for parsing ASN.1 data (DER only).

Installation

Add asn1 to the [dependencies] section of your Cargo.toml:

[dependencies]
asn1 = "0.3"

A recent Rust nightly is currently required for const generics.

Usage

To parse a structure like:

Signature ::= SEQUENCE {
    r INTEGER,
    s INTEGER
}

you would write:

let result = asn1::parse(data, |d| {
    return d.read_element::<asn1::Sequence>()?.parse(|d| {
        let r = d.read_element::<u64>()?;
        let s = d.read_element::<u64>()?;
        return Ok((r, s));
    })
});

match result {
    Ok((r, s)) => println("r={}, s={}", r, s),
    Err(e) => println!("Error! {:?}", e),
}