Skip to content

Commit

Permalink
feat: consider tagging and extensibility environments
Browse files Browse the repository at this point in the history
  • Loading branch information
6d7a committed Sep 19, 2024
1 parent 48706ce commit 06ea582
Show file tree
Hide file tree
Showing 23 changed files with 542 additions and 278 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Backend for CustomBackend {
const FILE_EXTENSION: &'static str = ".ext";

fn generate_module(
&self,
&mut self,
top_level_declarations: Vec<ToplevelDefinition>,
) -> Result<GeneratedModule, GeneratorError> {
Ok(GeneratedModule::empty())
Expand All @@ -109,6 +109,14 @@ impl Backend for CustomBackend {
fn from_config(config: Self::Config) -> Self {
CustomBackend
}

fn new(
config: Self::Config,
tagging_environment: TaggingEnvironment,
extensibility_environment: ExtensibilityEnvironment,
) -> Self {
CustomBackend
}
}

fn main() {
Expand Down
115 changes: 95 additions & 20 deletions rasn-compiler-tests/tests/edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ fn recursion() {
.add_asn_literal(
r#"
TestModule DEFINITIONS AUTOMATIC TAGS::= BEGIN
Filter ::= CHOICE {
and [0] SET SIZE (1..MAX) OF filter Filter,
or [1] SET SIZE (1..MAX) OF filter Filter,
not [2] Filter,
equalityMatch [3] AttributeValueAssertion,
...
}
AttributeValueAssertion ::= SEQUENCE {
attributeDesc AttributeDescription,
assertionValue AssertionValue }
Filter ::= CHOICE {
and [0] SET SIZE (1..MAX) OF filter Filter,
or [1] SET SIZE (1..MAX) OF filter Filter,
not [2] Filter,
equalityMatch [3] AttributeValueAssertion,
...
}
AssertionValue ::= OCTET STRING
AttributeValueAssertion ::= SEQUENCE {
attributeDesc AttributeDescription,
assertionValue AssertionValue }
AttributeDescription ::= LDAPString
AssertionValue ::= OCTET STRING
LDAPString ::= [UNIVERSAL 4] IMPLICIT UTF8String
END
"#
AttributeDescription ::= LDAPString
LDAPString ::= [UNIVERSAL 4] IMPLICIT UTF8String
filterValue Filter ::= and: { not:equalityMatch:{ attributeDesc "ABCDLMYZ", assertionValue 'A24F'H }, equalityMatch:{ attributeDesc "XY", assertionValue '00FF'H } }
END
"#
)
.compile_to_string()
.unwrap()
Expand All @@ -54,7 +58,7 @@ e2e_pdu!(
r#" #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, value("1..=10"))]
pub struct Distinguished(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, value("2..=8"))]
pub struct Restricted(pub Distinguished); "#
);
Expand All @@ -81,7 +85,7 @@ e2e_pdu!(
r#" #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, value("1..=10"))]
pub struct Distinguished(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(choice, automatic_tags)]
#[non_exhaustive]
pub enum TestChoice {
Expand Down Expand Up @@ -116,7 +120,7 @@ e2e_pdu!(
r#" #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, value("1..=10"))]
pub struct Distinguished(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(choice, automatic_tags)]
#[non_exhaustive]
pub enum TestChoice {
Expand Down Expand Up @@ -158,7 +162,7 @@ e2e_pdu!(
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, value("1..=10"))]
pub struct IntWithDefault(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(automatic_tags)]
pub struct Test {
#[rasn(default = "test_int_default")]
Expand Down Expand Up @@ -195,7 +199,7 @@ e2e_pdu!(
}
"#,
r#"
#[derive(AsnType,Debug,Clone,Decode,Encode,PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(choice,automatic_tags)]
pub enum ChoiceType {
number(Integer),
Expand All @@ -215,3 +219,74 @@ e2e_pdu!(
}
} "#
);

e2e_pdu!(
recursive_type,
rasn_compiler::prelude::RasnConfig {
..Default::default()
},
r#"
Filter ::= CHOICE {
and [0] SET SIZE (1..MAX) OF filter Filter,
or [1] SET SIZE (1..MAX) OF filter Filter,
not [2] Filter,
equalityMatch [3] AttributeValueAssertion,
...
}
AttributeValueAssertion ::= SEQUENCE {
attributeDesc AttributeDescription,
assertionValue AssertionValue }
AssertionValue ::= OCTET STRING
AttributeDescription ::= LDAPString
LDAPString ::= [UNIVERSAL 4] IMPLICIT UTF8String
"#,
r#"
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate)]
pub struct AssertionValue(pub OctetString);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate)]
pub struct AttributeDescription(pub LDAPString);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(automatic_tags)]
pub struct AttributeValueAssertion {
#[rasn(identifier = "attributeDesc")]
pub attribute_desc: AttributeDescription,
#[rasn(identifier = "assertionValue")]
pub assertion_value: AssertionValue,
}
impl AttributeValueAssertion {
pub fn new(attribute_desc: AttributeDescription, assertion_value: AssertionValue) -> Self {
Self {
attribute_desc,
assertion_value,
}
}
}
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(choice, automatic_tags)]
#[non_exhaustive]
pub enum Filter {
#[rasn(size("1.."), tag(context, 0))]
and(SetOf<Filter>),
#[rasn(size("1.."), tag(context, 1))]
or(SetOf<Filter>),
#[rasn(tag(context, 2))]
not(Box<Filter>),
#[rasn(tag(context, 3))]
equalityMatch(AttributeValueAssertion),
}
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, tag(universal, 4))]
pub struct LDAPString(pub Utf8String);
"#
);
4 changes: 2 additions & 2 deletions rasn-compiler-tests/tests/information_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ e2e_pdu!(
asn-val-unknown-order ErrorCode ::= local: 3
"#,
r#"
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(automatic_tags)]
pub struct Actual {
#[rasn(identifier = "errorCode")]
Expand All @@ -60,7 +60,7 @@ e2e_pdu!(
Errors_ParameterType::decode(decoder, self.parameter.as_ref(), &self.error_code)
}
}
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(choice, automatic_tags)]
pub enum ErrorCode {
local(Integer),
Expand Down
98 changes: 49 additions & 49 deletions rasn-compiler-tests/tests/nested_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ e2e_pdu!(
r#" Test-Boolean ::= BOOLEAN
Wrapping-Boolean ::= Test-Boolean
value Wrapping-Boolean ::= FALSE"#,
r#" #[derive(AsnType, Debug, Clone, Copy, Decode, Encode, PartialEq)]
r#" #[derive(AsnType, Debug, Clone, Copy, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, identifier = "Test-Boolean")]
pub struct TestBoolean(pub bool);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, identifier = "Wrapping-Boolean")]
pub struct WrappingBoolean(pub TestBoolean);
Expand All @@ -26,63 +26,63 @@ e2e_pdu!(
#[rasn(delegate, value("0..=123723"), identifier = "Test-Int")]
pub struct TestInt(pub u32);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, value("0..=123"), identifier = "Wrapping-Int")]
pub struct WrappingInt(pub TestInt);
pub const VALUE: WrappingInt = WrappingInt(TestInt(4)); "#
);

