Skip to content
Open
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
17 changes: 11 additions & 6 deletions pycrate_asn1c/asnobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,17 @@ def get_asnobj(mod_name, obj_name):
mod = GLOBAL.MOD[mod_name]
except KeyError:
raise(ASN1Err('module {0}, undefined'.format(mod_name)))
# it is possible to import an object from a module which itsel imports it...
while obj_name in mod['_imp_']:
try:
mod = GLOBAL.MOD[mod['_imp_'][obj_name]]
except KeyError:
raise(ASN1Err('module {0}, undefined'.format(mod_name)))
if obj_name in mod:
# locally defined name, use it
pass
else:
# it is possible to import an object from a module which itsel imports it...
while obj_name in mod['_imp_']:
try:
impmods = mod['_imp_'][obj_name]
mod = GLOBAL.MOD[impmods[0]] # return the first IMPORTED name
except KeyError:
raise(ASN1Err('module {0}, undefined'.format(mod_name)))
try:
obj = mod[obj_name]
except KeyError:
Expand Down
19 changes: 10 additions & 9 deletions pycrate_asn1c/asnproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# *--------------------------------------------------------
#*/

import collections
import os
import re

Expand Down Expand Up @@ -186,7 +187,7 @@ def compile_text(text=u'', **kwargs):
- _tag_: str (EXPLICIT, IMPLICIT, AUTOMATIC), tagging mode of the module
- _ext_: str (IMPLIED) or None, extensibility mode of the module
- _exp_: list of str or None, list of objects' name exported
- _imp_: dict of imported objects' name (str) and corresponding module name (str)
- _imp_: dict of imported objects' name (str) to list(corresponding module names (str))
- _obj_: list of str, all objects' name defined in the module
- _type_: list of str, all ASN.1 subtypes' name defined in the module
- _val_: list of str, all ASN.1 values' name defined in the module
Expand Down Expand Up @@ -364,12 +365,12 @@ def _compile_text_pass(text, with_order, **kwargs):
#
# 5) scan the asnblock for module imports
imports, cur = module_get_import(asnblock)
module['_imp_'] = {}
module['_imp_'] = collections.defaultdict(list)
if cur:
asnblock = asnblock[cur:]
for imp in imports:
for obj_name in imp['obj']:
module['_imp_'][obj_name] = imp['name']
module['_imp_'][obj_name].append(imp['name'])
#
# 6) init objects lists for the module
module['_obj_'] = []
Expand All @@ -388,9 +389,6 @@ def _compile_text_pass(text, with_order, **kwargs):
if Obj._name in module:
raise(ASN1ProcTextErr('[proc]{0} module {1}: duplicate object, {2}'\
.format(fn, name, Obj._name)))
elif Obj._name in module['_imp_']:
raise(ASN1ProcTextErr('[proc]{0} module {1}: duplicate object with import, {2}'\
.format(fn, name, Obj._name)))
module[Obj._name] = Obj
module['_obj_'].append(Obj._name)
#
Expand Down Expand Up @@ -433,7 +431,7 @@ def build_implicit_mod():
module = GLOBAL.MOD['_IMPL_']
module['_name_'] = '_IMPL_'
module['_oid_'] = []
module['_imp_'] = {}
module['_imp_'] = collections.defaultdict(list)
module['_obj_'] = [TYPE_REAL, TYPE_EXT, TYPE_EMB_PDV, TYPE_CHAR_STR, TYPE_TYPEIDENT, TYPE_ABSSYNT]
GLOBAL.COMP['NS']['mod'] = '_IMPL_'
#
Expand Down Expand Up @@ -918,8 +916,11 @@ def init_ns_mod(mod_name):
# add module's local objects
GLOBAL.COMP['NS']['obj'].update(
dict((obj_name, mod_name) for obj_name in Mod if obj_name[0] != '_'))
# add module's imported objects
GLOBAL.COMP['NS']['obj'].update(GLOBAL.MOD[mod_name]['_imp_'])
# add module's imported objects only if not present
for imp_name, imp_mods in GLOBAL.MOD[mod_name]['_imp_'].items():
if imp_name not in GLOBAL.COMP['NS']['obj']:
GLOBAL.COMP['NS']['obj'][imp_name] = imp_mods[0]

