From 5372dcda0dbf126899d5874c79a89b930c498d81 Mon Sep 17 00:00:00 2001 From: p1-bmu Date: Tue, 9 Nov 2021 15:48:17 +0100 Subject: [PATCH] asn1c: enable improper extension notation for size and alphabet constraint --- pycrate_asn1c/asnobj.py | 40 ++++++++++++++++++++++++++++++++-------- pycrate_asn1c/utils.py | 14 ++------------ pycrate_asn1dir/H225.py | 1 + pycrate_asn1dir/H245.py | 1 + 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/pycrate_asn1c/asnobj.py b/pycrate_asn1c/asnobj.py index 30eacc4..520b32f 100644 --- a/pycrate_asn1c/asnobj.py +++ b/pycrate_asn1c/asnobj.py @@ -4159,11 +4159,23 @@ class ASN1Obj(object): # 4) transfer references from ObjProxy to self if ObjProxy._ref: self._ref.update( ObjProxy._ref ) - + # + # 5) check for some more funny constraint + m = SYNT_RE_CONST_EXT.match(rest) + if m: + # previous constraint must be considered extensible + const = self.select(['const', const_index]) + if const['ext'] is None: + const['ext'] = [] + rest = rest[m.end():].lstrip() + elif rest[0:1] == '^': + # intersection with a 2nd constraint + self._parse_const('(%s)' % rest[1:].lstrip()) + # this is a hack, and this is bad + rest = '' if rest: - # may have ", ..." or "^ $other_constraint" - asnlog('WNG: remaining text for SIZE constraint, {1}'\ - .format(self.fullname(), rest)) + raise(ASN1ProcTextErr('{0}: remaining text for SIZE constraint, {1}'\ + .format(self.fullname(), rest))) def _parse_const_alphabet(self, const): const_index = len(self._const) @@ -4216,11 +4228,23 @@ class ASN1Obj(object): # 4) transfer references from ObjProxy to self if ObjProxy._ref: self._ref.update( ObjProxy._ref ) - + # + # 5) check for some more funny constraint + m = SYNT_RE_CONST_EXT.match(rest) + if m: + # previous constraint must be considered extensible + const = self.select(['const', const_index]) + if const['ext'] is None: + const['ext'] = [] + rest = rest[m.end():].lstrip() + elif rest[0:1] == '^': + # intersection with a 2nd constraint + self._parse_const('(%s)' % rest[1:].lstrip()) + # this is a hack, and this is bad + rest = '' if rest: - # may have ", ..." or "^ $other_constraint" - asnlog('WNG: remaining text for ALPHABET constraint, {1}'\ - .format(self.fullname(), rest)) + raise(ASN1ProcTextErr('{0}: remaining text for SIZE constraint, {1}'\ + .format(self.fullname(), rest))) def _parse_const_withcomp(self, const): const_index = len(self._const) diff --git a/pycrate_asn1c/utils.py b/pycrate_asn1c/utils.py index 8e01097..c859b74 100644 --- a/pycrate_asn1c/utils.py +++ b/pycrate_asn1c/utils.py @@ -334,18 +334,6 @@ SYNT_RE_MODULEDEF = re.compile( SYNT_RE_MODULEREF = re.compile( '(?:^|\s{1})(%s){1}\s{0,}(\{[\s\-a-zA-Z0-9\(\)]{1,}\}){0,1}' % _RE_TYPEREF) -''' -# FROM $ModuleRef $ModuleOIDOrOIDRef{0,1} -SYNT_RE_MODULEFROM = re.compile( - '(?:FROM\s{1,})(%s)' \ - '(?:\s*' \ - '(\{[\s\-a-zA-Z0-9\(\)]{1,}\})|' \ - '\s{1,}(%s)(?:\s{1,}%s(?:\s*\{\})?(?:\s*,|\s{1,}FROM)|\s*$)' \ - '){0,1}' \ - '(?:\s*WITH\s{1,}(SUCCESSORS|DESCENDANTS)){0,1}' \ - % (_RE_TYPEREF, _RE_IDENT, _RE_WORD)) - # TODO, catch "WITH SUCCESSORS" / "WITH DESCENDANTS" after the imported module name -''' SYNT_RE_MODULEFROM = re.compile( '(?:FROM\s{1,})(%s)\s*' % _RE_TYPEREF) SYNT_RE_MODULEFROM_SYM = re.compile( @@ -420,6 +408,8 @@ SYNT_RE_TIMEGENE = re.compile( SYNT_RE_CONST_DISPATCH = re.compile( '(?:^|\s{1})(INCLUDES)|(SIZE)|(FROM)|(WITH COMPONENTS)|(WITH COMPONENT)|' \ '(PATTERN)|(SETTINGS)|(CONTAINING)|(ENCODED BY)|(CONSTRAINED BY)') +SYNT_RE_CONST_EXT = re.compile( + ',\s{0,}\.\.\.') SYNT_RE_GROUPVERS = re.compile( '(?:^|\s{1})[0-9]{1,}\s{0,1}\:') diff --git a/pycrate_asn1dir/H225.py b/pycrate_asn1dir/H225.py index dbafb86..c124a01 100644 --- a/pycrate_asn1dir/H225.py +++ b/pycrate_asn1dir/H225.py @@ -7488,6 +7488,7 @@ class MULTIMEDIA_SYSTEM_CONTROL: _UserInputIndication_signal = SEQ(name=u'signal', mode=MODE_TYPE, tag=(3, TAG_CONTEXT_SPEC, TAG_IMPLICIT)) __UserInputIndication_signal_signalType = STR_IA5(name=u'signalType', mode=MODE_TYPE, tag=(0, TAG_CONTEXT_SPEC, TAG_IMPLICIT)) __UserInputIndication_signal_signalType._const_sz = ASN1Set(rv=[1], rr=[], ev=None, er=[]) + __UserInputIndication_signal_signalType._const_alpha = ASN1Set(rv=[u'0', u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9', u'#', u'*', u'A', u'B', u'C', u'D', u'!'], rr=[], ev=None, er=[]) __UserInputIndication_signal_duration = INT(name=u'duration', mode=MODE_TYPE, tag=(1, TAG_CONTEXT_SPEC, TAG_IMPLICIT), opt=True) __UserInputIndication_signal_duration._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=1, ub=65535)], ev=None, er=[]) __UserInputIndication_signal_rtp = SEQ(name=u'rtp', mode=MODE_TYPE, tag=(2, TAG_CONTEXT_SPEC, TAG_IMPLICIT), opt=True) diff --git a/pycrate_asn1dir/H245.py b/pycrate_asn1dir/H245.py index 5f9a1cc..2081a3f 100644 --- a/pycrate_asn1dir/H245.py +++ b/pycrate_asn1dir/H245.py @@ -6669,6 +6669,7 @@ class MULTIMEDIA_SYSTEM_CONTROL: _UserInputIndication_signal = SEQ(name=u'signal', mode=MODE_TYPE, tag=(3, TAG_CONTEXT_SPEC, TAG_IMPLICIT)) __UserInputIndication_signal_signalType = STR_IA5(name=u'signalType', mode=MODE_TYPE, tag=(0, TAG_CONTEXT_SPEC, TAG_IMPLICIT)) __UserInputIndication_signal_signalType._const_sz = ASN1Set(rv=[1], rr=[], ev=None, er=[]) + __UserInputIndication_signal_signalType._const_alpha = ASN1Set(rv=[u'0', u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9', u'#', u'*', u'A', u'B', u'C', u'D', u'!'], rr=[], ev=None, er=[]) __UserInputIndication_signal_duration = INT(name=u'duration', mode=MODE_TYPE, tag=(1, TAG_CONTEXT_SPEC, TAG_IMPLICIT), opt=True) __UserInputIndication_signal_duration._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=1, ub=65535)], ev=None, er=[]) __UserInputIndication_signal_rtp = SEQ(name=u'rtp', mode=MODE_TYPE, tag=(2, TAG_CONTEXT_SPEC, TAG_IMPLICIT), opt=True)