encoding_asn1/
common.rs

1pub const TAG_BOOLEAN: i32 = 1;
2pub const TAG_INTEGER: i32 = 2;
3pub const TAG_BIT_STRING: i32 = 3;
4pub const TAG_OCTET_STRING: i32 = 4;
5pub const TAG_NULL: i32 = 5;
6pub const TAG_OID: i32 = 6;
7pub const TAG_ENUM: i32 = 10;
8pub const TAG_UTF8_STRING: i32 = 12;
9pub const TAG_SEQUENCE: i32 = 16;
10pub const TAG_SET: i32 = 17;
11pub const TAG_NUMERIC_STRING: i32 = 18;
12pub const TAG_PRINTABLE_STRING: i32 = 19;
13pub const TAG_T61_STRING: i32 = 20;
14pub const TAG_IA5_STRING: i32 = 22;
15pub const TAG_UTCTIME: i32 = 23;
16pub const TAG_GENERALIZED_TIME: i32 = 24;
17pub const TAG_GENERAL_STRING: i32 = 27;
18pub const TAG_BMPSTRING: i32 = 30;
19
20// ASN.1 class types represent the namespace of the tag.
21pub const CLASS_UNIVERSAL: i32 = 0;
22pub const CLASS_APPLICATION: i32 = 1;
23pub const CLASS_CONTEXT_SPECIFIC: i32 = 2;
24pub const CLASS_PRIVATE: i32 = 3;
25
26// ASN.1 has IMPLICIT and EXPLICIT tags, which can be translated as "instead
27// of" and "in addition to". When not specified, every primitive type has a
28// default tag in the UNIVERSAL class.
29//
30// For example: a BIT STRING is tagged [UNIVERSAL 3] by default (although ASN.1
31// doesn't actually have a UNIVERSAL keyword). However, by saying [IMPLICIT
32// CONTEXT-SPECIFIC 42], that means that the tag is replaced by another.
33//
34// On the other hand, if it said [EXPLICIT CONTEXT-SPECIFIC 10], then an
35// /additional/ tag would wrap the default tag. This explicit tag will have the
36// compound flag set.
37//
38// (This is used in order to remove ambiguity with optional elements.)
39//
40// You can layer EXPLICIT and IMPLICIT tags to an arbitrary depth, however we
41// don't support that here. We support a single layer of EXPLICIT or IMPLICIT
42// tagging with tag strings on the fields of a structure.
43
44// FieldParameters is the parsed representation of tag string from a structure field.
45#[derive(Debug)]
46pub struct FieldParameters {
47    pub optional: bool,             // true iff the field is OPTIONAL
48    pub explicit: bool,             // true iff an EXPLICIT tag is in use.
49    pub application: bool,          // true iff an APPLICATION tag is in use.
50    pub private: bool,              // true iff a PRIVATE tag is in use.
51    pub default_value: Option<i64>, // a default value for INTEGER typed fields (maybe nil).
52    pub tag: Option<i32>,           // the EXPLICIT or IMPLICIT tag (maybe nil).
53    pub string_type: i32,           // the string tag to use when marshaling.
54    pub time_type: i32,             // the time tag to use when marshaling.
55    pub set: bool,                  // true iff this should be encoded as a SET
56    pub omit_empty: bool,           // true iff this should be omitted if empty when marshaling.
57
58                                    // Invariants:
59                                    //   if explicit is set, tag is non-nil.
60}
61
62impl Default for FieldParameters {
63    fn default() -> FieldParameters {
64        FieldParameters {
65            optional: false,
66            explicit: false,
67            application: false,
68            private: false,
69            default_value: None,
70            tag: None,
71            string_type: 0,
72            time_type: 0,
73            set: false,
74            omit_empty: false,
75        }
76    }
77}
78
79#[derive(Debug, Default, PartialEq)]
80pub struct TagAndLength {
81    pub class: i32,
82    pub tag: i32,
83    pub length: usize,
84    pub is_compound: bool,
85}