Skip to main content

asn1_compiler/resolver/asn/structs/types/
base.rs

1//! Structs for the resolved Base Types
2use std::collections::{BTreeSet, HashMap};
3
4use crate::resolver::asn::structs::types::constraints::Asn1ConstraintValueSet;
5
6#[derive(Debug, Clone)]
7pub(crate) enum ResolvedBaseType {
8    Integer(Asn1ResolvedInteger),
9    Enum(Asn1ResolvedEnumerated),
10    BitString(Asn1ResolvedBitString),
11    Boolean(Asn1ResolvedBoolean),
12    OctetString(Asn1ResolvedOctetString),
13    CharacterString(Asn1ResolvedCharacterString),
14    ObjectIdentifier(Asn1ResolvedObjectIdentifier),
15    Null(Asn1ResolvedNull),
16    Real(Asn1ResolvedReal),
17}
18
19// An intermediate representation for a Resolved Integer Type
20//
21// This structure is obtained when all the 'Constraints' in a give definition are applied.
22// Information from this structure can be directly used for code generation.
23#[derive(Debug, Clone)]
24pub(crate) struct Asn1ResolvedInteger {
25    pub(crate) bits: u8,
26    pub(crate) signed: bool,
27    pub(crate) resolved_constraints: Option<Asn1ConstraintValueSet>,
28    pub(crate) named_values: Option<HashMap<String, i128>>,
29}
30
31impl Default for Asn1ResolvedInteger {
32    fn default() -> Self {
33        Self {
34            bits: 64,
35            signed: true,
36            named_values: None,
37            resolved_constraints: None,
38        }
39    }
40}
41
42#[derive(Debug, Clone)]
43pub(crate) struct Asn1ResolvedEnumerated {
44    pub(crate) bits: u8,
45    pub(crate) signed: bool,
46    pub(crate) extensible: bool,
47    pub(crate) root_values: Option<BTreeSet<i128>>,
48    pub(crate) ext_values: Option<BTreeSet<i128>>,
49    pub(crate) excepts: Option<BTreeSet<i128>>,
50    pub(crate) named_root_values: Vec<(String, i128)>,
51    pub(crate) named_ext_values: Vec<(String, i128)>,
52}
53
54impl Default for Asn1ResolvedEnumerated {
55    fn default() -> Self {
56        Self {
57            bits: 8,
58            signed: true,
59            extensible: false,
60            root_values: None,
61            ext_values: None,
62            excepts: None,
63            named_root_values: vec![],
64            named_ext_values: vec![],
65        }
66    }
67}
68
69// A Resolved `BIT STRING` representation. Normally only the `SIZE` Constraint needs to be
70// resolved. If optional, `named_bits` are present, we maintain those in the map below.
71#[derive(Debug, Default, Clone)]
72pub(crate) struct Asn1ResolvedBitString {
73    pub(crate) size: Option<Asn1ConstraintValueSet>,
74
75    // We support only up to 128 named bits, if more than that is required, change this to appropriate. value
76    pub(crate) named_values: HashMap<String, u8>,
77}
78
79// Just an empty structure for Resolved `BOOLEAN` type.
80#[derive(Debug, Default, Clone)]
81pub(crate) struct Asn1ResolvedBoolean;
82
83// Just an empty structure for Resolved `NULL` type.
84#[derive(Debug, Default, Clone)]
85pub(crate) struct Asn1ResolvedNull;
86
87// Just an empty structure for Resolved `NULL` type.
88#[derive(Debug, Default, Clone)]
89pub(crate) struct Asn1ResolvedReal;
90
91// A structure representing a Resolved `OCTET STRING`. `SIZE` Constraint is resolved as well. The
92// `CONTAINING` Constraint is not resolved.
93#[derive(Debug, Default, Clone)]
94pub(crate) struct Asn1ResolvedOctetString {
95    pub(crate) size: Option<Asn1ConstraintValueSet>,
96}
97
98// A structure representing a Resolved `CharacterString`. `SIZE` Constraint is resolved as well. The
99#[derive(Debug, Default, Clone)]
100pub(crate) struct Asn1ResolvedCharacterString {
101    pub(crate) str_type: String,
102    pub(crate) size: Option<Asn1ConstraintValueSet>,
103}
104
105#[derive(Debug, Default, Clone)]
106pub(crate) struct Asn1ResolvedObjectIdentifier;