Skip to content
Draft
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
53 changes: 49 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rasn-compiler-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ readme.workspace = true
[dependencies]
rasn-compiler-derive = { path = "../rasn-compiler-derive" }
rasn-compiler = { path = "../rasn-compiler" }
rasn = { version = "0.27" }
rasn = { git = "https://github.com/jp-marcotte/rasn.git", branch = "fix/avn-named-integer" }

[dev-dependencies]
bitvec = { version = "1" }
Expand Down
22 changes: 22 additions & 0 deletions rasn-compiler-tests/tests/simple_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ e2e_pdu!(
} (0..2)"
);

e2e_pdu!(
integer_named_values_unbounded,
"PUKKeyReferenceValue ::= INTEGER {
pukAppl1(1),
pukAppl2(2),
pukAppl3(3),
pukAppl4(4),
pukAppl5(5),
pukAppl6(6),
pukAppl7(7),
pukAppl8(8),
secondPUKAppl1(129),
secondPUKAppl2(130),
secondPUKAppl3(131),
secondPUKAppl4(132),
secondPUKAppl5(133),
secondPUKAppl6(134),
secondPUKAppl7(135),
secondPUKAppl8(136)
}"
);

e2e_pdu!(
integer_const,
r#" Test-Int ::= INTEGER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod test_module {
use rasn::prelude::*;
use std::sync::LazyLock;
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, value("1..=10"))]
# [rasn (delegate , value ("1..=10") , named_values ("first" = 1 , "second" = 2 , "third" = 3 , "fourth" = 4 , "fifth" = 5 , "sixth" = 6 , "seventh" = 7 , "eighth" = 8 , "ninth" = 9 , "tenth" = 10))]
pub struct Distinguished(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, value("2..=8"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod test_module {
use rasn::prelude::*;
use std::sync::LazyLock;
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, value("1..=10"))]
# [rasn (delegate , value ("1..=10") , named_values ("first" = 1 , "second" = 2 , "third" = 3 , "fourth" = 4 , "fifth" = 5 , "sixth" = 6 , "seventh" = 7 , "eighth" = 8 , "ninth" = 9 , "tenth" = 10))]
pub struct Distinguished(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(choice, automatic_tags)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod test_module {
use rasn::prelude::*;
use std::sync::LazyLock;
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, value("1..=10"))]
# [rasn (delegate , value ("1..=10") , named_values ("first" = 1 , "second" = 2 , "third" = 3 , "fourth" = 4 , "fifth" = 5 , "sixth" = 6 , "seventh" = 7 , "eighth" = 8 , "ninth" = 9 , "tenth" = 10))]
pub struct Distinguished(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(choice, automatic_tags)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod test_module {
second = 2,
}
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, value("1..=10"))]
# [rasn (delegate , value ("1..=10") , named_values ("first" = 1 , "second" = 2))]
pub struct IntWithDefault(pub u8);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(automatic_tags)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ pub mod test_module {
use rasn::prelude::*;
use std::sync::LazyLock;
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, identifier = "Test-Int", value("0..=2"))]
# [rasn (delegate , identifier = "Test-Int" , value ("0..=2") , named_values ("first" = 0 , "second" = 1 , "third" = 2))]
pub struct TestInt(pub u8);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: rasn-compiler-tests/tests/simple_types.rs
description: "PUKKeyReferenceValue ::= INTEGER {\n pukAppl1(1),\n pukAppl2(2),\n pukAppl3(3),\n pukAppl4(4),\n pukAppl5(5),\n pukAppl6(6),\n pukAppl7(7),\n pukAppl8(8),\n secondPUKAppl1(129),\n secondPUKAppl2(130),\n secondPUKAppl3(131),\n secondPUKAppl4(132),\n secondPUKAppl5(133),\n secondPUKAppl6(134),\n secondPUKAppl7(135),\n secondPUKAppl8(136)\n }"
---
Generated:
#[allow(
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused,
clippy::too_many_arguments
)]
pub mod test_module {
extern crate alloc;
use core::borrow::Borrow;
use rasn::prelude::*;
use std::sync::LazyLock;
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
# [rasn (delegate , named_values ("pukAppl1" = 1 , "pukAppl2" = 2 , "pukAppl3" = 3 , "pukAppl4" = 4 , "pukAppl5" = 5 , "pukAppl6" = 6 , "pukAppl7" = 7 , "pukAppl8" = 8 , "secondPUKAppl1" = 129 , "secondPUKAppl2" = 130 , "secondPUKAppl3" = 131 , "secondPUKAppl4" = 132 , "secondPUKAppl5" = 133 , "secondPUKAppl6" = 134 , "secondPUKAppl7" = 135 , "secondPUKAppl8" = 136))]
pub struct PUKKeyReferenceValue(pub Integer);
}
3 changes: 3 additions & 0 deletions rasn-compiler/src/generator/rasn/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ impl Rasn {
if let ASN1Type::Integer(ref int) = tld.ty {
let (name, mut annotations) = self.format_name_and_common_annotations(&tld);
annotations.push(self.format_range_annotations(true, &int.constraints)?);
if let Some(ref dvs) = int.distinguished_values {
annotations.push(self.format_named_values_annotation(dvs));
}
Ok(integer_template(
self.format_comments(&tld.comments),
name,
Expand Down
20 changes: 19 additions & 1 deletion rasn-compiler/src/generator/rasn/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
per_visible_range_constraints, CharsetSubset, PerVisibleAlphabetConstraints,
},
information_object::{InformationObjectField, ObjectClassDefn},
types::{Choice, ChoiceOption, Enumerated, SequenceOrSet, SequenceOrSetMember},
types::{Choice, ChoiceOption, DistinguishedValue, Enumerated, SequenceOrSet, SequenceOrSetMember},
ASN1Type, ASN1Value, AsnTag, CharacterStringType, IntegerType, TagClass,
TaggingEnvironment, ToplevelDefinition, ToplevelTypeDefinition,
},
Expand Down Expand Up @@ -221,6 +221,24 @@ impl Rasn {
)
}

/// Formats a `named_values(...)` rasn annotation for INTEGER types with a NamedNumberList.
/// Returns an empty `TokenStream` when the slice is empty so callers can push it
/// unconditionally and `join_annotations` will filter it out.
pub(crate) fn format_named_values_annotation(
&self,
distinguished_values: &[DistinguishedValue],
) -> TokenStream {
if distinguished_values.is_empty() {
return TokenStream::new();
}
let pairs = distinguished_values.iter().map(|dv| {
let name = &dv.name;
let value = Literal::i128_unsuffixed(dv.value);
quote!(#name = #value)
});
quote!(named_values(#(#pairs),*))
}

pub(crate) fn format_alphabet_annotations(
&self,
string_type: CharacterStringType,
Expand Down
Loading