// e2e_pdu!(
// sequence,
// r#" Test-Int ::= INTEGER (0..123723)
// Wrapping-Int ::= Test-Int (0..123)
// Test-Boolean ::= BOOLEAN
// Wrapping-Boolean ::= Test-Boolean
// Test-Sequence ::= SEQUENCE {
// int Wrapping-Int DEFAULT 5,
// boolean Wrapping-Boolean,
// }
// value Test-Sequence ::= { boolean TRUE }"#,
// r#" #[derive(AsnType, Debug, Clone, Copy, Decode, Encode, PartialEq)]
// #[rasn(delegate)]
// pub struct TestBoolean(pub bool);
e2e_pdu!(
sequence,
r#" Test-Int ::= INTEGER (0..123723)
Wrapping-Int ::= Test-Int (0..123)
Test-Boolean ::= BOOLEAN
Wrapping-Boolean ::= Test-Boolean
Test-Sequence ::= SEQUENCE {
int Wrapping-Int DEFAULT 5,
boolean Wrapping-Boolean,
}
value Test-Sequence ::= { boolean TRUE }"#,
r#" #[derive(AsnType, Debug, Clone, Copy, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, identifier = "Test-Boolean")]
pub struct TestBoolean(pub bool);
// #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
// #[rasn(delegate, value("0..=123723"))]
// pub struct TestInt(pub u32);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, value("0..=123723"), identifier = "Test-Int")]
pub struct TestInt(pub u32);
// #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
// #[rasn(automatic_tags)]
// pub struct TestSequence {
// #[rasn(default = "test_sequence_int_default")]
// pub int: WrappingInt,
// pub boolean: WrappingBoolean,
// }
// impl TestSequence {
// pub fn new(int: WrappingInt, boolean: WrappingBoolean) -> Self {
// Self { int, boolean }
// }
// }
// fn test_sequence_int_default() -> WrappingInt {
// WrappingInt(TestInt(5))
// }
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(automatic_tags, identifier = "Test-Sequence")]
pub struct TestSequence {
#[rasn(default = "test_sequence_int_default")]
pub int: WrappingInt,
pub boolean: WrappingBoolean,
}
impl TestSequence {
pub fn new(int: WrappingInt, boolean: WrappingBoolean) -> Self {
Self { int, boolean }
}
}
fn test_sequence_int_default() -> WrappingInt {
WrappingInt(TestInt(5))
}
// #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
// #[rasn(delegate)]
// pub struct WrappingBoolean(pub TestBoolean);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, identifier = "Wrapping-Boolean")]
pub struct WrappingBoolean(pub TestBoolean);
// #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
// #[rasn(delegate, value("0..=123"))]
// pub struct WrappingInt(pub TestInt);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, value("0..=123"), identifier = "Wrapping-Int")]
pub struct WrappingInt(pub TestInt);
// lazy_static! {
// pub static ref VALUE: TestSequence = TestSequence::new(
// WrappingInt(TestInt(5)),
// WrappingBoolean(TestBoolean(true))
// );
// } "#
// );
lazy_static! {
pub static ref VALUE: TestSequence = TestSequence::new(
WrappingInt(TestInt(5)),
WrappingBoolean(TestBoolean(true))
);
} "#
);

