Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cla #114

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2021 Hampi Contributors
Copyright (c) 2024 hyphenOs Software Labs

This code is dual licensed as MIT Apache-2.0. See LICENSE-MIT and
LICENSE-Apache2
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 @@ -147,8 +147,9 @@ pub(crate) enum Asn1TagMode {
Implicit,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub(crate) enum Asn1TagClass {
#[default]
Universal,
Application,
ContextSpecific,
Expand Down
28 changes: 22 additions & 6 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 @@ -26,6 +26,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 @@ -35,6 +36,7 @@ impl Default for Asn1ResolvedInteger {
signed: true,
named_values: None,
resolved_constraints: None,
tag: None,
}
}
}
Expand All @@ -49,6 +51,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 @@ -62,6 +65,7 @@ impl Default for Asn1ResolvedEnumerated {
excepts: None,
named_root_values: vec![],
named_ext_values: vec![],
tag: None,
}
}
}
Expand All @@ -74,33 +78,45 @@ 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>,
}

// Just an empty structure for Resolved `NULL` type.
// Just an empty structure for Resolved `REAL` type.
#[derive(Debug, Default, Clone)]
pub(crate) struct Asn1ResolvedReal;
pub(crate) struct Asn1ResolvedReal {
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,
}
10 changes: 6 additions & 4 deletions asn-compiler/src/resolver/asn/types/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ pub(crate) fn resolve_base_type(
Asn1BuiltinType::BitString(ref b) => Ok(ResolvedBaseType::BitString(
Asn1ResolvedBitString::resolve_bit_string(ty, b, resolver)?,
)),
Asn1BuiltinType::Boolean => Ok(ResolvedBaseType::Boolean(Asn1ResolvedBoolean)),
Asn1BuiltinType::Boolean => {
Ok(ResolvedBaseType::Boolean(Asn1ResolvedBoolean::default()))
}
Asn1BuiltinType::OctetString => Ok(ResolvedBaseType::OctetString(
Asn1ResolvedOctetString::resolve_octet_string(ty, resolver)?,
)),
Asn1BuiltinType::CharacterString { .. } => Ok(ResolvedBaseType::CharacterString(
Asn1ResolvedCharacterString::resolve_character_string(ty, resolver)?,
)),
Asn1BuiltinType::ObjectIdentifier => Ok(ResolvedBaseType::ObjectIdentifier(
Asn1ResolvedObjectIdentifier,
Asn1ResolvedObjectIdentifier::default(),
)),
Asn1BuiltinType::Null => Ok(ResolvedBaseType::Null(Asn1ResolvedNull)),
Asn1BuiltinType::Real => Ok(ResolvedBaseType::Real(Asn1ResolvedReal)),
Asn1BuiltinType::Null => Ok(ResolvedBaseType::Null(Asn1ResolvedNull::default())),
Asn1BuiltinType::Real => Ok(ResolvedBaseType::Real(Asn1ResolvedReal::default())),
_ => Err(resolve_error!(
"parse_base_type: Not Implemented! {:#?}",
ty
Expand Down