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.
- SEQUENCE/SET
ber::serial::seq - SEQUENCE/SET OF
ber::serial::seq_of - CHOICE/ANY
ber::serial::choice - A ::= B
ber::serial::alias - OCTET STRING
ber::serial::prim
§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.