# tagging and extensibility mode for the module
GLOBAL.COMP['NS']['tag'] = GLOBAL.MOD[mod_name]['_tag_']
GLOBAL.COMP['NS']['ext'] = GLOBAL.MOD[mod_name]['_ext_']
Expand Down
13 changes: 10 additions & 3 deletions pycrate_asn1c/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ def typeref_to_defin(Obj):
# which be misleading due to IMPORTS chain)
else:
(modname, objname) = Obj._typeref.called
while objname in GLOBAL.MOD[modname]['_imp_']:
modname = GLOBAL.MOD[modname]['_imp_'][objname]
if objname in GLOBAL.MOD[modname]:
# locally defined name, use it
pass
else:
while objname in GLOBAL.MOD[modname]['_imp_']:
modname = GLOBAL.MOD[modname]['_imp_'][objname][0]
if isinstance(Obj._typeref, ASN1RefType):
return 'ASN1RefType((\'{0}\', \'{1}\'))'.format(modname, objname)
elif isinstance(Obj._typeref, ASN1RefClassField):
Expand Down Expand Up @@ -1047,6 +1051,7 @@ def gen(self):
for name in GLOBAL.MOD[mod]['_obj_']:
nodes.append('{"id": "%s.%s", "group": %i},'\
% (mod, name, groups.index(mod)))
nodes.sort()
# remove last coma
#nodes[-1] = nodes[-1][:-1]
last_node = nodes[-1]
Expand All @@ -1071,9 +1076,11 @@ def gen(self):
# we must ensure that tgt is really defined within tgt.called[0]
# and not imported from another module
while tgt[1] not in GLOBAL.MOD[tgt[0]]:
tgt[0] = GLOBAL.MOD[tgt[0]]['_imp_'][tgt[1]]
# use the first imported module for name tgt[1]
tgt[0] = GLOBAL.MOD[tgt[0]]['_imp_'][tgt[1]][0]
links.append('{"source": "%s.%s", "target": "%s.%s", "value": %i},'\
% (mod, name, tgt[0], tgt[1], self.LINK_FORCE))
links.sort()
# remove last coma
#links[-1] = links[-1][:-1]
last_link = links[-1]
Expand Down
34 changes: 17 additions & 17 deletions pycrate_asn1dir/AESCCMGCM.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"_comment": "code automatically generated by pycrate_asn1c",
"nodes": [
{"id": "_IMPL_.REAL", "group": 0},
{"id": "_IMPL_.EXTERNAL", "group": 0},
{"id": "_IMPL_.EMBEDDED PDV", "group": 0},
{"id": "_IMPL_.CHARACTER STRING", "group": 0},
{"id": "_IMPL_.TYPE-IDENTIFIER", "group": 0},
{"id": "_IMPL_.ABSTRACT-SYNTAX", "group": 0},
{"id": "CMS-AES-CCM-and-AES-GCM.AES-CCM-ICVlen", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.AES-GCM-ICVlen", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.CCMParameters", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.GCMParameters", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.aes", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes128-CCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes192-CCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes256-CCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes128-GCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes192-CCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes192-GCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes256-CCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.id-aes256-GCM", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.CCMParameters", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.AES-CCM-ICVlen", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.GCMParameters", "group": 2},
{"id": "CMS-AES-CCM-and-AES-GCM.AES-GCM-ICVlen", "group": 2}
{"id": "_IMPL_.ABSTRACT-SYNTAX", "group": 0},
{"id": "_IMPL_.CHARACTER STRING", "group": 0},
{"id": "_IMPL_.EMBEDDED PDV", "group": 0},
{"id": "_IMPL_.EXTERNAL", "group": 0},
{"id": "_IMPL_.REAL", "group": 0},
{"id": "_IMPL_.TYPE-IDENTIFIER", "group": 0}
],
"links": [
{"source": "CMS-AES-CCM-and-AES-GCM.CCMParameters", "target": "CMS-AES-CCM-and-AES-GCM.AES-CCM-ICVlen", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.GCMParameters", "target": "CMS-AES-CCM-and-AES-GCM.AES-GCM-ICVlen", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes128-CCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes192-CCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes256-CCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes128-GCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes192-CCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes192-GCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes256-GCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.CCMParameters", "target": "CMS-AES-CCM-and-AES-GCM.AES-CCM-ICVlen", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.GCMParameters", "target": "CMS-AES-CCM-and-AES-GCM.AES-GCM-ICVlen", "value": 1}
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes256-CCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1},
{"source": "CMS-AES-CCM-and-AES-GCM.id-aes256-GCM", "target": "CMS-AES-CCM-and-AES-GCM.aes", "value": 1}
]
}
Loading