Samuel-Tyler / fast_ber

A C++11 ASN.1 BER Encoding and Decoding Library
Boost Software License 1.0
84 stars 11 forks source link

IMPORT enumeration FROM module: incorrect code generation #37

Closed ezrec closed 3 years ago

ezrec commented 3 years ago

If an IMPORT specifies an enumeration from a module, incorrect code is generated.

Specifically, the namespace for the module containing the EnumeratedValues for the type is omitted.

-- Diff against testfiles/import.asn that illustrates the issue --

--- a/fast_ber/testfiles/import.asn
+++ b/fast_ber/testfiles/import.asn
@@ -1,11 +1,13 @@
 ModuleA DEFINITIONS IMPLICIT TAGS ::= BEGIN
 IMPORTS
     StringInModuleB, string-value FROM ModuleB
-    integer-value, IntegerInModuleC FROM ModuleC;
+    integer-value, IntegerInModuleC FROM ModuleC
+    EnumInModuleD FROM ModuleD;

 Collection ::= SEQUENCE {
     string StringInModuleB,
-    integer IntegerInModuleC
+    integer IntegerInModuleC,
+    enum EnumInModuleD
 }

 END
@@ -27,3 +29,14 @@ IntegerInModuleC ::= INTEGER
 integer-value IntegerInModuleC ::= 5

 END
+
+ModuleD DEFINITIONS IMPLICIT TAGS ::= BEGIN
+EXPORTS EnumInModuleD;
+
+EnumInModuleD ::= ENUMERATED {
+    first (0),
+    second (1),
+    third (2)
+}
+
+END

-- Diff between expected .hpp, and what was actually generated

--- a/import.hpp    2021-08-02 15:04:42.829197796 -0400
+++ b/fast_ber/test/autogen/import.hpp  2021-08-02 14:59:13.107882016 -0400
@@ -40,13 +40,13 @@

 FAST_BER_ALIAS(IntegerInModuleC, ::fast_ber::Integer<ExplicitId<UniversalTag::integer>>);

-FAST_BER_ALIAS(EnumInModuleD, ::fast_ber::Enumerated<ModuleD::EnumInModuleDValues,ExplicitId<UniversalTag::enumerated>>);
+FAST_BER_ALIAS(EnumInModuleD, ::fast_ber::Enumerated<EnumInModuleDValues,ExplicitId<UniversalTag::enumerated>>);

 struct Collection
 {
     using String = ::fast_ber::OctetString<ExplicitId<UniversalTag::octet_string>>;
     using Integer = ::fast_ber::Integer<ExplicitId<UniversalTag::integer>>;
-    using Enum_ = ::fast_ber::Enumerated<ModuleD::EnumInModuleDValues,ExplicitId<UniversalTag::enumerated>>;
+    using Enum_ = ::fast_ber::Enumerated<EnumInModuleDValues,ExplicitId<UniversalTag::enumerated>>;

     String string;
     Integer integer;
Samuel-Tyler commented 3 years ago

Fixed in: https://github.com/Samuel-Tyler/fast_ber/pull/38

ezrec commented 3 years ago

Thanks for resolving this!

Samuel-Tyler commented 3 years ago

Thanks for resolving this!

No problem, let me know if you have any other problems