ASN.1 library for Rust
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Reynard User 8a3fcfdbf5
Some checks failed
test.yml / chore: sync dependencies (monorepo) (push) Failing after 0s
chore: sync dependencies (monorepo)
2026-04-07 18:06:22 +02:00
.github/workflows Bump Minimum Supported Rust Version to 1.60 2026-03-12 15:40:56 +01:00
doc Prepare for travis. 2016-07-02 14:42:41 +09:00
fuzz chore: sync dependencies (monorepo) 2026-04-07 18:06:22 +02:00
src Fix slices and tuples serialization 2024-02-26 17:29:51 +01:00
.gitignore Split ASN.1 module from my TLS implementation. 2016-07-02 12:32:00 +09:00
Cargo.toml chore: sync dependencies (monorepo) 2026-04-06 20:09:32 +02:00
CHANGELOG.md Update CHANGELOG.md for v0.6.0 2026-03-13 14:23:34 +01:00
LICENSE-APACHE Split ASN.1 module from my TLS implementation. 2016-07-02 12:32:00 +09:00
LICENSE-MIT Split ASN.1 module from my TLS implementation. 2016-07-02 12:32:00 +09:00
README.md Bump Minimum Supported Rust Version to 1.60 2026-03-12 15:40:56 +01:00

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.60.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.