[][src]Crate red_asn1

A little library to encode/decode ASN1 DER

Example

/*
Person ::= [APPLICATION 1] SEQUENCE {
    name:       [0] GeneralString,
    age:        [1] Integer,
    address:    [2] GeneralString OPTIONAL,
}
*/
 
use red_asn1::*;
 
#[derive(Sequence)]
#[seq(application_tag = 1)]
struct Person {
    #[seq_field(context_tag = 0)]
    name: SeqField<GeneralString>,
    #[seq_field(context_tag = 1)]
    age: SeqField<Integer>,
    #[seq_field(context_tag = 2, optional)]
    address: SeqField<GeneralString>
}
 
let mut person = Person{
    name: GeneralString::from("John").into(),
    age: Integer::from(18).into(),
    address: SeqField::default()
};
 
assert_eq!(
    vec![
        0x61, 0xf, 0x30, 0xd,
        0xa0, 0x6, 0x1b, 0x4, 0x4a, 0x6f, 0x68, 0x6e, // "John"
        0xa1, 0x3, 0x2, 0x1, 0x12 // 18
    ]
    , person.encode().unwrap()
);
 
person.decode(&[
    0x61, 0x1b, 0x30, 0x19,
    0xa0, 0x8, 0x1b, 0x6, 0x52, 0x61, 0x63, 0x68, 0x65, 0x6c, // "Rachel"
    0xa1, 0x3, 0x2, 0x1, 0x1e, // 30
    0xa2, 0x8, 0x1b, 0x6, 0x48, 0x61, 0x77, 0x61, 0x69, 0x69 // "Hawaii"
]).unwrap();
 
assert_eq!("Rachel", person.get_name().unwrap().value().unwrap());
assert_eq!(30, person.get_age().unwrap().value().unwrap());
assert_eq!("Hawaii", person.get_address().unwrap().value().unwrap());
 

Structs

BitSring

Class to encode/decode BitSring ASN1

BitSringValue

Data type for representing the value of a BitString

Boolean

Class to encode/decode Boolean ASN1

Error

Error in ASN1-DER decode/encode operations

GeneralString

Class to encode/decode GeneralString ASN1

GeneralizedTime

Class to encode/decode GeneralizedTime ASN1

IA5String

Class to encode/decode IA5String ASN1

Integer

Class to encode/decode Integer ASN1

OctetString

Class to encode/decode OctetString ASN1

SeqField

Class to represent a field of a Sequence

SequenceOf

Class to encode/decode SequenceOf ASN1

Tag

Class to represent DER-ASN1 tags of the different types.

Enums

ErrorKind

Type of error

LengthErrorKind

Error related to type length encoding/decoding, subtype of ErrorKind::InvalidLength

TagClass

Enum with the different tag classes

TagErrorKind

Error related to type tag encoding/decoding, subtype of ErrorKind::InvalidTag

TagType

Enum with the different tag types

TimeFormat

Enum to indicate the format of time used by GeneralizedTime

ValueErrorKind

Error related to type value encoding/decoding, subtype of ErrorKind::InvalidValue

Statics

BIT_STRING_TAG_NUMBER
BOOLEAN_TAG_NUMBER
GENERALIZED_TIME_TAG_NUMBER
GENERALSTRING_TAG_NUMBER
IA5STRING_TAG_NUMBER
INTEGER_TAG_NUMBER
OCTET_STRING_TAG_NUMBER
SEQUENCE_TAG_NUMBER

Traits

Asn1Object

A trait to allow objects to be encoded/decoded from ASN1-DER

Type Definitions

Result

Result that encapsulates the Error type of this library