This is a Rust library for parsing and generating ASN.1 data (DER only).
Add asn1 to your Cargo.toml:
$ cargo add asn1
Builds on Rust 1.83.0 and newer.
rust-asn1 is compatible with #![no_std] environments:
$ cargo add asn1 --no-default-features
Tlv::tag_bytes() which returns the DER-encoded bytes
of the tag portion of a TLV. (#608)Set with absent optional fields incorrectly
returning InvalidSetOrdering. (#607)Set, SetWriter, and SetElementWriter types for parsing and
writing ASN.1 SET values with DER ordering validation.
(#600)Asn1Writable, SimpleAsn1Writable
and Asn1DefinedByWritable traits. Types implementing these traits can
now return a custom error type during serialization, as long as the error
type is convertible to WriteError. (#597)BigInt::bit_length() and OwnedBigInt::bit_length() which return
the number of significant bits in the integer's magnitude (absolute value).
(#603)ObjectIdentifier::as_der(). (#598)SequenceWriter is now generic over the error type, which defaults to
WriteError. (#601)Tag::write_to has been removed from the public API.
(#604)Tag now exposes a write_to method that writes the tag's encoded
representation to a WriteBuf.Writer now exposes write_explicit_element and write_implicit_element
methods that allow encoding EXPLICIT/IMPLICIT elements when the tag number
is not known at compile time.
NonZero numbers now implement Asn1Writable.
Asn1Writable::encoded_length, SimpleAsn1Writable::data_length, and
Asn1DefinedByWritable::encoded_length. Implementing these functions reduces
the number of re-allocations required when writing. None can be returned if
it is not possible to provide an efficient implementation.BitString::new is now const fn.BigInt::new, BigUint::new, and DateTime::new are now const fn.Parser now exposes a peek_tag method that returns the tag of the next
element in the parse, without consuming that element.
(#532)Parser now exposes read_explicit_element and read_implicit_element
methods that allow parsing EXPLICIT/IMPLICIT elements when the tag number
is not known at compile time.PrintableString, Utf8String, BMPString, and UniversalString now
#[derive(Hash)]. (#536)#[derive(Asn1DefinedByRead)] and
#[derive(Asn1DefinedByWrite)].
(#506)Writer::{write_explicit_element, write_optional_explicit_element, write_implicit_element, write_optional_implicit_element}.
These can all be better accomplished with the asn1::Explicit and
asn1::Implicit types.#[implicit] and #[explicit].
(#502)GeneralizedTime has been renamed to X509GeneralizedTime. The type does
not allow fractional seconds, however this restriction is not actually a DER
rule, it is specific to X.509.
(#494)
GeneralizedTime is a new type that accepts fractional seconds
replacing the old GeneralizedTime.
(#492)
#[derive(asn1::Asn1Read)] and #[derive(asn1::Asn1Write)] now implement
"perfect derives".
(#496)
$ claude mcp add rust-asn1 \
-- python -m otcore.mcp_server <graph>