58 releases
| 0.24.1 | Mar 21, 2026 |
|---|---|
| 0.23.1 | Feb 11, 2026 |
| 0.23.0 | Oct 8, 2025 |
| 0.22.0 | Jun 20, 2025 |
| 0.1.0 | Jul 21, 2015 |
#30 in Cryptography
401,682 downloads per month
Used in 20 crates
(14 directly)
235KB
6K
SLoC
rust-asn1
This is a Rust library for parsing and generating ASN.1 data (DER only).
Installation
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
Changelog
Unreleased
[0.24.1]
Added
- Added
Tlv::tag_bytes()which returns the DER-encoded bytes of the tag portion of a TLV. (#608)
Fixes
- Fixed encoding a
Setwith absent optional fields incorrectly returningInvalidSetOrdering. (#607)
[0.24.0]
Added
- Added
Set,SetWriter, andSetElementWritertypes for parsing and writing ASN.1SETvalues with DER ordering validation. (#600) - Added an associated error type to the
Asn1Writable,SimpleAsn1WritableandAsn1DefinedByWritabletraits. Types implementing these traits can now return a custom error type during serialization, as long as the error type is convertible toWriteError. (#597) - Added
BigInt::bit_length()andOwnedBigInt::bit_length()which return the number of significant bits in the integer's magnitude (absolute value). (#603) - Added
ObjectIdentifier::as_der(). (#598)
Changes
SequenceWriteris now generic over the error type, which defaults toWriteError. (#601)
Removed
Tag::write_tohas been removed from the public API. (#604)
[0.23.1]
Added
Tagnow exposes awrite_tomethod that writes the tag's encoded representation to aWriteBuf.
[0.23.0]
Added
-
Writernow exposeswrite_explicit_elementandwrite_implicit_elementmethods that allow encoding EXPLICIT/IMPLICIT elements when the tag number is not known at compile time. -
NonZeronumbers now implementAsn1Writable.
Changes
- Updated MSRV to 1.83.0.
[0.22.0]
Added
- Added
Asn1Writable::encoded_length,SimpleAsn1Writable::data_length, andAsn1DefinedByWritable::encoded_length. Implementing these functions reduces the number of re-allocations required when writing.Nonecan be returned if it is not possible to provide an efficient implementation.
Changes
- Updated MSRV to 1.74.0.
[0.21.3]
Added
BitString::newis nowconst fn.
[0.21.2]
Added
BigInt::new,BigUint::new, andDateTime::neware nowconst fn.
[0.21.1]
Added
Parsernow exposes apeek_tagmethod that returns the tag of the next element in the parse, without consuming that element. (#532)Parsernow exposesread_explicit_elementandread_implicit_elementmethods that allow parsing EXPLICIT/IMPLICIT elements when the tag number is not known at compile time.PrintableString,Utf8String,BMPString, andUniversalStringnow#[derive(Hash)]. (#536)
[0.21.0]
Changes
- Updated MSRV to 1.65.0.
Fixes
- Fixed "perfect derives"
in conjunction with
#[derive(Asn1DefinedByRead)]and#[derive(Asn1DefinedByWrite)]. (#506)
[0.20.0]
🚨 Breaking changes
- Removed
Writer::{write_explicit_element, write_optional_explicit_element, write_implicit_element, write_optional_implicit_element}. These can all be better accomplished with theasn1::Explicitandasn1::Implicittypes.
Fixes
- Fixed "perfect derives"
in conjunction with
#[implicit]and#[explicit]. (#502)
[0.19.0]
🚨 Breaking changes
-
GeneralizedTimehas been renamed toX509GeneralizedTime. The type does not allow fractional seconds, however this restriction is not actually a DER rule, it is specific to X.509. (#494) -
GeneralizedTimeis a new type that accepts fractional seconds replacing the oldGeneralizedTime. (#492) -
#[derive(asn1::Asn1Read)]and#[derive(asn1::Asn1Write)]now implement "perfect derives". (#496)
Dependencies
~115–490KB
~12K SLoC