kimgr / asn1ate Goto Github PK
View Code? Open in Web Editor NEWA Python library for translating ASN.1 into other forms.
License: Other
A Python library for translating ASN.1 into other forms.
License: Other
Problem: Using asn1ate 0.6.0 as packaged for Python 3.9, we discovered a problem with PyParsing 3.0.6; this caused exceptions when using OPTIONAL
or DEFAULT x
annotations,
File ".../asn1ate-0.6.0-py3.7.egg/asn1ate/sema.py", line 474, in <listcomp>
for token in component_tokens]
File ".../asn1ate-0.6.0-py3.7.egg/asn1ate/sema.py", line 994, in _create_sema_node
raise Exception('Unknown token type: %s' % token.ty)
Exception: Unknown token type: ComponentTypeOptional
Workaround: We worked around it by demanding an older version, namely 3.0.0, of PyParsing.
Question: It is not quite clear if this is only due to PyParsing; there may be something wrong with asn1ate that gets triggered. This most likely is in sema.py
function _create_sema_node()
which has
elif token.ty == 'ComponentType':
return ComponentType(token.elements)
but no cases for ComponentTypeOptional
, ComponentTypeDefault
, ComponentTypeComponentsOf
. When I added such cases under PyParsing 3.0.6, it ran into a problem using the elements
array, which I could not furhter assign to my thinking or that in the sema.py
module.
Using this module definition:
Class-definitions DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Myenum ::= ENUMERATED { zero, one, two }
Mysequence-with-enum ::= SEQUENCE
{
foo Myenum DEFAULT two
}
END
the output isn't valid python:
...
Mysequence_with_enum.componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('foo', Myenum().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)).subtype(value=two))
)
...
The default values for enums need to be quoted.
Some string types are recognised by parser, but not output properly. TeletexString and UniversalString are not prefixed with char.
shouldn't restricted_integer_type, at line 275 in parse.py, have the possibility for value_range_constraint?
I edited mine to:
restricted_integer_type = INTEGER + braced_list(named_number) + Optional(value_range_constraint | single_value_constraint, default=None)
and it resolved an error I had and seems to work fine.
Please correct me if I'm wrong.
We're using asn1ate heavily in our Quick DER as a means of using ASN.1 in protocols. We generate C and Python code from it that simplifies parsing and processing of DER (and, in prepartion, JER).
One such application is KIP which takes a surprising new angle on encryption. As part of it I'm designing a document format which makes most sense in DER but which also ought to be as compact as possible. In short, there are many features but most of them have simple defaults. This is where I'm running into the following limitations of the grammar recognised by asn1ate
, and I would like to extend that, or see it extended, in the next release.
To motivate the use with a few possible applications of KIP:
data:
URIs and serve as signed referencesPlease let me know if it is possible to add these DEFAULT
parsing forms; their empty forms should make that really easy; if you cannot do it we might, but then we'd like to know ahead of time that you agree with the idea and are willing to integrate it into the Python distributed form of asn1ate
.
Thanks!
Rick, for the ARPA2 projects
Hi guys,
found a new issue, regarding to the size constraint:
In case of a HexaString, the length have to be div by 2
file : constraint.py
function : ValueSizeConstraint
line 106 : l = len(value)/2 to count the number of OCTET
bye
Mourad
I'm trying to convert an LTE specification's ASN.1 syntax into python code and ran the file (see attached zip) in pyasn1gen.py.
I received the following error:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 649, in <module>
sys.exit(main())
File "/usr/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 627, in main
parse_tree = parser.parse_asn1(asn1def)
File "/usr/lib/python2.7/site-packages/asn1ate/parser.py", line 40, in parse_asn1
parse_result = grammar.parseString(asn1_definition)
File "/usr/lib/python2.7/site-packages/pyparsing.py", line 1632, in parseString
raise exc
pyparsing.ParseException: Expected "DEFINITIONS" (at char 195), (line:8, col:13)
The attached file was taken from here. I had to filter out the ASN.1 definitions and remove unwanted text.
I might have made a mistake doing that. Could you please help?
gtp.zip
Hi guys,
In new in the ASN1 parsing
I was trying to parse an example of ASN1 Definition. It the New Sim ASN1 definition. I found it at SIMAlliance.
This parsing raise some exception on the original file.
What they call PE-Dummy at line 60 is an Empty element, that seems to not being accepted by asn1ate :(
PE-Dummy ::= SEQUENCE {
}
And at the line 574 an other element called PE-AKAParameter, the asn1ate reject it because of the DEFAULT definition :
PE-AKAParameter ::= SEQUENCE {
aka-header PEHeader,
algoConfiguration CHOICE {
mappingParameter MappingParameter,
algoParameter AlgoParameter
},
sqnOptions OCTET STRING (SIZE(1)) DEFAULT '02'H,
sqnDelta OCTET STRING (SIZE(6)) DEFAULT '000010000000'H,
sqnAgeLimit OCTET STRING (SIZE(6)) DEFAULT '000010000000'H,
-- Sequence numbers do not include the index (IND)
sqnInit SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6)) DEFAULT {
/* Index 0 */'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H,
/* Index 31 */'000000000000'H }
}
I am not a ASN1 expert is this ASN1 elements well written. is this case not implemented in ASN1ATE.
is this the Definition of DEFAULT values for a sequence?
results in the following line:
pyparsing.ParseException: Expected "END" (at char 1766), (line:60, col:23)
and
pyparsing.ParseException: Expected "END" (at char 16038), (line:574, col:30)
What's wrong?
PS C:\users\user\appdata\local\programs\python\python310\lib\site-packages\asn1ate> python pyasn1gen.py asn_def.asn
Traceback (most recent call last):
File "C:\users\user\appdata\local\programs\python\python310\lib\site-packages\asn1ate\pyasn1gen.py", line 649, in <module>
sys.exit(main())
File "C:\users\user\appdata\local\programs\python\python310\lib\site-packages\asn1ate\pyasn1gen.py", line 629, in main
modules = build_semantic_model(parse_tree)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 36, in build_semantic_model
root.append(_create_sema_node(token))
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 926, in _create_sema_node
return Module(token.elements)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 276, in __init__
self.assignments = [_create_sema_node(token) for token in assignments.elements]
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 276, in <listcomp>
self.assignments = [_create_sema_node(token) for token in assignments.elements]
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 932, in _create_sema_node
return TypeAssignment(token.elements)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 440, in __init__
self.type_decl = _create_sema_node(type_decl)
File "C:\Users\skorzan\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 948, in _create_sema_node
return _create_sema_node(token.elements[0])
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 960, in _create_sema_node
return SequenceType(token.elements)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 503, in __init__
super(SequenceType, self).__init__(elements)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 473, in __init__
self.components = [_create_sema_node(token)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 473, in <listcomp>
self.components = [_create_sema_node(token)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\asn1ate\sema.py", line 994, in _create_sema_node
raise Exception('Unknown token type: %s' % token.ty)
Exception: Unknown token type: ComponentTypeDefault
PS C:\users\user\appdata\local\programs\python\python310\lib\site-packages\asn1ate>
ASN.1 module:
IMPORTS
SLPAddress, QoP, PosMethod FROM ULP-Components
Ver2-SUPL-INIT-extension FROM ULP-Version-2-message-extensions
Ver2-Notification-extension FROM ULP-Version-2-parameter-extensions
Ver3-SUPL-INIT-extension FROM ULP-Version-3-message-extensions;
Notification ::= SEQUENCE {
notificationType NotificationType,
encodingType EncodingType OPTIONAL,
requestorId OCTET STRING(SIZE (1..maxReqLength)) OPTIONAL,
requestorIdType FormatIndicator OPTIONAL,
clientName OCTET STRING(SIZE (1..maxClientLength)) OPTIONAL,
clientNameType FormatIndicator OPTIONAL,
...,
ver2-Notification-extension Ver2-Notification-extension OPTIONAL}
ULP-Version-2-parameter-extensions defines the Ver2-Notification-extension define type.
Debug:
return module.resolve_type_decl(module.user_types()[type_decl.type_name], referenced_modules)
KeyError: 'Ver2-Notification-extension'
(edit: formatted the code sample and removed some accidental styling /kimgr)
This is valid according to ASN.1 Playground:
Test DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
UARFCN ::= INTEGER(0..16383)
FQDN ::= VisibleString(FROM ("a".."z" | "A".."Z" | "0".."9" | ".-")) (SIZE (1..255))
END
This is excerpted from Wireshark's ULP support.
The example above fails with:
Traceback (most recent call last):
File "../.direnv/python-2.7.13/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 588, in <module>
sys.exit(main(sys.argv[1:]))
File "../.direnv/python-2.7.13/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 574, in main
parse_tree = parser.parse_asn1(asn1def)
File "/Users/rbdixon/projects/library/201708-vzw-lte_precloc/testing/fuzz/.direnv/python-2.7.13/lib/python2.7/site-packages/asn1ate/parser.py", line 40, in parse_asn1
parse_result = grammar.parseString(asn1_definition)
File "/Users/rbdixon/projects/library/201708-vzw-lte_precloc/testing/fuzz/.direnv/python-2.7.13/lib/python2.7/site-packages/pyparsing.py", line 1632, in parseString
raise exc
pyparsing.ParseException: Expected "END" (at char 94), (line:5, col:23)
I believe that VisibleString is supported since it is parsed correctly elsewhere in my ASN.1 example. Any advice on getting this going?
I'm trying to parse the DSRC definition included in the testdata/public folder.
It uses automatic tagging, which the parser recognises but doesn't act upon. (See line 314 in sema.py)
I'm happy to have a go at implementing this myself and creating a patch, but honestly I don't know what the best way to tackle it would be. Have you any suggestions about where and how to go about adding this?
Hello,
I am trying to use your library to generate pyasn1 file from this ASN
http://hillfolk.synology.me:5000/fbsharing/F6Y9Fv87
but errors are displayed.
File "asn1ate/asn1ate/pyasn1gen.py", line 589, in sys.exit(main(sys.argv[1:])) File "asn1ate/asn1ate/pyasn1gen.py", line 575, in main parse_tree = parser.parse_asn1(asn1def) File "/home/junyong/Source/ASN-Test/venv/local/lib/python2.7/site-packages/asn1ate/parser.py", line 40, in parse_asn1 parse_result = grammar.parseString(asn1_definition) File "/home/junyong/Source/ASN-Test/venv/local/lib/python2.7/site-packages/pyparsing.py", line 1111, in parseString raise exc pyparsing.ParseException: Expected "END" (at char 16673), (line:218, col:44)
Can I give you help me?
pyasn1gen.py can only transform one asn1 file to python. So how can i transform several asn1 files which are interdependent to py files?
I'm trying to process the z3950 1995 asn spec using asn1ate, because I'm trying to revive the module PyZ3950 which implemented its own asn1 encoder/decoder, and I need to get good data before I choose to replace with pyasn1 and asn1ate.
The file https://github.com/danizen/PyZ3950/blob/master/z3950_asn/z3950_1995.asn holds the asn I am trying to parse, and I worked through problems where copy and paste from https://www.loc.gov/z3950/agency/asn1.html to that file failed, e.g. comments broken onto multiple lines.
Now that I've done that, I think it gets through parsing the file, but when it goes to export the pyasn1 schemas, it outputs this:
KeyError: 'EXTERNAL'
I understand its looking for that in a dict, but how can I address this?
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.
With input Foo DEFINITIONS ::= BEGIN bar BOOLEAN ::= true END
, I get output containing bar = univ.Boolean(true)
. I would expect to get (1) a parse error; or (2) valid (non-erroring) python code. (The 'T' in 'true' should be capitalized, True
; currently I get a NameError)
The full output is
# Auto-generated by asn1ate v.0.5.1.dev from foo.asn
# (last modified on 2016-11-28 19:08:26.094569)
from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful
bar = univ.Boolean(true)
Hello, I am quite new to ASN and parsing and this may be naive problem. I am trying to use your library to generate pyasn1 file from this ASN
http://jayu.googlecode.com/svn-history/r3/trunk/jayu/src/test/testdata/Huawie.txt
But I am getting exception.
pyparsing.ParseException: Expected "END" (at char 97715), (line:1110, col:32)
Could you help me with this issue ?
i found it don't support value notation like this :
myValue MyType ::=
{
a 100,
b 200,
c 300
}
could it be supported ?
Thanks
When parsing rfc3281, the following fragment:
Clearance ::= SEQUENCE {
policyId [0] OBJECT IDENTIFIER,
classList [1] ClassList DEFAULT {unclassified},
securityCategories
[2] SET OF SecurityCategory OPTIONAL
}
ClassList ::= BIT STRING {
unmarked (0),
unclassified (1),
restricted (2),
confidential (3),
secret (4),
topSecret (5)
}
results in the following line
namedtype.DefaultedNamedType('classList', ClassList().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)).subtype(value={unclassified})),
With unclassified
being used as a variable rather than string / ClassList value.
Here's the definition extracted from the text of RFC 3851.
When I run pyasn1gen.py rfc3851.asn
with either Python 2.7.10 or Python 3.5.0, I get:
File "asn1ate/asn1ate/pyasn1gen.py", line 299, in inline_defined_type
if t.module_name and t.module_name != self.sema_module.name:
AttributeError: 'DefinedType' object has no attribute 'module_name'
This is strange since DefinedType's constructor does set the module_name
attribute, but with some print debugging it looks like this DefinedType instance was never initialized. Not sure how that could be.
I am trying to decode the CDR and using asn1ate to generate the pyasn module. I get the error when I try to use the default generated module.
ASN: http://jayu.googlecode.com/svn/!svn/bc/3/trunk/jayu/src/test/testdata/Huawie.txt
Data: http://jayu.googlecode.com/svn/!svn/bc/3/trunk/jayu/src/test/testdata/hua.dat
Generated Code: https://www.dropbox.com/s/hc1b5xocwxecac9/huawei.py?dl=0
If I change all the explicitTag
arguments to implicitTag
argument in the generated code it works.
Working code after change: https://www.dropbox.com/s/vw477nsdtysmsnc/huawei_change.py?dl=0
Other Samples: http://jayu.googlecode.com/svn/!svn/bc/3/trunk/jayu/src/test/testdata/
Hello,
I was using pyasn1gen.py and I found a bug. I used it with wireshark's sv.asn and one of the things it gave me was:
namedtype.OptionalNamedType('datSet', VisibleString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
I tried to run this and it gave me this error:
namedtype.NamedType('svID', VisibleString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
NameError: name 'VisibleString' is not defined
After I investigated I found that the VisibleString is defined in char.py but it isn't introduced to your _ASN1_BUILTIN_TYPES in pyasn1gen.py. I fixed this by adding 'VisibleString': 'char.VisibleString' to the BUILTIN dictionary so that when you generate the pyasn1 youll get the char.VisibleString(). Another way to solve this is to import the library as follows:
from pyasn1.type.char import VisibleString
If you import VisibleString this way then VisibleString() will work just fine. Besides that I think the library is really useful, great job.
If you want me to make a merge request just let me know.
Thanks!
I have some asn1 that fails with 0.4 (the version from PyPI) but works with the latest master. It would be easier for some of my co-workers to install from PyPI than using git clone. Do you have any schedule or plans to update the version on PyPI?
Thanks,
Mark
Originally reported by @Mourhamo as issue #32.
The asn1ate parser does not accept SEQUENCE elements without components:
PE-Dummy ::= SEQUENCE {
}
(example from PEDefinitions V2.0.txt)
Parsing fails with:
pyparsing.ParseException: Expected "END" (at char 16038), (line:574, col:30)
They are spec:ed as a subtype of ReferencedType, but since pyasn1 has a native representation of them (useful.*) , I think they should be considered part of simple_type.
See X.680, section 41.
I'm not quite sure how imports are handled right now, but it seems I can't use imported types. I'm guessing types are resolved when they are referenced with their module explicitly, with a dot
BasicContainer ::= SEQUENCE { someVar SomeModule.SomeType }
But it should be possible to use the type without the module reference when it is imported.
My guess is that this can be fixed in resolve_type_decl, line 287 in sema.py, with a loop through the imported types if type_decl.module_ref
doesn't exist.
Will look into it
TypeWithConstraint ::=
SET Constraint OF Type
| SET SizeConstraint OF Type
| SEQUENCE Constraint OF Type
| SEQUENCE SizeConstraint OF Type
| SET Constraint OF NamedType
| SET SizeConstraint OF NamedType
| SEQUENCE Constraint OF NamedType
| SEQUENCE SizeConstraint OF NamedType
The SIZE constraints are recorded in sema, but not emitted to pyasn1.
Hi, I have a problem with translate ASN.1 grammar of Kerberos from:
https://cwiki.apache.org/confluence/display/DIRxSRVx10/Kerberos+ASN.1+codec
when I put:
python pyasn1gen.py KrbGrammar.asn1 > rfc4120.py
output is:
Traceback (most recent call last):
File "pyasn1gen.py", line 628, in
sys.exit(main())
File "pyasn1gen.py", line 606, in main
parse_tree = parser.parse_asn1(asn1def)
File "/usr/local/lib/python2.7/dist-packages/asn1ate/parser.py", line 40, in parse_asn1
parse_result = grammar.parseString(asn1_definition)
File "/usr/local/lib/python2.7/dist-packages/pyparsing.py", line 1613, in parseString
raise exc
pyparsing.ParseException: Expected "END" (at char 908), (line:28, col:35)
I don't know, maybe doing something wrong.
Thank you for You help.
I've been trying to get asn1ate to digest the 3GPP RRC protocol, and I've had some success with taking snippets out and processing them individually. However the parser chokes on the whole thing:
# Auto-generated by asn1ate v.0.5.1.dev from rrc.asn1
# (last modified on 2016-09-08 23:03:47)
from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful
class BCCH_BCH_Message(univ.Sequence):
pass
Traceback (most recent call last):
File "asn1ate/pyasn1gen.py", line 631, in <module>
sys.exit(main())
File "asn1ate/pyasn1gen.py", line 622, in main
generate_pyasn1(module, output_file, modules)
File "asn1ate/pyasn1gen.py", line 495, in generate_pyasn1
return Pyasn1Backend(sema_module, out_stream, referenced_modules).generate_code()
File "asn1ate/pyasn1gen.py", line 145, in generate_code
details = self.generate_definition(assignment)
File "asn1ate/pyasn1gen.py", line 159, in generate_definition
return self.generate_defn(assigned_type, type_decl)
File "asn1ate/pyasn1gen.py", line 171, in generate_defn
return generator(class_name, t)
File "asn1ate/pyasn1gen.py", line 210, in defn_constructed_type
fragment.write_block(self.inline_component_types(t.components))
File "asn1ate/pyasn1gen.py", line 321, in inline_component_types
component_exprs.append(self.generate_expr(c))
File "asn1ate/pyasn1gen.py", line 167, in generate_expr
return generator(t)
File "asn1ate/pyasn1gen.py", line 427, in inline_component_type
return "namedtype.NamedType('%s', %s)" % (t.identifier, self.generate_expr(t.type_decl))
File "asn1ate/pyasn1gen.py", line 167, in generate_expr
return generator(t)
File "asn1ate/pyasn1gen.py", line 337, in inline_tagged_type
type_expr += '.subtype(%s=%s)' % (tag_implicitness, self.build_tag_expr(t))
File "asn1ate/pyasn1gen.py", line 351, in build_tag_expr
tagged_type_decl = self.sema_module.resolve_type_decl(tag_def.type_decl, self.referenced_modules)
File "/Users/aholtzma/src/asn1ate/asn1ate/sema.py", line 303, in resolve_type_decl
return module.resolve_type_decl(module.user_types()[type_decl.type_name], referenced_modules)
KeyError: 'SystemInformation-BCH'
The reason is that SystemInformation-BCH is defined in the PDU-definitions module, which gets completely dropped by the parser (confirmed by running test.py --parse, I won't paste it here).
is the following grammar syntax supported by asn1ate in 0.6.0, I see this failing -
pcie-bus-defs ::= SEQUENCE {
pcie-bus-number INTEGER (0 .. 255),
pcie-lane INTEGER ( 0 | 1 | 2 | 4 | 8 | 16 ),
pcie-slot-speed INTEGER ( 0 | 2500 | 5000 | 8000 ), -- in Mbps, per lane
pcie-flags OCTECT STRING (SIZE(4 | 12..16)), -- pcie flags space
...
}
seem like (a|b|c|d) is incorrectly parsed in released version.
I tried to parse a proprietary ASN but a KeyError occured. I found out the issue was due to definitions as follows:
Record ::= SET
{
....
namedValue [13] BIT STRING OPTIONAL,
...
I kinda solved the issue by replacing self.inline_generator
in line 106 of pyasn1gen.py
with this
self.inline_generators = {
TaggedType: self.inline_tagged_type,
SelectionType: self.inline_selection_type,
SimpleType: self.inline_simple_type,
DefinedType: self.inline_defined_type,
ComponentType: self.inline_component_type,
NamedType: self.inline_named_type,
SequenceOfType: self.inline_sequenceof_type,
SetOfType: self.inline_setof_type,
ValueListType: self.inline_value_list_type,
ChoiceType: self.inline_constructed_type,
SequenceType: self.inline_constructed_type,
SetType: self.inline_constructed_type,
BitStringType: self.inline_simple_type,
}
It solves my issue but I donot know if it is the right way to go.
Hi,
I have a issue in case of an OBJECT IDENTIFIER define with two args:
OBJECT IDENTIFIER (id-qt-cps | id-qt-unotice)
i think the character | is not handeled
find the ANS1 line 92
Thanks for help :)
PKIX1Implicit88.asn1.txt
RFC 4108 includes this syntax:
FirmwarePackageLoadReceipt ::= SEQUENCE {
version FWReceiptVersion DEFAULT v1,
hwType OBJECT IDENTIFIER,
hwSerialNum OCTET STRING,
... }
FWReceiptVersion ::= INTEGER { v1(1) }
When I used asn1ate to compile the module, it did not handle this part properly.
It produced:
class FWReceiptVersion(univ.Integer):
pass
FWReceiptVersion.namedValues = namedval.NamedValues(
('v1', 1)
)
FirmwarePackageLoadReceipt.componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('version', FWReceiptVersion().subtype(value=v1)),
namedtype.NamedType('hwType', univ.ObjectIdentifier()),
namedtype.NamedType('hwSerialNum', univ.OctetString()),
... )
It should have produced:
class FWReceiptVersion(univ.Integer):
pass
FWReceiptVersion.namedValues = namedval.NamedValues(
('v1', 1)
)
FirmwarePackageLoadReceipt.componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('version', FWReceiptVersion().subtype(value='v1')),
namedtype.NamedType('hwType', univ.ObjectIdentifier()),
namedtype.NamedType('hwSerialNum', univ.OctetString()),
....
)
Following ASN#1 fails:
Sequence ::= SEQUENCE {
a INTEGER,
b BOOLEAN,
c BIT STRING
}
This will generate the following error:
KeyError: <class 'asn1ate.sema.BitStringType'>
Hi,
I have some ASNs which have cyclic references. They are quite common in the protocols I'm looking at such as IEC 61850 and MMS.
Here is a minimal example:
CYCLIC DEFINITIONS ::=
BEGIN
Data ::= CHOICE {
a [1] INTEGER,
b [2] DataSequence
}
DataSequence ::= SEQUENCE OF Data
END
I'm hitting the exception on line 75 of sema.py. So it does seem to be explicitly disallowed. I'm quite handy in Python, but have absolutely no experience in pyparsing or parsers in general. Any comments on why cyclic references aren't handled and what would be involved in getting it there?
Thanks (great product otherwise!)
Related to a finding from Pelion manifest-tool - turns out the issue is actually in asn1ate.
Short conclusion: asn1ate
needs wheels
, it should ask for it in it's requirements.txt
.
(feature request)
This construct is popping up in RFCs and other specifications to an increasing degree. It would be splendid to have it added to asn1ate, and then also to asn2quickder.
Hi,
I have recently used asn1ate to translate ASN.1 file to python code.
The case of following cannot correctly generate code.
I paste the patch code to solve this.
FYI
Network-Device ::= SEQUENCE {
port-num INTEGER (0 .. 255),
port-lane INTEGER ( 0 | 1 | 2 | 4 ),
port-speed INTEGER ( 0 | 1000 | 10000 | 250000 ),
...
}
## patch code:
diff --git a/asn1ate/parser.py b/asn1ate/parser.py
index b8e3623..e9970a9 100644
--- a/asn1ate/parser.py
+++ b/asn1ate/parser.py
@@ -236,8 +236,9 @@ def _build_asn1_grammar():
# todo: consider the full subtype and general constraint syntax described in 45.*
lower_bound = (constraint_real_value | signed_number | referenced_value | MIN)
upper_bound = (constraint_real_value | signed_number | referenced_value | MAX)
- single_value_constraint = Suppress('(') + value + Suppress(')')
## \+ single_value_constraint = Suppress('(') + Optional(Group(delimitedList(value, delim='|'))) + Suppress(')')
Regards,
FredLien
The following input ASN1 definition:
Class-definitions DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
MultiplePLMN-List-r6 ::= SEQUENCE {
mibPLMN-Identity BOOLEAN,
multiplePLMNs SEQUENCE (SIZE (1..5)) OF
PLMN-IdentityWithOptionalMCC-r6
}
END
produces the following output, which is missing the size constraint on multiplePLMNs.
# Auto-generated by asn1ate v.0.5.1.dev from missing_size.asn1
# (last modified on 2016-09-07 12:30:06)
from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful
class MultiplePLMN_List_r6(univ.Sequence):
pass
MultiplePLMN_List_r6.componentType = namedtype.NamedTypes(
namedtype.NamedType('mibPLMN-Identity', univ.Boolean().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.NamedType('multiplePLMNs', univ.SequenceOf(componentType=PLMN_IdentityWithOptionalMCC_r6()).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
)
Since size contstraints work elsewhere on sequence-ofs, I suspect this problem is due to the sequence-of being nested inside a sequence.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.