Crate asn1_cereal

Source
Expand description

§asn1-cereal

A collection of encoders and decoders for BER, DER and ASN.1.

The grains of this library are a collection of traits and macros, that allow serialization and deserialization of rust types to and from ASN.1.

The Asn1Info, BerSerialize and BerDeserialize traits are what most users will want to use.

§ASN.1 Elements

These pages will provide more details on specific ASN.1 constructs.

§Example

#[macro_use] extern crate asn1_cereal; fn main() {
  struct ShortSequence {
    z: u64,
    y: u32,
  }

  ber_sequence!(
    ShortSequence,
    "SHORT_SEQUENCE",
    z;
    y;
  );

  use asn1_cereal::BerSerialize;

  let data = ShortSequence{ z: 1, y: 2 };
  let mut bytes: Vec<u8> = Vec::new();
  BerSerialize::serialize(&data, &mut bytes).unwrap();
}

Re-exports§

pub use info::Asn1Info;
pub use ber::serial::traits::BerSerialize;
pub use ber::serial::traits::BerDeserialize;
pub use ber::enc::BER;
pub use ber::enc::DER;
pub use ber::enc::BERAlt;
pub use ber::enc::BerEncRules;
pub use ber::serial::prim::OctetString;

Modules§

ber
Tools that can be used to parse BER streams.
byte
Constructs for reading and writing bytes used by this crate.
err
Encoding and Decoding errors that this crate can produce.
info
tag
Encoding and decoding of tag and length bytes for BER.

Macros§

asn1_info
This macro defines the Asn1Info trait for a rust type.
asn1_sequence_info
This macro defines the Asn1Info trait for a rust struct. This allows the other traits to get information about this type. If you need to provide a custom class or tag, consider using the asn1_info! macro.
asn1_spec_tag
This macro parses an ASN.1 tag specification, and returns the appropriate Tag.
ber_alias
Generate the implemention of an ASN.1 alias for a Rust type.
ber_alias_deserialize
This macro defines the BerSerialize trait for an ASN.1 type alias.
ber_alias_info
Generate the Asn1Info implemention of an ASN.1 alias for a Rust type.
ber_alias_serialize
This macro defines the BerSerialize trait for an ASN.1 type alias.
ber_choice
Generate the Asn1Info implemention for an ASN.1 Choice type, represented by a Rust enum.
ber_choice_deserialize
Generate the BerDeserialize implemention for an ASN.1 Choice type, represented by a Rust enum.
ber_choice_serialize
Generate the BerSerialize implemention for an ASN.1 Choice type, represented by a Rust enum.
ber_sequence
This macro is a compact way of defining all three of the Asn1 traits - Asn1Info, BerSerialize and BerDeserialize - for a rust struct, that represents an ASN.1 sequence.
ber_sequence_deserialize
This macro defines the BerDeserialize trait for a rust struct. The code generated will deserialize the specified fields in the order that they are given.
ber_sequence_of
Generate a SEQUENCE OF implementation for an iterator type. asn1_info! must be called manually.
ber_sequence_of_deserialize
Implement BerDeserialize for a type, by collecting the elements from an iterator built by calling deserialize_enc on the stream continually.
ber_sequence_of_serialize
Implement BerSerialize for a type, by iterating over each element, and calling serialize_enc on each element.
ber_sequence_serialize
This macro defines the BerSerialize trait for a rust struct. The code generated will serialize the specified fields in the order that they are given.