e2e_pdu!(
constraint_cross_reference,
Expand All @@ -93,7 +93,7 @@ e2e_pdu!(
#[rasn(delegate, value("0..=123723"), identifier = "Test-Int")]
pub struct TestInt(pub u32);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, value("0..=5"), identifier = "Wrapping-Int")]
pub struct WrappingInt(pub TestInt);
Expand Down
8 changes: 4 additions & 4 deletions rasn-compiler-tests/tests/parameterization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ r#"
ImplType ::= ParamType { 2, TRUE }
"#,
r#"
#[derive (AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive (AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn (automatic_tags)]
pub struct ImplType {
#[rasn(value("2..=12"), identifier = "int-value")]
Expand Down Expand Up @@ -73,7 +73,7 @@ e2e_pdu! {
"#,
r#"
#[doc = " Anonymous SEQUENCE OF member "]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(automatic_tags, identifier = "SEQUENCE")]
pub struct AnonymousA2XPC5FlowBitRatesIEExtensions {
pub id: Integer,
Expand Down Expand Up @@ -103,12 +103,12 @@ e2e_pdu! {
}
}
#[doc = " Inner type "]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(delegate, size("1.."))]
pub struct A2XPC5FlowBitRatesIEExtensions(
pub SequenceOf<AnonymousA2XPC5FlowBitRatesIEExtensions>,
);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord)]
#[rasn(automatic_tags, identifier = "A2X-PC5-FlowBitRates")]
#[non_exhaustive]
pub struct A2XPC5FlowBitRates {
Expand Down
2 changes: 1 addition & 1 deletion rasn-compiler-tests/tests/parse_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn compile_etsi() {
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_container.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_ies.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_pdus.asn")
.add_asn_by_path("../rasn-compiler/test_asn1/ivi-3.1.asn")
.add_asn_by_path("../rasn-compiler/test_asn1/ldap.asn")
.set_output_path("./tests")
.compile()
);
Expand Down
Loading

0 comments on commit 06ea582

Please sign in to comment.