MCPcopy Index your code
hub / github.com/alex/rust-asn1

github.com/alex/rust-asn1 @0.24.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.24.1 ↗ · + Follow
449 symbols 926 edges 17 files 52 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rust-asn1

Dependency Status Documentation

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 Set with absent optional fields incorrectly returning InvalidSetOrdering. (#607)

[0.24.0]

Added

  • Added Set, SetWriter, and SetElementWriter types for parsing and writing ASN.1 SET values with DER ordering validation. (#600)
  • Added an associated error type to the 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)
  • Added BigInt::bit_length() and OwnedBigInt::bit_length() which return the number of significant bits in the integer's magnitude (absolute value). (#603)
  • Added ObjectIdentifier::as_der(). (#598)

Changes

  • SequenceWriter is now generic over the error type, which defaults to WriteError. (#601)

Removed

  • Tag::write_to has been removed from the public API. (#604)

[0.23.1]

Added

  • Tag now exposes a write_to method that writes the tag's encoded representation to a WriteBuf.

[0.23.0]

Added

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

Changes

  • Updated MSRV to 1.83.0.

[0.22.0]

Added

  • Added 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.

Changes

  • Updated MSRV to 1.74.0.

[0.21.3]

Added

  • BitString::new is now const fn.

[0.21.2]

Added

  • BigInt::new, BigUint::new, and DateTime::new are now const fn.

[0.21.1]

Added

  • 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)

[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]

:rotating_light: 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 the asn1::Explicit and asn1::Implicit types.

Fixes

[0.19.0]

:rotating_light: Breaking changes

  • 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)

Extension points exported contracts — how you extend this code

SimpleAsn1Readable (Interface)
Types with a fixed-tag that can be parsed as DER ASN.1 [29 implementers]
src/types.rs
X (Interface)
(no doc) [2 implementers]
tests/derive_test.rs
OptionExt (Interface)
(no doc) [1 implementers]
src/lib.rs
SimpleAsn1Writable (Interface)
Types with a fixed-tag that can be written as DER ASN.1. [35 implementers]
src/types.rs
Asn1Writable (Interface)
Any type that can be written as DER ASN.1. [5 implementers]
src/types.rs
Asn1Readable (Interface)
Any type that can be parsed as DER ASN.1. [4 implementers]
src/types.rs
Asn1DefinedByReadable (Interface)
A trait for types that can be parsed based on a `DEFINED BY` value. `T` is the type of the `DEFINED BY` field (nearly a [1 …
src/types.rs

Core symbols most depended-on inside this repo

len
called by 50
src/types.rs
add_location
called by 37
src/parser.rs
clone
called by 37
src/types.rs
parse
called by 22
src/parser.rs
push_byte
called by 22
src/writer.rs
as_bytes
called by 21
src/types.rs
push_slice
called by 19
src/writer.rs
is_empty
called by 17
src/types.rs

Shape

Function 260
Method 98
Class 66
Enum 17
Interface 8

Languages

Rust100%

Modules by API surface

src/types.rs129 symbols
src/parser.rs81 symbols
src/writer.rs77 symbols
tests/derive_test.rs60 symbols
asn1_derive/src/lib.rs29 symbols
src/tag.rs18 symbols
src/object_identifier.rs12 symbols
src/bit_string.rs12 symbols
tests/roundtrip_tests.rs6 symbols
src/lib.rs6 symbols
src/base128.rs5 symbols
tests/oid_tests.rs3 symbols

For agents

$ claude mcp add rust-asn1 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact