Crate yasna[−][src]
A library for reading and writing ASN.1 data.
Examples
Encoding/decoding simple data
A type implementing DEREncodable
can be easily encoded:
extern crate yasna; fn main() { let der = yasna::encode_der(&(10, true)); println!("(10, true) = {:?}", der); }
Similarly, a type implementing BERDecodable
can be
easily decoded:
extern crate yasna; fn main() { let asn: (i64, bool) = yasna::decode_der( &[48, 6, 2, 1, 10, 1, 1, 255]).unwrap(); println!("{:?} = [48, 6, 2, 1, 10, 1, 1, 255]", asn); }
Encoding/decoding by hand
Default DEREncodable
/BERDecodable
implementations can’t handle
all ASN.1 type. In many cases you have to write your reader/writer
by hand.
To serialize ASN.1 data, you can use construct_der
.
extern crate yasna; fn main() { let der = yasna::construct_der(|writer| { writer.write_sequence(|writer| { writer.next().write_i64(10); writer.next().write_bool(true); }) }); println!("(10, true) = {:?}", der); }
To deserialize ASN.1 data, you can use parse_ber
or parse_der
.
extern crate yasna; fn main() { let asn = yasna::parse_der(&[48, 6, 2, 1, 10, 1, 1, 255], |reader| { reader.read_sequence(|reader| { let i = try!(reader.next().read_i64()); let b = try!(reader.next().read_bool()); return Ok((i, b)); }) }).unwrap(); println!("{:?} = [48, 6, 2, 1, 10, 1, 1, 255]", asn); }
Modules
models | Provides datatypes which correspond to ASN.1 types. |
tags | Provides universal tag constants. |
Structs
ASN1Error | |
BERReader | A reader object for BER/DER-encoded ASN.1 data. |
BERReaderSeq | A reader object for a sequence of BER/DER-encoded ASN.1 data. |
BERReaderSet | A reader object for a set of BER/DER-encoded ASN.1 data. |
DERWriter | A writer object that accepts an ASN.1 value. |
DERWriterSeq | A writer object that accepts ASN.1 values. |
DERWriterSet | A writer object that accepts ASN.1 values. |
Tag | An ASN.1 tag. |
Enums
ASN1ErrorKind | |
BERMode | Used by |
PCBit | A value of the ASN.1 primitive/constructed (“P/C”) bit. |
TagClass | An ASN.1 tag class, used in |
Traits
BERDecodable | Types decodable in BER. |
DEREncodable | Types encodable in DER. |
Functions
construct_der | Constructs DER-encoded data as |
construct_der_seq | Constructs DER-encoded sequence of data as |
decode_ber | Reads an ASN.1 value from |
decode_ber_general | Decodes DER/BER-encoded data. |
decode_der | Reads an ASN.1 value from |
encode_der | Encodes a value to DER-encoded ASN.1 data. |
parse_ber | Parses BER-encoded data. |
parse_ber_general | Parses DER/BER-encoded data. |
parse_der | Parses DER-encoded data. |
try_construct_der | Tries to construct DER-encoded data as |
try_construct_der_seq | Tries to construct a DER-encoded sequence of data as |
Type Definitions
ASN1Result |