Skip to content

rasn 0.3.0

Compare
Choose a tag to compare
@XAMPPRocky XAMPPRocky released this 18 Jul 19:30
· 431 commits to main since this release

Hello everyone, I'm proud to announce the 0.3.0 of rasn! rasn is a #[no_std] codec framework for the ASN.1 data model and encoding rules. Allowing you to safely and easily parse data formats such as BER, CER, and DER in safe Rust.

Sponsorship

Work on rasn is funded through the support of contributors on GitHub Sponsors. If you would like support work on rasn, tokei, or my other open source projects, contributions are always welcome, appreciated, and make a direct impact on my ability to build new projects as well support existing ones.

New Crates

This release was focused on building implementations of standards that use these formats as their underlying protocol, which is why I'm also happy to announce the release of three new sibling crates, rasn-smi, rasn-mib, and rasn-snmp. These crates provide the types needed to be able to decode and encode Simple Network Management Protocol (SNMP) messages, SMI object syntax, and MIB objects. It's important to note that this does not contain a implementation of an SNMP proxy or manager, but provides the data types needed to build one. Like rasn, these crates are entirely #[no_std] and are transport-layer and encoding rule agnostic written in 100% safe Rust.

As an example, let's say we wanted to store our SNMPv2c messages containing SNMPv2 Protocol Data Units (PDUs), but we wanted to ensure when is saved it is encoded in DER so that it is "canonical" (meaning the same value always produces the same encoding), but we need to be able to accept messages in BER. Here's how you'd write that with rasn.

use rasn_smi::{v2c::Message, v2::Pdus};

// The SNMP data we received from the wire.
let data = &[...];

// Decode BER message.
let message: Message<Pdus> = rasn::ber::decode(data)?;

// Re-encode it as DER.
let der_data = rasn::der::encode(&message)?;

That's it! All the complexity in encoding and decoding is completely abstracted by the types, letting us focus on the actual implementation of our agent.

With this release, the initial set of Management Information Base (MIB) objects covers the most of what was defined in RFC 3418. Contributions adding more MIB objects from IETF RFCs are both welcome and appreciated.

New Additions

  • Added support for all [T; N] array types for AsnType, Decode, and Encode.
  • Added the Oid type which is reference type equivalent for ObjectIdentifier, and ConstOid, which allows you to define object identifiers in const contexts.
  • Added #[rasn(delegate)] container attribute which is accepted on single value newtype structs (e.g. struct Foo(u8);). This will cause the implementation of of any of the derive macros to directly encode and decode the inner type, and to ignore the wrapper.
  • Added #[rasn(choice)] field attribute which specifies to decode a given field as a CHOICE type.
  • Added #[rasn(default)] field attribute which will use the Default value if it cannot parse the given field.
  • Added the Incomplete error variant to de::Error that provides how many more bytes are needed to potentially decode the message.
  • Added the ExceedsMaxLength error variant to de::Error that provides an error when a list-like type (SEQUENCE OF) is encoded correctly but it's length exceeds the maximum allowed by the type.

Breaking Changes

  • Decoder::decode_sequence, no longer returns a Deocder and instead accepts a FnOnce(Decoder) -> Result<Self> function to decode the sequence. This is needed in order to correctly handle nested indefinite length sequences in CER.