Skip to content

Commit

Permalink
asn-compiler: Getting started with Tags resolution
Browse files Browse the repository at this point in the history
Added `Asn1ResolvedTag` to a base type as an `Option`. In the 'resolve'
value of each ingeger etc, we'll be resolving the actual tag if present
(or the module level support suggests `IMPLICIT/EXPLICIT` tags etc.

Right now just basic structure definitions etc.
  • Loading branch information
gabhijit committed Aug 7, 2023
1 parent 4d66ce5 commit a919536
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion asn-compiler/src/parser/asn/structs/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ pub(crate) enum Asn1TagMode {
Implicit,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub(crate) enum Asn1TagClass {
#[default]
Universal,
Application,
ContextSpecific,
Expand Down
22 changes: 18 additions & 4 deletions asn-compiler/src/resolver/asn/structs/types/base.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Structs for the resolved Base Types
use std::collections::{BTreeSet, HashMap};

use crate::resolver::asn::structs::types::constraints::Asn1ConstraintValueSet;
use crate::resolver::asn::structs::types::{constraints::Asn1ConstraintValueSet, Asn1ResolvedTag};

#[derive(Debug, Clone)]
pub(crate) enum ResolvedBaseType {
Expand All @@ -25,6 +25,7 @@ pub(crate) struct Asn1ResolvedInteger {
pub(crate) signed: bool,
pub(crate) resolved_constraints: Option<Asn1ConstraintValueSet>,
pub(crate) named_values: Option<HashMap<String, i128>>,
pub(crate) tag: Option<Asn1ResolvedTag>,
}

impl Default for Asn1ResolvedInteger {
Expand All @@ -34,6 +35,7 @@ impl Default for Asn1ResolvedInteger {
signed: true,
named_values: None,
resolved_constraints: None,
tag: None,
}
}
}
Expand All @@ -48,6 +50,7 @@ pub(crate) struct Asn1ResolvedEnumerated {
pub(crate) excepts: Option<BTreeSet<i128>>,
pub(crate) named_root_values: Vec<(String, i128)>,
pub(crate) named_ext_values: Vec<(String, i128)>,
pub(crate) tag: Option<Asn1ResolvedTag>,
}

impl Default for Asn1ResolvedEnumerated {
Expand All @@ -61,6 +64,7 @@ impl Default for Asn1ResolvedEnumerated {
excepts: None,
named_root_values: vec![],
named_ext_values: vec![],
tag: None,
}
}
}
Expand All @@ -73,29 +77,39 @@ pub(crate) struct Asn1ResolvedBitString {

// We support only up to 128 named bits, if more than that is required, change this to appropriate. value
pub(crate) named_values: HashMap<String, u8>,

pub(crate) tag: Option<Asn1ResolvedTag>,
}

// Just an empty structure for Resolved `BOOLEAN` type.
#[derive(Debug, Default, Clone)]
pub(crate) struct Asn1ResolvedBoolean;
pub(crate) struct Asn1ResolvedBoolean {
pub(crate) tag: Option<Asn1ResolvedTag>,
}

// Just an empty structure for Resolved `NULL` type.
#[derive(Debug, Default, Clone)]
pub(crate) struct Asn1ResolvedNull;
pub(crate) struct Asn1ResolvedNull {
pub(crate) tag: Option<Asn1ResolvedTag>,
}

// A structure representing a Resolved `OCTET STRING`. `SIZE` Constraint is resolved as well. The
// `CONTAINING` Constraint is not resolved.
#[derive(Debug, Default, Clone)]
pub(crate) struct Asn1ResolvedOctetString {
pub(crate) size: Option<Asn1ConstraintValueSet>,
pub(crate) tag: Option<Asn1ResolvedTag>,
}

// A structure representing a Resolved `CharacterString`. `SIZE` Constraint is resolved as well. The
#[derive(Debug, Default, Clone)]
pub(crate) struct Asn1ResolvedCharacterString {
pub(crate) str_type: String,
pub(crate) size: Option<Asn1ConstraintValueSet>,
pub(crate) tag: Option<Asn1ResolvedTag>,
}

#[derive(Debug, Default, Clone)]
pub(crate) struct Asn1ResolvedObjectIdentifier;
pub(crate) struct Asn1ResolvedObjectIdentifier {
pub(crate) tag: Asn1ResolvedTag,
}
10 changes: 10 additions & 0 deletions asn-compiler/src/resolver/asn/structs/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::BTreeMap;

use crate::parser::asn::structs::types::Asn1TagClass;

pub(crate) mod constructed;
use constructed::ResolvedConstructedType;

Expand Down Expand Up @@ -32,3 +34,11 @@ pub(crate) enum Asn1ResolvedType {
// A Set of Resolved Types. This is true if the type is obtained from Object Sets or Value Sets
Set(ResolvedSetType),
}

// When tags are to be supported, an instance of this class will be available for each of the
// 'resolved' type.
#[derive(Debug, Clone, Default)]
pub(crate) struct Asn1ResolvedTag {
num: u32,
class: Asn1TagClass,
}

0 comments on commit a919536

Please sign in to comment.