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

Default value management #24

Open
kgalhabbo opened this issue Dec 8, 2015 · 4 comments
Open

Default value management #24

kgalhabbo opened this issue Dec 8, 2015 · 4 comments

Comments

@kgalhabbo
Copy link

Hello,

I am trying to parse a file containing the following (from http://simalliance.org/euicc/euicc-technical-releases/):

AlgoParameter ::= SEQUENCE {
key OCTET STRING,
opc OCTET STRING, -- For TUAK, this parameter sets TOPc
rotationConstants OCTET STRING (SIZE (5)) DEFAULT '4000204060'H,
xoringConstants OCTET STRING (SIZE (40)) DEFAULT '00000000000000000000000000000001000000000000000200000000000000040000000000000008'H,
sqnInit SEQUENCE (SIZE (3)) OF OCTET STRING (SIZE (6)) DEFAULT {'000000000000'H, '000000000000'H, '000000000000'H }
}

I get the following error:

Traceback (most recent call last):
File "pyasn1gen.py", line 588, in
sys.exit(main(sys.argv[1:]))
File "pyasn1gen.py", line 574, in main
parse_tree = parser.parse_asn1(asn1def)
File "C:\Python27\lib\site-packages\asn1ate\parser.py", line 41, in parse_asn1
parse_result = grammar.parseString(asn1_definition)
File "C:\Python27\lib\site-packages\pyparsing.py", line 1114, in parseString
raise exc
pyparsing.ParseException: Expected "END" (at char 533), (line:18, col:28)

Do you have any suggestions about how to solve this and/or how to deal with default values?
Thank you for your help.

@kgalhabbo kgalhabbo changed the title Default value Default value management Dec 8, 2015
@kimgr
Copy link
Owner

kimgr commented Dec 8, 2015

The problem is the last component:

sqnInit SEQUENCE (SIZE (3)) OF OCTET STRING (SIZE (6)) DEFAULT {'000000000000'H, '000000000000'H, '000000000000'H }

specifically the curly-brace form on DEFAULT.

We don't yet seem to handle the SequenceOfValue production -- I'm not entirely sure where to put it.

@kgalhabbo
Copy link
Author

Thank you for your answer. What would you therefore recommend?

@kimgr
Copy link
Owner

kimgr commented Dec 10, 2015

I think, and this is a big maybe, that you can omit the DEFAULT clause
entirely.

If I recall correctly, DEFAULTs are handled encode-time, so if you're
decoding, you'll always get a full value. If you're encoding, you'll have
to provide the value explicitly.

That might work.

  • Kim

On Thu, Dec 10, 2015 at 9:11 AM, kgalhabbo [email protected] wrote:

Thank you for your answer. What would you therefore recommend?


Reply to this email directly or view it on GitHub
#24 (comment).

@kimgr
Copy link
Owner

kimgr commented May 22, 2016

From #26 -- this actually runs clean through the parser, but generates nonsense pyasn1 code:

         Clearance  ::=  SEQUENCE {                                          
               policyId       [0] OBJECT IDENTIFIER,
               classList      [1] ClassList DEFAULT {unclassified},
               securityCategories [2] SET OF SecurityCategory  OPTIONAL
         }

Output:

# the subtype(value={unclassified}) part is not valid Python
namedtype.DefaultedNamedType('classList', ClassList().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)).subtype(value={unclassified})),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants