rasn/types/identifier.rs
1/// The identifier of an ASN.1 type in an ASN.1 module. In most cases,
2/// the identifier is the human-readable type name as defined in the ASN.1 module.
3/// For built-in ASN.1 types, the XML tag names as defined in ITU-T X.680 (2021/02) ยง12.36
4/// are used. Some ASN.1 types, most notably open types, do not have a consistent identifier.
5#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
6pub struct Identifier(pub Option<&'static str>);
7
8impl Identifier {
9 /// Empty identifier value
10 pub const EMPTY: Self = Self(None);
11 /// Identifier for the built-in Bit String type
12 pub const BIT_STRING: Self = Self(Some("BIT_STRING"));
13 /// Identifier for the built-in Bool type
14 pub const BOOL: Self = Self(Some("BOOLEAN"));
15 /// Identifier for the built-in Choice type
16 pub const CHOICE: Self = Self(Some("CHOICE"));
17 /// Identifier for the built-in Date type
18 pub const DATE: Self = Self(Some("DATE"));
19 /// Identifier for the built-in Date Time type
20 pub const DATE_TIME: Self = Self(Some("DATE_TIME"));
21 /// Identifier for the built-in Duration type
22 pub const DURATION: Self = Self(Some("DURATION"));
23 /// Identifier for the built-in Embedded PDV type
24 pub const EMBEDDED_PDV: Self = Self(Some("SEQUENCE"));
25 /// Identifier for the built-in Enumerated type
26 pub const ENUMERATED: Self = Self(Some("ENUMERATED"));
27 /// Identifier for the built-in External type
28 pub const EXTERNAL: Self = Self(Some("SEQUENCE"));
29 /// Identifier for the built-in Instance_Of type
30 pub const INSTANCE_OF: Self = Self(Some("SEQUENCE"));
31 /// Identifier for the built-in Integer type
32 pub const INTEGER: Self = Self(Some("INTEGER"));
33 /// Identifier for the built-in Iri type
34 pub const IRI: Self = Self(Some("OID_IRI"));
35 /// Identifier for the built-in Null type
36 pub const NULL: Self = Self(Some("NULL"));
37 /// Identifier for the built-in Object_Identifier type
38 pub const OBJECT_IDENTIFIER: Self = Self(Some("OBJECT_IDENTIFIER"));
39 /// Identifier for the built-in Octet String type
40 pub const OCTET_STRING: Self = Self(Some("OCTET_STRING"));
41 /// Identifier for the built-in Real type
42 pub const REAL: Self = Self(Some("REAL"));
43 /// Identifier for the built-in Relative Iri type
44 pub const RELATIVE_IRI: Self = Self(Some("RELATIVE_OID_IRI"));
45 /// Identifier for the built-in Relative Oid type
46 pub const RELATIVE_OID: Self = Self(Some("RELATIVE_OID"));
47 /// Identifier for the built-in Sequence type
48 pub const SEQUENCE: Self = Self(Some("SEQUENCE"));
49 /// Identifier for the built-in Sequence Of type
50 pub const SEQUENCE_OF: Self = Self(Some("SEQUENCE_OF"));
51 /// Identifier for the built-in Set type
52 pub const SET: Self = Self(Some("SET"));
53 /// Identifier for the built-in Set Of type
54 pub const SET_OF: Self = Self(Some("SET_OF"));
55 /// Identifier for the built-in Time type
56 pub const TIME: Self = Self(Some("TIME"));
57 /// Identifier for the built-in Time Of Day type
58 pub const TIME_OF_DAY: Self = Self(Some("TIME_OF_DAY"));
59 /// Identifier for the built-in Unrestricted Character String type
60 pub const UNRESTRICTED_CHARACTER_STRING: Self = Self(Some("SEQUENCE"));
61 /// Identifier for the built-in Bmp String type
62 pub const BMP_STRING: Self = Self(Some("BMPString"));
63 /// Identifier for the built-in Ia5 String type
64 pub const IA5_STRING: Self = Self(Some("IA5String"));
65 /// Identifier for the built-in General String type
66 pub const GENERAL_STRING: Self = Self(Some("GeneralString"));
67 /// Identifier for the built-in Graphic String type
68 pub const GRAPHIC_STRING: Self = Self(Some("GraphicString"));
69 /// Identifier for the built-in Numeric String type
70 pub const NUMERIC_STRING: Self = Self(Some("NumericString"));
71 /// Identifier for the built-in Printable String type
72 pub const PRINTABLE_STRING: Self = Self(Some("PrintableString"));
73 /// Identifier for the built-in Teletex String type
74 pub const TELETEX_STRING: Self = Self(Some("TeletexString"));
75 /// Identifier for the built-in Visible String type
76 pub const VISIBLE_STRING: Self = Self(Some("VisibleString"));
77 /// Identifier for the built-in Utf8 String type
78 pub const UTF8_STRING: Self = Self(Some("UTF8String"));
79 /// Identifier for the built-in Generalized Time type
80 pub const GENERALIZED_TIME: Self = Self(Some("GeneralizedTime"));
81 /// Identifier for the built-in Utc Time type
82 pub const UTC_TIME: Self = Self(Some("UTCTime"));
83
84 /// Returns a reference of `self` if the identifier is not empty, or `other` if it is.
85 pub fn or(&self, other: Self) -> Self {
86 if self.0.is_none() {
87 other
88 } else {
89 *self
90 }
91 }
92
93 /// Returns the undelying string or panics if identifier is empty.
94 pub fn unwrap(&self) -> &'static str {
95 self.0.unwrap()
96 }
97}