14 releases

0.5.2 Apr 6, 2023
0.5.1 Dec 15, 2022
0.5.0 Feb 2, 2022
0.4.0 Apr 28, 2021
0.1.3 Jul 5, 2016

#32 in Parser implementations

Download history 176317/week @ 2024-07-23 170576/week @ 2024-07-30 197030/week @ 2024-08-06 193533/week @ 2024-08-13 184597/week @ 2024-08-20 195741/week @ 2024-08-27 204742/week @ 2024-09-03 180732/week @ 2024-09-10 174445/week @ 2024-09-17 190956/week @ 2024-09-24 205302/week @ 2024-10-01 183542/week @ 2024-10-08 216302/week @ 2024-10-15 213984/week @ 2024-10-22 196304/week @ 2024-10-29 196529/week @ 2024-11-05

857,158 downloads per month
Used in 1,268 crates (41 directly)

MIT/Apache

250KB
5K SLoC

yasna.rs: ASN.1 library for Rust

Build Status

This is a Rust library for reading and writing ASN.1 data.

Since this library is at an early stage, the APIs are subject to change. However, BERReader and DERWriter functionalities are getting stable.

Serialization/Construction

Serialization in DER (Distinguished Encoding Rules) is supported. It can also be used for serialization in BER (Basic Encoding Rules).

fn main() {
    let der = yasna::construct_der(|writer| {
        writer.write_sequence(|writer| {
            writer.next().write_i64(10);
            writer.next().write_bool(true);
            return Ok(());
        })
    });
    println!("(10, true) = {:?}", der);
}

Currently, these datatypes are supported:

  • BOOLEAN, INTEGER, BITSTRING, OCTETSTRING, NULL, OBJECT IDENTIFIER,
  • SEQUENCE, SEQUENCE OF, SET, SET OF, CHOICE,
  • UTF8String, NumericString, PrintableString, VisibleString, IA5String, BMPString,
  • UTCTime, GeneralizedTime,
  • Explicitly/Implicitly tagged types,
  • DEFAULT/OPTIONAL in SEQUENCE/SET.

These datatypes are not supported:

  • REAL
  • TeletexString, VideotexString, GraphicString, GeneralString, UniversalString,
  • TIME, DATE, TIME-OF-DAY, DATE-TIME, DURATION.

Deserialization/Parsing

Deserialization in BER (Basic Encoding Rules) or DER (Distinguished Encoding Rules) is supported.

fn main() {
    let asn = yasna::parse_der(&[48, 6, 2, 1, 10, 1, 1, 255], |reader| {
        reader.read_sequence(|reader| {
            let i = reader.next().read_i64()?;
            let b = reader.next().read_bool()?;
            return Ok((i, b));
        })
    }).unwrap();
    println!("{:?} = [48, 6, 2, 1, 10, 1, 1, 255]", asn);
}

Currently, these datatypes are supported:

  • BOOLEAN, INTEGER, BITSTRING, OCTETSTRING, NULL, OBJECT IDENTIFIER,
  • SEQUENCE, SEQUENCE OF, SET, SET OF, CHOICE,
  • UTF8String, NumericString, PrintableString, VisibleString, IA5String, BMPString,
  • UTCTime, GeneralizedTime,
  • Explicitly/Implicitly tagged types,
  • DEFAULT/OPTIONAL in SEQUENCE.

These datatypes are not supported:

  • REAL
  • TeletexString, VideotexString, GraphicString, GeneralString, UniversalString,
  • TIME, DATE, TIME-OF-DAY, DATE-TIME, DURATION.
  • DEFAULT/OPTIONAL in SET.

Other encodings

This library is currently specialized for BER (Basic Encoding Rules) and DER (Distinguished Encoding Rules). Other encodings such as CER (Canonical Encoding Rules), PER (Packed Encoding Rules), and XER (XML Encoding Rules) are currently out of scope.

Streaming

This library is currently specialized for on-memory serialization/deserialization. There are no plans for streaming ones.

Compatibility

The minimum supported Rust version (MSRV) of yasna.rs is Rust 1.36.0. Optional feature flags that enable interoperability with third-party crates (e.g. time) follow the policy of that crate if stricter.

License

This library is distributed under MIT/Apache-2.0 dual license.

Dependencies

~0–310KB