Merge branch 'OER_implementation' of https://github.com/JNevrly/pycrate into JNevrly-OER_implementation
This commit is contained in:
commit
f6ded2c3ec
|
@ -1724,7 +1724,7 @@ class ASN1Obj(Element):
|
|||
###
|
||||
# conversion between internal value and ASN.1 JER encoding
|
||||
###
|
||||
|
||||
|
||||
if _with_json:
|
||||
|
||||
def _from_jval(self, val):
|
||||
|
@ -1756,6 +1756,106 @@ class ASN1Obj(Element):
|
|||
to_json = to_jer
|
||||
from_json = from_jer
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _from_oer(self, char):
|
||||
raise (ASN1NotSuppErr(self.fullname()))
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
raise (ASN1NotSuppErr(self.fullname()))
|
||||
|
||||
def _to_oer(self):
|
||||
raise (ASN1NotSuppErr(self.fullname()))
|
||||
|
||||
def _to_oer_ws(self):
|
||||
raise (ASN1NotSuppErr(self.fullname()))
|
||||
|
||||
def from_oer(self, buf):
|
||||
# ASN1CodecOER.CANONICAL = False
|
||||
if isinstance(buf, bytes_types):
|
||||
char = Charpy(buf)
|
||||
else:
|
||||
char = buf
|
||||
|
||||
self._from_oer(char)
|
||||
|
||||
if self._SAFE_BND:
|
||||
self._safechk_bnd(self._val)
|
||||
|
||||
def from_oer_ws(self, buf):
|
||||
# ASN1CodecOER.CANONICAL = False
|
||||
if isinstance(buf, bytes_types):
|
||||
char = Charpy(buf)
|
||||
else:
|
||||
char = buf
|
||||
|
||||
self._from_oer_ws(char)
|
||||
|
||||
if self._SAFE_BND:
|
||||
self._safechk_bnd(self._val)
|
||||
|
||||
def to_oer(self, val=None):
|
||||
ASN1CodecOER.CANONICAL = False
|
||||
if val is not None:
|
||||
self.set_val(val)
|
||||
if self._val is not None:
|
||||
ret = pack_val(*self._to_oer())[0]
|
||||
if ret:
|
||||
return ret
|
||||
else:
|
||||
return b'\0'
|
||||
else:
|
||||
return None
|
||||
|
||||
def to_oer_ws(self, val=None):
|
||||
ASN1CodecOER.CANONICAL = False
|
||||
if val is not None:
|
||||
self.set_val(val)
|
||||
if self._val is not None:
|
||||
_struct = self._to_oer_ws()
|
||||
ret = _struct.to_bytes()
|
||||
if ret:
|
||||
return ret
|
||||
else:
|
||||
return b'\0'
|
||||
else:
|
||||
return None
|
||||
|
||||
def from_coer(self, buf):
|
||||
self.from_oer(buf)
|
||||
|
||||
def from_coer_ws(self, buf):
|
||||
self.from_oer_ws(buf)
|
||||
|
||||
def to_coer(self, val=None):
|
||||
ASN1CodecOER.CANONICAL = True
|
||||
if val is not None:
|
||||
self.set_val(val)
|
||||
if self._val is not None:
|
||||
ret = pack_val(*self._to_oer())[0]
|
||||
if ret:
|
||||
return ret
|
||||
else:
|
||||
return b'\0'
|
||||
else:
|
||||
return None
|
||||
|
||||
def to_coer_ws(self, val=None):
|
||||
ASN1CodecOER.CANONICAL = True
|
||||
if val is not None:
|
||||
self.set_val(val)
|
||||
if self._val is not None:
|
||||
_struct = self._to_oer_ws()
|
||||
ret = _struct.to_bytes()
|
||||
if ret:
|
||||
return ret
|
||||
else:
|
||||
return b'\0'
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def _save_ber_params():
|
||||
global __ber_enc_llong
|
||||
|
|
|
@ -136,6 +136,22 @@ Single value: int 0
|
|||
def _to_jval(self):
|
||||
return None
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _from_oer(self, char):
|
||||
self._from_per(char)
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
self._from_per_ws()
|
||||
|
||||
def _to_oer(self):
|
||||
return self._to_per()
|
||||
|
||||
def _to_oer_ws(self):
|
||||
return self._to_per_ws()
|
||||
|
||||
|
||||
class BOOL(ASN1Obj):
|
||||
__doc__ = """
|
||||
|
@ -152,6 +168,8 @@ Single value: Python bool
|
|||
_ASN_LUT = {'FALSE': False, 'TRUE': True, False: 'FALSE', True: 'TRUE'}
|
||||
_PER_LUT = {0: False, 1: True}
|
||||
_PER_LUTR = {False: 0, True: 1}
|
||||
_OER_LUT = {ASN1CodecOER.TRUE: True, ASN1CodecOER.FALSE: False}
|
||||
_OER_LUTS = {ASN1CodecOER.FALSE: 'FALSE', ASN1CodecOER.TRUE: 'TRUE'}
|
||||
|
||||
def _safechk_val(self, val):
|
||||
if not isinstance(val, bool):
|
||||
|
@ -263,7 +281,31 @@ Single value: Python bool
|
|||
|
||||
def _to_jval(self):
|
||||
return self._val
|
||||
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _from_oer(self, char):
|
||||
self._val = (char.get_uint(8) > ASN1CodecOER.FALSE)
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
self._struct = Envelope(self._name, GEN=(
|
||||
Uint('V', bl=8, dic=self._OER_LUTS), ))
|
||||
self._struct._from_char(char)
|
||||
self._val = self._OER_LUT[self._struct[0]._val]
|
||||
|
||||
def _to_oer(self):
|
||||
# actually, COER only
|
||||
val = ASN1CodecOER.TRUE if (self._val is True) else ASN1CodecOER.FALSE
|
||||
return [(T_UINT, val, 8)]
|
||||
|
||||
def _to_oer_ws(self):
|
||||
# actually, COER only
|
||||
val = ASN1CodecOER.TRUE if (self._val is True) else ASN1CodecOER.FALSE
|
||||
self._struct = Envelope(self._name, GEN=(
|
||||
Uint('V', bl=8, val=val, dic=self._OER_LUTS), ))
|
||||
return self._struct
|
||||
|
||||
#------------------------------------------------------------------------------#
|
||||
# INTEGER and REAL
|
||||
|
@ -544,6 +586,78 @@ Specific attribute:
|
|||
self._names_to_val()
|
||||
return self._val
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _to_oer(self):
|
||||
if self._const_val:
|
||||
# Constraints defined
|
||||
if self._const_val.ext is not None:
|
||||
# Extensible OER-visible constraints are encoded as integer
|
||||
# type with no bounds
|
||||
return ASN1CodecOER.encode_intunconst(self._val)
|
||||
|
||||
# Constrained
|
||||
return ASN1CodecOER.encode_intconst(self._val, self._const_val)
|
||||
else:
|
||||
# Unconstrained
|
||||
return ASN1CodecOER.encode_intunconst(self._val)
|
||||
|
||||
def _to_oer_ws(self):
|
||||
if self._const_val:
|
||||
# Constraints defined
|
||||
if self._const_val.ext is not None:
|
||||
# Extensible OER-visible constraints are encoded as integer
|
||||
# type with no bounds
|
||||
self._struct = Envelope(
|
||||
self._name,
|
||||
GEN=ASN1CodecOER.encode_intunconst_ws(self._val))
|
||||
return self._struct
|
||||
|
||||
# Constrained
|
||||
self._struct = Envelope(
|
||||
self._name,
|
||||
GEN=ASN1CodecOER.encode_intconst_ws(self._val, self._const_val)
|
||||
)
|
||||
return self._struct
|
||||
else:
|
||||
# Unconstrained
|
||||
self._struct = Envelope(
|
||||
self._name,
|
||||
GEN=ASN1CodecOER.encode_intunconst_ws(self._val)
|
||||
)
|
||||
return self._struct
|
||||
|
||||
def _from_oer(self, char):
|
||||
if self._const_val:
|
||||
if self._const_val.ext is not None:
|
||||
self._val = ASN1CodecOER.decode_intunconst(char)
|
||||
return
|
||||
|
||||
# Constrained
|
||||
self._val = ASN1CodecOER.decode_intconst(char, self._const_val)
|
||||
return
|
||||
else:
|
||||
# Unconstrained
|
||||
self._val = ASN1CodecOER.decode_intunconst(char)
|
||||
return
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
if self._const_val:
|
||||
if self._const_val.ext is not None:
|
||||
self._val, _gen = ASN1CodecOER.decode_intunconst_ws(char)
|
||||
self._struct = Envelope(self._name, GEN=_gen)
|
||||
return
|
||||
|
||||
# Constrained
|
||||
self._val, _gen = ASN1CodecOER.decode_intconst_ws(char, self._const_val)
|
||||
self._struct = Envelope(self._name, GEN=_gen)
|
||||
else:
|
||||
# Unconstrained
|
||||
self._val, _gen = ASN1CodecOER.decode_intunconst_ws(char)
|
||||
self._struct = Envelope(self._name, GEN=_gen)
|
||||
|
||||
|
||||
class REAL(ASN1Obj):
|
||||
__doc__ = """
|
||||
|
@ -937,6 +1051,167 @@ Specific attribute:
|
|||
# lead to an integer encoding instead of this scientific notation
|
||||
return {'base10Value': '%ie%i' % (self._val[0], self._val[2])}
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
# Assuming pycrate takes care of constraints
|
||||
if ((self._const_val is not None) and
|
||||
(not self._const_val.in_root(None)) and
|
||||
(self._const_val.ext is None)):
|
||||
# Check for constraints
|
||||
lb = self._const_val.root[0].lb
|
||||
ub = self._const_val.root[0].ub
|
||||
if lb[1] == ub[1] == 2: # Automatically excludes +/- Inf
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MAX))):
|
||||
buf = Buf('V', bl=32)
|
||||
buf._from_char(char)
|
||||
self._struct = Envelope(self._name, GEN=(buf,))
|
||||
self._val = decode_ieee754_32(Charpy(buf.to_bytes()))
|
||||
return
|
||||
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MAX))):
|
||||
buf = Buf('V', bl=64)
|
||||
buf._from_char(char)
|
||||
self._struct = Envelope(self._name, GEN=(buf,))
|
||||
self._val = decode_ieee754_64(Charpy(buf.to_bytes()))
|
||||
return
|
||||
|
||||
# else DER
|
||||
l_val, _gen = ASN1CodecOER.decode_length_determinant_ws(char)
|
||||
buf = Buf('V', bl=l_val*8)
|
||||
buf._from_char(char)
|
||||
_gen.append(buf)
|
||||
self._struct = Envelope(self._name, GEN=(_gen,))
|
||||
self.from_der(buf.to_bytes())
|
||||
|
||||
def _from_oer(self, char):
|
||||
# Assuming pycrate takes care of constraints
|
||||
if ((self._const_val is not None) and
|
||||
(not self._const_val.in_root(None)) and
|
||||
(self._const_val.ext is None)):
|
||||
# Check for constraints
|
||||
lb = self._const_val.root[0].lb
|
||||
ub = self._const_val.root[0].ub
|
||||
if lb[1] == ub[1] == 2: # Automatically excludes +/- Inf
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MAX))):
|
||||
self._val = decode_ieee754_32(char)
|
||||
return
|
||||
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MAX))):
|
||||
self._val = decode_ieee754_64(char)
|
||||
return
|
||||
|
||||
# else DER
|
||||
l_val = ASN1CodecOER.decode_length_determinant(char)
|
||||
val = char.get_bytes(l_val*8)
|
||||
self.from_der(val)
|
||||
|
||||
def _to_oer_ws(self):
|
||||
# Assuming pycrate takes care of constraints
|
||||
if ((self._const_val is not None) and
|
||||
(not self._const_val.in_root(None)) and
|
||||
(self._const_val.ext is None)):
|
||||
# Check for constraints
|
||||
lb = self._const_val.root[0].lb
|
||||
ub = self._const_val.root[0].ub
|
||||
if lb[1] == ub[1] == 2: # Automatically excludes +/- Inf
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MAX))):
|
||||
_gen = (Buf('V', val=encode_ieee754_32(self._val), bl=32),)
|
||||
self._struct = Envelope(self._name, GEN=_gen)
|
||||
return self._struct
|
||||
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MAX))):
|
||||
_gen = (Buf('V', val=encode_ieee754_64(self._val), bl=64),)
|
||||
self._struct = Envelope(self._name, GEN=_gen)
|
||||
return self._struct
|
||||
|
||||
# else DER
|
||||
val = self.to_der() # not to_det_ws!!!, we are only interested in buf
|
||||
l_val = len(val)
|
||||
_gen = ASN1CodecOER.encode_length_determinant_ws(len(val))
|
||||
_gen.append(Buf('V', val=val, bl=l_val*8))
|
||||
self._struct = Envelope(self._name, GEN=(_gen,))
|
||||
return self._struct
|
||||
|
||||
def _to_oer(self):
|
||||
# Assuming pycrate takes care of constraints
|
||||
if ((self._const_val is not None) and
|
||||
(not self._const_val.in_root(None)) and
|
||||
(self._const_val.ext is None)):
|
||||
# Check for constraints
|
||||
lb = self._const_val.root[0].lb
|
||||
ub = self._const_val.root[0].ub
|
||||
if lb[1] == ub[1] == 2: # Automatically excludes +/- Inf
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_32_MANTIS_MAX))):
|
||||
return [(T_BYTES, encode_ieee754_32(self._val), 32)]
|
||||
|
||||
if (((min(lb[3], ub[3]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_EXP_MAX)) and
|
||||
((min(lb[0], ub[0]) >=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MIN) and
|
||||
(max(lb[3], ub[3]) <=
|
||||
ASN1CodecOER.REAL_IEEE754_64_MANTIS_MAX))):
|
||||
return [(T_BYTES, encode_ieee754_64(self._val), 64)]
|
||||
|
||||
# else DER
|
||||
val = self.to_der()
|
||||
l_val = len(val)
|
||||
GEN = ASN1CodecOER.encode_length_determinant(len(val))
|
||||
GEN.append((T_BYTES, val, l_val*8))
|
||||
return GEN
|
||||
|
||||
#------------------------------------------------------------------------------#
|
||||
# ENUMERATED, OID and RELATIVE-OID
|
||||
|
@ -1254,6 +1529,63 @@ Specific attribute:
|
|||
def _to_jval(self):
|
||||
return self._val
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _get_index(self):
|
||||
try:
|
||||
ind = self._cont[self._val]
|
||||
except KeyError:
|
||||
if self._ext is not None:
|
||||
# Just try to convert the value into an index
|
||||
try:
|
||||
ind = int(self._val)
|
||||
except ValueError:
|
||||
try:
|
||||
# The pycrate "_ext_" format
|
||||
ind = int(self._val[5:])
|
||||
except ValueError:
|
||||
raise ASN1OEREncodeErr(
|
||||
"{0}: invalid ENUMERATED value, {1}".format(
|
||||
self.fullname(),
|
||||
self._val))
|
||||
return ind
|
||||
|
||||
def _get_index_value(self, index):
|
||||
try:
|
||||
val = self._cont_rev[index]
|
||||
except (KeyError):
|
||||
if self._ext is not None:
|
||||
if not self._SILENT:
|
||||
asnlog('ENUM._from_oer: %s, unknown extension value %r' \
|
||||
% (self._name, index))
|
||||
# Just try to convert the value into an index
|
||||
val = '_ext_%r' % index
|
||||
else:
|
||||
raise (ASN1OERDecodeErr(
|
||||
'{0}: invalid ENUMERATED value, {1}'.format(self.fullname(),
|
||||
index)))
|
||||
|
||||
return val
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
index, _gen = ASN1CodecOER.decode_enumerated_ws(char)
|
||||
self._val = self._get_index_value(index)
|
||||
self._struct = Envelope(self._name, GEN=(_gen,))
|
||||
|
||||
def _from_oer(self, char):
|
||||
self._val = self._get_index_value(ASN1CodecOER.decode_enumerated(char))
|
||||
|
||||
def _to_oer_ws(self):
|
||||
self._struct = Envelope(self._name, GEN=(
|
||||
ASN1CodecOER.encode_enumerated_ws(self._get_index()),
|
||||
))
|
||||
return self._struct
|
||||
|
||||
def _to_oer(self):
|
||||
return ASN1CodecOER.encode_enumerated(self._get_index())
|
||||
|
||||
|
||||
class _OID(ASN1Obj):
|
||||
|
||||
|
@ -1374,6 +1706,35 @@ class _OID(ASN1Obj):
|
|||
def _to_jval(self):
|
||||
return '.'.join(map(str, self._val))
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
def _to_oer(self):
|
||||
_, l_val, _gen = self._encode_ber_cont()
|
||||
det = ASN1CodecOER.encode_length_determinant(l_val)
|
||||
det.extend(_gen)
|
||||
return det
|
||||
|
||||
def _to_oer_ws(self):
|
||||
_, l_val, _gen = self._encode_ber_cont_ws()
|
||||
det = ASN1CodecOER.encode_length_determinant_ws(l_val)
|
||||
det.append(_gen)
|
||||
self._struct = Envelope(self._name, GEN=tuple(det))
|
||||
return self._struct
|
||||
|
||||
def _from_oer(self, char):
|
||||
l_val = ASN1CodecOER.decode_length_determinant(char)
|
||||
buf = char.get_bytes(l_val * 8)
|
||||
self._decode_cont(buf)
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
l_val, det = ASN1CodecOER.decode_length_determinant_ws(char)
|
||||
buf = Buf('V', bl=l_val*8)
|
||||
buf._from_char(char)
|
||||
det.append(buf)
|
||||
self._decode_cont(buf.to_bytes())
|
||||
return Envelope(self._name, GEN=tuple(det))
|
||||
|
||||
|
||||
class OID(_OID):
|
||||
__doc__ = """
|
||||
|
|
|
@ -580,6 +580,146 @@ Specific attributes:
|
|||
ret = {ident[5:] : self._val[1]}
|
||||
return ret
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _oer_tag_class(self):
|
||||
try:
|
||||
tag_class, tag = next(t for t, ident in self._cont_tags.items()
|
||||
if ident == self._val[0])
|
||||
except StopIteration:
|
||||
if self._val[0][:5] == '_ext_':
|
||||
# unknown extension re-encoding
|
||||
tag_class, _, tag = int(self._val[0][5:6]), int(
|
||||
self._val[0][6:7]), int(self._val[0][7:])
|
||||
else:
|
||||
raise ASN1OEREncodeErr("Unknown tag for item {0}".format(
|
||||
self._val[0]))
|
||||
try:
|
||||
tag_class = ASN1CodecOER.TagClassLUT[tag_class]
|
||||
except KeyError:
|
||||
ASN1OEREncodeErr("Unknown tag class: {0}".format(tag_class))
|
||||
|
||||
return tag_class, tag
|
||||
|
||||
def _to_oer(self):
|
||||
tag_class, tag = self._oer_tag_class()
|
||||
|
||||
# Tag
|
||||
temp = ASN1CodecOER.encode_tag(tag, tag_class)
|
||||
|
||||
if self._val[0] in self._root:
|
||||
# Normal encoding
|
||||
# Value
|
||||
Cho = self._cont[self._val[0]]
|
||||
Cho._val = self._val[1]
|
||||
temp.extend(Cho._to_oer())
|
||||
|
||||
elif self._ext is not None:
|
||||
# Extensible type
|
||||
if self._val[0] in self._ext:
|
||||
Cho = self._cont[self._val[0]]
|
||||
Cho._val = self._val[1]
|
||||
temp.extend(ASN1CodecOER.encode_open_type(Cho.to_oer()))
|
||||
else:
|
||||
temp.extend(ASN1CodecOER.encode_open_type(self._val[1]))
|
||||
|
||||
return temp
|
||||
|
||||
def _to_oer_ws(self):
|
||||
tag_class, tag = self._oer_tag_class()
|
||||
|
||||
# Tag
|
||||
temp = [ASN1CodecOER.encode_tag_ws(tag, tag_class)]
|
||||
|
||||
if self._val[0] in self._root:
|
||||
# Normal encoding
|
||||
# Value
|
||||
Cho = self._cont[self._val[0]]
|
||||
Cho._val = self._val[1]
|
||||
temp.append(Cho._to_oer_ws())
|
||||
elif self._ext is not None:
|
||||
# Extensible type
|
||||
if self._val[0] in self._ext:
|
||||
Cho = self._cont[self._val[0]]
|
||||
Cho._val = self._val[1]
|
||||
temp.append(ASN1CodecOER.encode_open_type_ws(Cho.to_oer()))
|
||||
else:
|
||||
temp.append(ASN1CodecOER.encode_open_type_ws(self._val[1]))
|
||||
|
||||
self._struct = Envelope(self._name, GEN=tuple(temp))
|
||||
return self._struct
|
||||
|
||||
def _from_oer(self, char):
|
||||
tag_class, tag = ASN1CodecOER.decode_tag(char)
|
||||
try:
|
||||
tag_class = ASN1CodecOER.TagClassLUT[tag_class]
|
||||
except KeyError:
|
||||
ASN1OEREncodeErr("Unknown tag class: {0}".format(tag_class))
|
||||
|
||||
try:
|
||||
ident = self._cont_tags[(tag_class, tag)]
|
||||
Cho = self._cont[ident]
|
||||
_par = Cho._parent
|
||||
Cho._parent = self
|
||||
if self._ext and (ident in self._ext):
|
||||
val_bytes = ASN1CodecOER.decode_open_type(char)
|
||||
Cho.from_oer(val_bytes)
|
||||
if ident in self._root:
|
||||
Cho.from_oer(char)
|
||||
Cho._parent = _par
|
||||
self._val = (ident, Cho._val)
|
||||
except KeyError:
|
||||
if self._ext is not None:
|
||||
# It's extension type
|
||||
if not self._SILENT:
|
||||
asnlog('CHOICE._from_oer: %s, unknown extension tag %r' \
|
||||
% (self.fullname(), (tag_class, tag)))
|
||||
# NOTE: There is no way how to resolve the primitive/constructed
|
||||
# flag in OER, as far as I understand it.
|
||||
ident = "_ext_{0}{1}{2}".format(tag_class, 0, tag)
|
||||
val_bytes = ASN1CodecOER.decode_open_type(char)
|
||||
self._val = (ident, val_bytes)
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
tag_class, tag, tag_struct = ASN1CodecOER.decode_tag_ws(char)
|
||||
try:
|
||||
tag_class = ASN1CodecOER.TagClassLUT[tag_class]
|
||||
except KeyError:
|
||||
ASN1OEREncodeErr("Unknown tag class: {0}".format(tag_class))
|
||||
|
||||
_gen = [tag_struct]
|
||||
try:
|
||||
ident = self._cont_tags[(tag_class, tag)]
|
||||
Cho = self._cont[ident]
|
||||
_par = Cho._parent
|
||||
Cho._parent = self
|
||||
if self._ext and (ident in self._ext):
|
||||
val_bytes, val_struct = ASN1CodecOER.decode_open_type_ws(char)
|
||||
_gen.append(val_struct)
|
||||
Cho.from_oer_ws(val_bytes)
|
||||
if ident in self._root:
|
||||
Cho.from_oer_ws(char)
|
||||
_gen.extend(Cho._struct)
|
||||
Cho._parent = _par
|
||||
self._struct = Envelope(self._name, GEN=tuple(_gen) )
|
||||
self._val = (ident, Cho._val)
|
||||
return
|
||||
except KeyError:
|
||||
if self._ext is not None:
|
||||
# It's extension type
|
||||
if not self._SILENT:
|
||||
asnlog('CHOICE._from_oer_ws: %s, unknown extension tag %r' \
|
||||
% (self.fullname(), (tag_class, tag)))
|
||||
# NOTE: There is no way how to resolve the primitive/constructed
|
||||
# flag in OER, as far as I understand it.
|
||||
ident = "_ext_{0}{1}{2}".format(tag_class, 0, tag)
|
||||
val_bytes, val_struct = ASN1CodecOER.decode_open_type_ws(char)
|
||||
_gen.append(val_struct)
|
||||
val = val_struct.get_val()
|
||||
self._struct = Envelope(self._name, GEN=tuple(_gen))
|
||||
self._val = (ident, val)
|
||||
|
||||
#------------------------------------------------------------------------------#
|
||||
# SEQUENCE and SET
|
||||
|
@ -1166,6 +1306,471 @@ class _CONSTRUCT(ASN1Obj):
|
|||
ret['_ext_%s' % ident] = comp_val
|
||||
return ret
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _to_oer(self):
|
||||
GEN = []
|
||||
if not self._cont and self._ext is None:
|
||||
# empty sequence
|
||||
return GEN
|
||||
|
||||
extended = False
|
||||
ext_bit = 0
|
||||
if self._ext is not None:
|
||||
# check if some extended components are provided
|
||||
for k in self._val:
|
||||
if k in self._ext or k[:5] == '_ext_':
|
||||
extended = True
|
||||
break
|
||||
|
||||
GEN.append((T_UINT, (1 if extended else 0), 1))
|
||||
ext_bit = 1
|
||||
|
||||
# generate the bitmap preambule for optional / default components of the root part
|
||||
opt_len = 0
|
||||
Bv = 0
|
||||
if self._root_opt:
|
||||
opt_len, opt_idents = len(self._root_opt), []
|
||||
for i in range(opt_len):
|
||||
ident = self._root_opt[i]
|
||||
if ident in self._val:
|
||||
if self._val[ident] == self._cont[ident]._def:
|
||||
# the value provided equals the default one
|
||||
# hence will not be encoded
|
||||
if not self._SILENT:
|
||||
asnlog('_CONSTRUCT._to_per: %s.%s, removing value equal ' \
|
||||
'to the default one' % (self.fullname(), ident))
|
||||
del self._val[ident]
|
||||
else:
|
||||
# component present in the encoding
|
||||
Bv += 1<<(opt_len-1-i)
|
||||
opt_idents.append(ident)
|
||||
else:
|
||||
opt_idents = []
|
||||
|
||||
# Padding bits
|
||||
pad_bits = 8 - ((opt_len + ext_bit) % 8)
|
||||
pad_bits = 0 if (pad_bits == 8) else pad_bits
|
||||
Bv = Bv << pad_bits
|
||||
GEN.append( (T_UINT, Bv, opt_len + pad_bits) )
|
||||
|
||||
# encode components in the root part
|
||||
if self.TYPE == TYPE_SET:
|
||||
root_canon = self._root_canon
|
||||
else:
|
||||
root_canon = self._root
|
||||
for ident in root_canon:
|
||||
if ident in self._val:
|
||||
# component present in the encoding
|
||||
Comp = self._cont[ident]
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
Comp._val = self._val[ident]
|
||||
GEN.extend( Comp._to_oer() )
|
||||
Comp._parent = _par
|
||||
|
||||
# encode components in the extension part
|
||||
if extended:
|
||||
# generate the structure for all known present extension
|
||||
_gen_ext, Bm, cnt = [], [], 1
|
||||
for ident in self._ext_nest:
|
||||
if isinstance(ident, list):
|
||||
# group of extension
|
||||
grp_val, gid = {}, None
|
||||
for ident_inner in ident:
|
||||
if ident_inner in self._val:
|
||||
grp_val[ident_inner] = self._val[ident_inner]
|
||||
if gid is None:
|
||||
gid = self._ext_ident[ident_inner]
|
||||
if grp_val:
|
||||
# group present in the encoding
|
||||
Comp = self._ext_group_obj[gid]
|
||||
Comp._val = grp_val
|
||||
_gen_ext.extend( ASN1CodecOER.encode_open_type(
|
||||
Comp.to_oer() ))
|
||||
Bm.append(cnt)
|
||||
else:
|
||||
if ident in self._val:
|
||||
# single extension
|
||||
Comp = self._cont[ident]
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
Comp._val = self._val[ident]
|
||||
_gen_ext.extend( ASN1CodecOER.encode_open_type(
|
||||
Comp.to_oer()))
|
||||
Comp._parent = _par
|
||||
Bm.append(cnt)
|
||||
cnt += 1
|
||||
|
||||
# generate the structure for all unknown present extension
|
||||
unk_idents = [i for i in self._val if i[:5] == '_ext_']
|
||||
if unk_idents:
|
||||
# sort by index set to the ident
|
||||
unk_idents.sort(key=lambda x:int(x[5:]))
|
||||
for ident in unk_idents:
|
||||
ind = int(ident[5:])
|
||||
if ind >= cnt and ind not in Bm:
|
||||
_gen_ext.extend( ASN1CodecOER.encode_open_type(
|
||||
self._val[ident]) )
|
||||
Bm.append(ind)
|
||||
elif not self._SILENT:
|
||||
asnlog('_CONSTRUCT._to_oer: %s.%s, '
|
||||
'invalid unknown extension index' \
|
||||
% (self.fullname(), ident))
|
||||
|
||||
if not Bm:
|
||||
return GEN
|
||||
|
||||
# generate the bitmap preambule for extended (group of) components
|
||||
# bitmap length is encoded with a normally small value
|
||||
ldet = max(max(Bm), len(self._ext_nest))
|
||||
ext_bitmap = 0
|
||||
for i in Bm:
|
||||
ext_bitmap = ext_bitmap | (1<<(ldet-i))
|
||||
pad_bits = uint_bytelen(ext_bitmap)*8 - ldet
|
||||
ext_bitmap = ext_bitmap << pad_bits
|
||||
ext_bmp_len = pad_bits + ldet
|
||||
GEN.extend(ASN1CodecOER.encode_length_determinant(1 +
|
||||
ext_bmp_len//8))
|
||||
GEN.append( (T_UINT, pad_bits, 8) )
|
||||
GEN.append( (T_UINT, ext_bitmap, ext_bmp_len) )
|
||||
GEN.extend(_gen_ext)
|
||||
|
||||
return GEN
|
||||
|
||||
def _to_oer_ws(self):
|
||||
GEN = []
|
||||
if not self._cont and self._ext is None:
|
||||
# empty sequence
|
||||
return GEN
|
||||
|
||||
extended = False
|
||||
ext_bit = 0
|
||||
if self._ext is not None:
|
||||
# check if some extended components are provided
|
||||
for k in self._val:
|
||||
if k in self._ext or k[:5] == '_ext_':
|
||||
extended = True
|
||||
break
|
||||
|
||||
GEN.append(Uint('Extension', val=(1 if extended else 0), bl=1))
|
||||
ext_bit = 1
|
||||
|
||||
# generate the bitmap preambule for optional / default components of the root part
|
||||
opt_len = 0
|
||||
Bv = 0
|
||||
if self._root_opt:
|
||||
opt_len, opt_idents = len(self._root_opt), []
|
||||
for i in range(opt_len):
|
||||
ident = self._root_opt[i]
|
||||
if ident in self._val:
|
||||
if self._val[ident] == self._cont[ident]._def:
|
||||
# the value provided equals the default one
|
||||
# hence will not be encoded
|
||||
if not self._SILENT:
|
||||
asnlog('_CONSTRUCT._to_per: %s.%s, removing value equal ' \
|
||||
'to the default one' % (self.fullname(), ident))
|
||||
del self._val[ident]
|
||||
else:
|
||||
# component present in the encoding
|
||||
Bv += 1<<(opt_len-1-i)
|
||||
opt_idents.append(ident)
|
||||
else:
|
||||
opt_idents = []
|
||||
|
||||
# Padding bits
|
||||
pad_bits = 8 - ((opt_len + ext_bit) % 8)
|
||||
pad_bits = 0 if (pad_bits == 8) else pad_bits
|
||||
Bv = Bv << pad_bits
|
||||
GEN.append( Uint('Root-Bmp', val=Bv, bl=opt_len + pad_bits) )
|
||||
|
||||
GEN = [Envelope('Preamble', GEN=tuple(GEN))]
|
||||
|
||||
# encode components in the root part
|
||||
if self.TYPE == TYPE_SET:
|
||||
root_canon = self._root_canon
|
||||
else:
|
||||
root_canon = self._root
|
||||
for ident in root_canon:
|
||||
if ident in self._val:
|
||||
# component present in the encoding
|
||||
Comp = self._cont[ident]
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
Comp._val = self._val[ident]
|
||||
GEN.append( Comp._to_oer_ws() )
|
||||
Comp._parent = _par
|
||||
|
||||
# encode components in the extension part
|
||||
if extended:
|
||||
# generate the structure for all known present extension
|
||||
_gen_ext, Bm, cnt = [], [], 1
|
||||
for ident in self._ext_nest:
|
||||
if isinstance(ident, list):
|
||||
# group of extension
|
||||
grp_val, gid = {}, None
|
||||
for ident_inner in ident:
|
||||
if ident_inner in self._val:
|
||||
grp_val[ident_inner] = self._val[ident_inner]
|
||||
if gid is None:
|
||||
gid = self._ext_ident[ident_inner]
|
||||
if grp_val:
|
||||
# group present in the encoding
|
||||
Comp = self._ext_group_obj[gid]
|
||||
Comp._val = grp_val
|
||||
_gen_ext.append( ASN1CodecOER.encode_open_type_ws(
|
||||
Comp.to_oer() ))
|
||||
Bm.append(cnt)
|
||||
else:
|
||||
if ident in self._val:
|
||||
# single extension
|
||||
Comp = self._cont[ident]
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
Comp._val = self._val[ident]
|
||||
_gen_ext.append( ASN1CodecOER.encode_open_type_ws(
|
||||
Comp.to_oer()))
|
||||
Comp._parent = _par
|
||||
Bm.append(cnt)
|
||||
cnt += 1
|
||||
|
||||
# generate the structure for all unknown present extension
|
||||
unk_idents = [i for i in self._val if i[:5] == '_ext_']
|
||||
if unk_idents:
|
||||
# sort by index set to the ident
|
||||
unk_idents.sort(key=lambda x:int(x[5:]))
|
||||
for ident in unk_idents:
|
||||
ind = int(ident[5:])
|
||||
if ind >= cnt and ind not in Bm:
|
||||
_gen_ext.append( ASN1CodecOER.encode_open_type_ws(
|
||||
self._val[ident]) )
|
||||
Bm.append(ind)
|
||||
elif not self._SILENT:
|
||||
asnlog('_CONSTRUCT._to_oer: %s.%s, '
|
||||
'invalid unknown extension index' \
|
||||
% (self.fullname(), ident))
|
||||
|
||||
if not Bm:
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
return self._struct
|
||||
|
||||
# generate the bitmap preambule for extended (group of) components
|
||||
# bitmap length is encoded with a normally small value
|
||||
ldet = max(max(Bm), len(self._ext_nest))
|
||||
ext_bitmap = 0
|
||||
for i in Bm:
|
||||
ext_bitmap = ext_bitmap | (1<<(ldet-i))
|
||||
pad_bits = uint_bytelen(ext_bitmap)*8 - ldet
|
||||
ext_bitmap = ext_bitmap << pad_bits
|
||||
ext_bmp_len = pad_bits + ldet
|
||||
ext_bmp_struct = []
|
||||
ext_bmp_struct.append(ASN1CodecOER.encode_length_determinant_ws(1 +
|
||||
ext_bmp_len//8))
|
||||
ext_bmp_struct.append( Uint('Initial-octet', val=pad_bits, bl=8) )
|
||||
ext_bmp_struct.append( Uint('Bitmap', val=ext_bitmap,
|
||||
bl=ext_bmp_len) )
|
||||
ext_bmp_struct = Envelope('Extension-bmp',
|
||||
GEN=tuple(ext_bmp_struct))
|
||||
GEN.append(ext_bmp_struct)
|
||||
GEN.extend(_gen_ext)
|
||||
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
return self._struct
|
||||
|
||||
def _from_oer(self, char):
|
||||
GEN, self._val = [], {}
|
||||
if not self._cont and self._ext is None:
|
||||
# empty sequence
|
||||
return
|
||||
|
||||
extended = False
|
||||
ext_bit = 0
|
||||
if self._ext is not None:
|
||||
extended = (1 == char.get_uint(1))
|
||||
ext_bit = 1
|
||||
|
||||
# get the bitmap preambule for optional / default components of the root part
|
||||
if self._root_opt:
|
||||
opt_len = len(self._root_opt)
|
||||
Bv = char.get_uint(opt_len)
|
||||
opt_idents = [self._root_opt[i] for i in range(opt_len) if Bv & (1<<(opt_len-1-i))]
|
||||
else:
|
||||
opt_len = 0
|
||||
opt_idents = []
|
||||
|
||||
# Get the padding bits
|
||||
pad_bits = 8 - ((opt_len + ext_bit) % 8)
|
||||
pad_bits = 0 if (pad_bits == 8) else pad_bits
|
||||
char.get_uint(pad_bits)
|
||||
|
||||
# decode components in the root part
|
||||
# for SET, use self._root_canon which is the canonical order of root components
|
||||
if self.TYPE == TYPE_SET:
|
||||
root_canon = self._root_canon
|
||||
else:
|
||||
root_canon = self._root
|
||||
for ident in root_canon:
|
||||
Comp = self._cont[ident]
|
||||
if ident in self._root_mand or ident in opt_idents:
|
||||
# component present in the encoding
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
Comp._from_oer(char)
|
||||
self._val[ident] = Comp._val
|
||||
Comp._parent = _par
|
||||
elif Comp._def is not None and ASN1CodecOER.GET_DEFVAL:
|
||||
# component absent of the encoding, but with default value
|
||||
self._val[ident] = Comp._def
|
||||
|
||||
# decode components in the extension part
|
||||
if extended:
|
||||
# get the bitmap preambule for extended (group of) components
|
||||
ldet = ASN1CodecOER.decode_length_determinant(char)
|
||||
pad_bits = char.get_uint(8)
|
||||
ldet = (ldet - 1) * 8
|
||||
Bv = char.get_uint(ldet)
|
||||
Bv = Bv >> pad_bits
|
||||
ldet = ldet - pad_bits
|
||||
|
||||
for i in range(ldet):
|
||||
if Bv & (1<<(ldet-1-i)):
|
||||
# extension present
|
||||
if i < len(self._ext_nest):
|
||||
# known extension
|
||||
ext = self._ext_nest[i]
|
||||
if isinstance(ext, list):
|
||||
# grouped extension
|
||||
Comp = self._ext_group_obj[self._ext_ident[ext[0]]]
|
||||
val_bytes = ASN1CodecOER.decode_open_type(char)
|
||||
if Comp:
|
||||
Comp.from_oer(val_bytes)
|
||||
self._val.update(Comp._val)
|
||||
else:
|
||||
self._val.update(val_bytes)
|
||||
else:
|
||||
# single extension, ident == ext
|
||||
Comp = self._cont[ext]
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
Comp.from_oer(ASN1CodecOER.decode_open_type(char))
|
||||
self._val[ext] = Comp._val
|
||||
Comp._parent = _par
|
||||
else:
|
||||
# unknown extension
|
||||
self._val['_ext_%r' % i] = \
|
||||
ASN1CodecOER.decode_open_type(char)
|
||||
return
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
GEN, self._val = [], {}
|
||||
if not self._cont and self._ext is None:
|
||||
# empty sequence
|
||||
return
|
||||
|
||||
extended = False
|
||||
ext_bit = 0
|
||||
if self._ext is not None:
|
||||
extension = Uint('Extension', bl=1)
|
||||
extension._from_char(char)
|
||||
GEN.append(extension)
|
||||
extended = (1 == extension.get_val())
|
||||
ext_bit = 1
|
||||
|
||||
# get the bitmap preambule for optional / default components of the root part
|
||||
opt_len = len(self._root_opt) if self._root_opt else 0
|
||||
pad_bits = 8 - ((opt_len + ext_bit) % 8)
|
||||
pad_bits = 0 if (pad_bits == 8) else pad_bits
|
||||
|
||||
root_bmp = Uint('Root-bmp', bl=opt_len+pad_bits)
|
||||
root_bmp._from_char(char)
|
||||
GEN.append(root_bmp)
|
||||
|
||||
if self._root_opt:
|
||||
Bv = root_bmp.get_val() >> pad_bits
|
||||
opt_idents = [self._root_opt[i] for i in range(opt_len) if Bv & (1<<(opt_len-1-i))]
|
||||
else:
|
||||
opt_len = 0
|
||||
opt_idents = []
|
||||
|
||||
GEN = [Envelope('Preamble', GEN=tuple(GEN))]
|
||||
|
||||
# decode components in the root part
|
||||
# for SET, use self._root_canon which is the canonical order of root components
|
||||
if self.TYPE == TYPE_SET:
|
||||
root_canon = self._root_canon
|
||||
else:
|
||||
root_canon = self._root
|
||||
for ident in root_canon:
|
||||
Comp = self._cont[ident]
|
||||
if ident in self._root_mand or ident in opt_idents:
|
||||
# component present in the encoding
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
Comp._from_oer_ws(char)
|
||||
self._val[ident] = Comp._val
|
||||
GEN.append(Comp._struct)
|
||||
Comp._parent = _par
|
||||
elif Comp._def is not None and ASN1CodecOER.GET_DEFVAL:
|
||||
# component absent of the encoding, but with default value
|
||||
self._val[ident] = Comp._def
|
||||
|
||||
# decode components in the extension part
|
||||
if extended:
|
||||
# get the bitmap preambule for extended (group of) components
|
||||
ldet, ldet_struct = ASN1CodecOER.decode_length_determinant_ws(char)
|
||||
i_oct = Uint('Initial-octet', bl=8)
|
||||
i_oct._from_char(char)
|
||||
pad_bits = i_oct.get_val()
|
||||
ldet = (ldet - 1) * 8
|
||||
ext_bmp = Uint('Bitmap', bl=ldet)
|
||||
ext_bmp._from_char(char)
|
||||
Bv = ext_bmp.get_val()
|
||||
Bv = Bv >> pad_bits
|
||||
ldet = ldet - pad_bits
|
||||
|
||||
GEN.append(Envelope('Extension-bmp',
|
||||
GEN=(ldet_struct, i_oct, ext_bmp)))
|
||||
|
||||
for i in range(ldet):
|
||||
if Bv & (1<<(ldet-1-i)):
|
||||
# extension present
|
||||
if i < len(self._ext_nest):
|
||||
# known extension
|
||||
ext = self._ext_nest[i]
|
||||
if isinstance(ext, list):
|
||||
# grouped extension
|
||||
Comp = self._ext_group_obj[self._ext_ident[ext[0]]]
|
||||
val_bytes, _struct = \
|
||||
ASN1CodecOER.decode_open_type_ws(char)
|
||||
if Comp:
|
||||
Comp.from_oer(val_bytes)
|
||||
self._val.update(Comp._val)
|
||||
else:
|
||||
self._val.update(val_bytes)
|
||||
GEN.append(_struct)
|
||||
else:
|
||||
# single extension, ident == ext
|
||||
Comp = self._cont[ext]
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
val_bytes, _struct = \
|
||||
ASN1CodecOER.decode_open_type_ws(char)
|
||||
Comp.from_oer(val_bytes)
|
||||
self._val[ext] = Comp._val
|
||||
Comp._parent = _par
|
||||
GEN.append(_struct)
|
||||
else:
|
||||
# unknown extension
|
||||
val_bytes, _struct = \
|
||||
ASN1CodecOER.decode_open_type_ws(char)
|
||||
self._val['_ext_%r' % i] = val_bytes
|
||||
GEN.append(_struct)
|
||||
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
return
|
||||
|
||||
|
||||
class SEQ(_CONSTRUCT):
|
||||
__doc__ = """
|
||||
|
@ -2578,6 +3183,94 @@ class _CONSTRUCT_OF(ASN1Obj):
|
|||
self._cont._parent = _par
|
||||
return ret
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _to_oer(self):
|
||||
GEN, ldet = [], len(self._val)
|
||||
l_size = uint_bytelen(ldet)
|
||||
GEN.extend(ASN1CodecOER.encode_length_determinant(l_size))
|
||||
GEN.append( (T_UINT, ldet, l_size*8) )
|
||||
|
||||
# Iterate over items
|
||||
Comp = self._cont
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
|
||||
for val in self._val:
|
||||
Comp._val = val
|
||||
GEN.extend(Comp._to_oer())
|
||||
|
||||
Comp._parent = _par
|
||||
|
||||
return GEN
|
||||
|
||||
def _to_oer_ws(self):
|
||||
GEN, ldet = [], len(self._val)
|
||||
l_size = uint_bytelen(ldet)
|
||||
GEN.append(ASN1CodecOER.encode_length_determinant_ws(l_size))
|
||||
GEN.append(Uint('Quantity', val=ldet, bl=l_size * 8))
|
||||
|
||||
GEN = [Envelope('Quantity-field', GEN=tuple(GEN))]
|
||||
|
||||
# Iterate over items
|
||||
Comp = self._cont
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
|
||||
for val in self._val:
|
||||
Comp._val = val
|
||||
GEN.append(Comp._to_oer_ws())
|
||||
|
||||
Comp._parent = _par
|
||||
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
return self._struct
|
||||
|
||||
def _from_oer(self, char):
|
||||
l_size = ASN1CodecOER.decode_length_determinant(char)
|
||||
ldet = char.get_uint(l_size*8)
|
||||
|
||||
Comp = self._cont
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
val = []
|
||||
if ldet:
|
||||
for i in range(ldet):
|
||||
Comp._from_oer(char)
|
||||
val.append(Comp._val)
|
||||
|
||||
Comp._parent = _par
|
||||
|
||||
self._val = val
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
GEN = []
|
||||
l_size, l_size_struct = ASN1CodecOER.decode_length_determinant_ws(char)
|
||||
GEN.append(l_size_struct)
|
||||
ldet_struct = Uint('Quantity', bl=l_size*8)
|
||||
ldet_struct._from_char(char)
|
||||
ldet = ldet_struct.get_val()
|
||||
GEN.append(ldet_struct)
|
||||
|
||||
GEN = [Envelope('Quantity-field', GEN=tuple(GEN))]
|
||||
|
||||
Comp = self._cont
|
||||
_par = Comp._parent
|
||||
Comp._parent = self
|
||||
val = []
|
||||
if ldet:
|
||||
for i in range(ldet):
|
||||
Comp._from_oer_ws(char)
|
||||
GEN.append(Comp._struct)
|
||||
val.append(Comp._val)
|
||||
|
||||
Comp._parent = _par
|
||||
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
self._val = val
|
||||
|
||||
|
||||
class SEQ_OF(_CONSTRUCT_OF):
|
||||
__doc__ = """
|
||||
|
|
|
@ -643,6 +643,107 @@ Single value: Python 2-tuple
|
|||
Obj._val = self._val[1]
|
||||
return Obj._to_jval()
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _from_oer(self, char):
|
||||
# try to get a defined object from a table constraint
|
||||
if self._TAB_LUT and self._const_tab and self._const_tab_at:
|
||||
const_obj_type, const_obj = self._get_tab_obj()
|
||||
if const_obj_type == CLASET_NONE:
|
||||
if not self._SILENT:
|
||||
asnlog('OPEN._from_oer: %s, unable to retrieve a table-looked up object' \
|
||||
% (self.fullname()))
|
||||
Obj = None
|
||||
elif const_obj_type == CLASET_UNIQ:
|
||||
Obj = const_obj
|
||||
else:
|
||||
# const_obj_type == CLASET_MULT
|
||||
# with PER, no tag to select a given object
|
||||
Obj = const_obj[0]
|
||||
else:
|
||||
# TODO: another way to provide a (set of) potential defined object(s)
|
||||
# is to look into value constraint self._const_val
|
||||
# if we have multiple, then we would have to bruteforce the decoding
|
||||
# until a correct one is found !!!
|
||||
Obj = None
|
||||
#
|
||||
val_bytes = ASN1CodecOER.decode_open_type(char)
|
||||
val = Obj.from_oer(val_bytes) if (Obj is not None) else val_bytes
|
||||
|
||||
if Obj is None:
|
||||
if self._const_val:
|
||||
asnlog('OPEN._from_per: %s, potential type constraint(s) available but unused' \
|
||||
% self.fullname())
|
||||
assert( isinstance(val, bytes_types) )
|
||||
self._val = ('_unk_004', val)
|
||||
else:
|
||||
if Obj._typeref is not None:
|
||||
self._val = (Obj._typeref.called[1], val)
|
||||
else:
|
||||
self._val = (Obj.TYPE, val)
|
||||
return
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
# try to get a defined object from a table constraint
|
||||
if self._TAB_LUT and self._const_tab and self._const_tab_at:
|
||||
const_obj_type, const_obj = self._get_tab_obj()
|
||||
if const_obj_type == CLASET_NONE:
|
||||
if not self._SILENT:
|
||||
asnlog('OPEN._from_per_ws: %s, unable to retrieve a table-looked up object' \
|
||||
% (self.fullname()))
|
||||
Obj = None
|
||||
elif const_obj_type == CLASET_UNIQ:
|
||||
Obj = const_obj
|
||||
else:
|
||||
# const_obj_type == CLASET_MULT
|
||||
# with PER, no tag to select a given object
|
||||
Obj = const_obj[0]
|
||||
else:
|
||||
# TODO: another way to provide a (set of) potential defined object(s)
|
||||
# is to look into value constraint self._const_val
|
||||
# if we have multiple, then we would have to bruteforce the decoding
|
||||
# until a correct one is found !!!
|
||||
Obj = None
|
||||
#
|
||||
val_bytes, GEN = ASN1CodecOER.decode_open_type_ws(char)
|
||||
if Obj is None:
|
||||
if self._const_val:
|
||||
asnlog('OPEN._from_per_ws: %s, potential type constraint(s) available but unused' \
|
||||
% self.fullname())
|
||||
self._val = ('_unk_004', val_bytes)
|
||||
else:
|
||||
val = Obj.from_oer(val_bytes)
|
||||
if Obj._typeref is not None:
|
||||
self._val = (Obj._typeref.called[1], val)
|
||||
else:
|
||||
self._val = (Obj.TYPE, val)
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
|
||||
def _to_oer(self):
|
||||
if isinstance(self._val[0], ASN1Obj):
|
||||
Obj = self._val[0]
|
||||
else:
|
||||
if self._val[0][:5] == '_unk_':
|
||||
return ASN1CodecOER.encode_open_type(self._val[1])
|
||||
Obj = self._get_val_obj(self._val[0])
|
||||
Obj._val = self._val[1]
|
||||
return ASN1CodecOER.encode_open_type(Obj.to_oer())
|
||||
|
||||
def _to_oer_ws(self):
|
||||
if isinstance(self._val[0], ASN1Obj):
|
||||
Obj = self._val[0]
|
||||
else:
|
||||
if self._val[0][:5] == '_unk_':
|
||||
_gen = ASN1CodecOER.encode_open_type_ws(self._val[1])
|
||||
return Envelope(self._name, GEN=(_gen,))
|
||||
Obj = self._get_val_obj(self._val[0])
|
||||
Obj._val = self._val[1]
|
||||
_gen = ASN1CodecOER.encode_open_type_ws(Obj.to_oer())
|
||||
self._struct = Envelope(self._name, GEN=(_gen,))
|
||||
return self._struct
|
||||
|
||||
|
||||
class ANY(OPEN):
|
||||
|
||||
|
|
|
@ -1043,6 +1043,167 @@ Specific constraints attributes:
|
|||
else:
|
||||
return {'value': uint_to_hex(val, bl), 'length': bl}
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _to_oer(self):
|
||||
if isinstance(self._val, set):
|
||||
self._names_to_val()
|
||||
|
||||
## Now check if the value is contained object or just number
|
||||
if not isinstance(self._val[0], integer_types):
|
||||
# 1) value is for a contained object to be encoded
|
||||
Cont = self._get_val_obj(self._val[0])
|
||||
if Cont == self._const_cont and self._const_cont_enc is not None:
|
||||
# TODO: different codec to be used
|
||||
raise(ASN1NotSuppErr('{0}: specific CONTAINING encoder unhandled' \
|
||||
.format(self.fullname())))
|
||||
Cont._val = self._val[1]
|
||||
buf = Cont.to_oer()
|
||||
l_val = len(buf) * 8
|
||||
pad_bits = 0
|
||||
_gen = [(T_BYTES, buf, l_val)]
|
||||
if Cont == self._const_cont:
|
||||
return _gen
|
||||
else:
|
||||
# 2) value is the standard (uint, bit length)
|
||||
if self._val[1]:
|
||||
l_val = self._val[1]
|
||||
_gen = [(T_UINT, self._val[0], l_val)]
|
||||
# padding bits
|
||||
pad_bits = (l_val % 8)
|
||||
pad_bits = (8 - pad_bits) if pad_bits else 0
|
||||
_gen.append((T_UINT, 0, pad_bits))
|
||||
else:
|
||||
# empty bit string
|
||||
pad_bits = 0
|
||||
l_val = 0
|
||||
_gen = [(T_BYTES, b'', l_val)]
|
||||
|
||||
if self._const_sz:
|
||||
if (self._const_sz._ev is None) and (self._const_sz.ra == 1):
|
||||
# Fixed size constrains
|
||||
return _gen
|
||||
|
||||
# Variable size constrains
|
||||
GEN = ASN1CodecOER.encode_length_determinant(((l_val + pad_bits) // 8)
|
||||
+ 1)
|
||||
GEN.append((T_UINT, pad_bits, 8)) # Initial octet
|
||||
GEN.extend(_gen)
|
||||
return GEN
|
||||
|
||||
def _to_oer_ws(self):
|
||||
if isinstance(self._val, set):
|
||||
self._names_to_val()
|
||||
|
||||
## Now check if the value is contained object or just number
|
||||
if not isinstance(self._val[0], integer_types):
|
||||
# 1) value is for a contained object to be encoded
|
||||
Cont = self._get_val_obj(self._val[0])
|
||||
if Cont == self._const_cont and self._const_cont_enc is not None:
|
||||
# TODO: different codec to be used
|
||||
raise (
|
||||
ASN1NotSuppErr('{0}: specific CONTAINING encoder unhandled' \
|
||||
.format(self.fullname())))
|
||||
Cont._val = self._val[1]
|
||||
buf = Cont.to_oer()
|
||||
l_val = len(buf) * 8
|
||||
pad_bits = 0
|
||||
_gen = [Buf('V', val=buf, bl=l_val)]
|
||||
if Cont == self._const_cont:
|
||||
self._struct = Envelope(self._name, GEN=tuple(_gen))
|
||||
return self._struct
|
||||
else:
|
||||
# 2) value is the standard (uint, bit length)
|
||||
if self._val[1]:
|
||||
l_val = self._val[1]
|
||||
_gen = [Uint('V', val=self._val[0], bl=l_val)]
|
||||
# padding bits
|
||||
pad_bits = (l_val % 8)
|
||||
pad_bits = (8 - pad_bits) if pad_bits else 0
|
||||
_gen.append(Uint('Zero-pad', val=0, bl=pad_bits))
|
||||
else:
|
||||
# empty bit string
|
||||
pad_bits = 0
|
||||
l_val = 0
|
||||
_gen = [Buf('V', b'', l_val)]
|
||||
|
||||
if self._const_sz:
|
||||
if (self._const_sz._ev is None) and (self._const_sz.ra == 1):
|
||||
# Fixed size constrains
|
||||
self._struct = Envelope(self._name, GEN=tuple(_gen))
|
||||
return self._struct
|
||||
|
||||
# Variable size constrains
|
||||
GEN = [ASN1CodecOER.encode_length_determinant_ws(
|
||||
((l_val + pad_bits) // 8) + 1)]
|
||||
GEN.append(Uint('Initial octet', val=pad_bits, bl=8))
|
||||
GEN.extend(_gen)
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
return self._struct
|
||||
|
||||
def _from_oer(self, char):
|
||||
if self._const_sz:
|
||||
if (self._const_sz._ev is None) and (self._const_sz.ra == 1):
|
||||
# Fixed
|
||||
l_val = self._const_sz.lb
|
||||
pad_bits = (l_val % 8)
|
||||
pad_bits = (8 - pad_bits) if pad_bits else 0
|
||||
buf = char.get_uint(l_val+pad_bits)
|
||||
self._val = (buf >> pad_bits, l_val)
|
||||
return
|
||||
elif self._const_cont:
|
||||
# Contained by constraint
|
||||
Cont = self._get_val_obj(self._const_cont._typeref.called)
|
||||
Cont.from_oer(char)
|
||||
self._val = (self._const_cont._typeref.called, Cont._val)
|
||||
return
|
||||
|
||||
# Variable size constraints
|
||||
l_det = ASN1CodecOER.decode_length_determinant(char)
|
||||
pad_bits = char.get_uint(8)
|
||||
l_val = 8*(l_det - 1) - pad_bits
|
||||
self._val = (char.get_uint(l_val+pad_bits) >> pad_bits, l_val)
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
if self._const_sz:
|
||||
if (self._const_sz._ev is None) and (self._const_sz.ra == 1):
|
||||
# Fixed
|
||||
l_val = self._const_sz.lb
|
||||
pad_bits = (l_val % 8)
|
||||
pad_bits = (8 - pad_bits) if pad_bits else 0
|
||||
val = Uint('V', bl=l_val)
|
||||
val._from_char(char)
|
||||
zero_pad = Uint('Zero-pad', bl=pad_bits)
|
||||
zero_pad._from_char(char)
|
||||
self._val = (val.get_val(), val.get_bl())
|
||||
self._struct = Envelope(self._name, GEN=(val, zero_pad))
|
||||
return
|
||||
elif self._const_cont:
|
||||
# Contained by constraint
|
||||
Cont = self._get_val_obj(self._const_cont._typeref.called)
|
||||
Cont.from_oer_ws(char)
|
||||
_gen = Cont._struct
|
||||
self._val = (self._const_cont._typeref.called, Cont._val)
|
||||
self._struct = Envelope(self._name, GEN=(_gen,))
|
||||
return
|
||||
|
||||
# Variable size constraints
|
||||
l_det, _gen = ASN1CodecOER.decode_length_determinant_ws(char)
|
||||
_gen = [_gen]
|
||||
i_oct = Uint('Initial octet', bl=8)
|
||||
i_oct._from_char(char)
|
||||
pad_bits = i_oct.get_val()
|
||||
l_val = 8*(l_det - 1) - pad_bits
|
||||
val = Uint('V', bl=l_val)
|
||||
val._from_char(char)
|
||||
zero_pad = Uint('Zero-pad', bl=pad_bits)
|
||||
zero_pad._from_char(char)
|
||||
_gen.extend((i_oct, val, zero_pad))
|
||||
self._val = (val.get_val(), val.get_bl())
|
||||
self._struct = Envelope(self._name, GEN=tuple(_gen))
|
||||
|
||||
|
||||
class OCT_STR(ASN1Obj):
|
||||
__doc__ = """
|
||||
|
@ -1668,6 +1829,117 @@ Specific constraints attributes:
|
|||
else:
|
||||
return {Cont.TYPE: val}
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _from_oer(self, char):
|
||||
if self._const_sz:
|
||||
if (self._const_sz._ev is None) and (self._const_sz.ra == 1):
|
||||
# Fixed
|
||||
self._val = char.get_bytes(self._const_sz.lb * 8)
|
||||
return
|
||||
elif self._const_cont:
|
||||
# Contained by constraint
|
||||
Cont = self._get_val_obj(self._const_cont._typeref.called)
|
||||
Cont.from_oer(char)
|
||||
self._val = (self._const_cont._typeref.called, Cont._val)
|
||||
return
|
||||
|
||||
# Variable size constraint
|
||||
l_val = ASN1CodecOER.decode_length_determinant(char)
|
||||
self._val = char.get_bytes(l_val * 8)
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
if self._const_sz:
|
||||
if (self._const_sz._ev is None) and (self._const_sz.ra == 1):
|
||||
# Fixed
|
||||
val = Buf('V', bl=self._const_sz.lb * 8)
|
||||
val._from_char(char)
|
||||
self._val = val.get_val()
|
||||
self._struct = Envelope(self._name, GEN=(val,))
|
||||
return
|
||||
elif self._const_cont:
|
||||
# Contained by constraint
|
||||
Cont = self._get_val_obj(self._const_cont._typeref.called)
|
||||
Cont.from_oer_ws(char)
|
||||
_gen = Cont._struct
|
||||
self._val = (self._const_cont._typeref.called, Cont._val)
|
||||
self._struct = Envelope(self._name, GEN=(_gen,))
|
||||
return
|
||||
|
||||
# Variable size constraints
|
||||
l_val, _gen = ASN1CodecOER.decode_length_determinant_ws(char)
|
||||
val = Buf('V', bl=8 * l_val)
|
||||
val._from_char(char)
|
||||
_gen.append(val)
|
||||
self._val = val.get_val()
|
||||
self._struct = Envelope(self._name, GEN=(_gen,))
|
||||
|
||||
def __to_coer_buf(self):
|
||||
Cont = self._get_val_obj(self._val[0])
|
||||
if Cont == self._const_cont and self._const_cont_enc is not None:
|
||||
# TODO: different codec to be used
|
||||
raise (
|
||||
ASN1NotSuppErr('{0}: specific CONTAINING encoder unhandled' \
|
||||
.format(self.fullname())))
|
||||
Cont._val = self._val[1]
|
||||
buf = Cont.to_coer()
|
||||
return buf, Cont
|
||||
|
||||
def __to_coer_ws_buf(self):
|
||||
Cont = self._get_val_obj(self._val[0])
|
||||
if Cont == self._const_cont and self._const_cont_enc is not None:
|
||||
# TODO: different codec to be used
|
||||
raise (
|
||||
ASN1NotSuppErr('{0}: specific CONTAINING encoder unhandled' \
|
||||
.format(self.fullname())))
|
||||
Cont._val = self._val[1]
|
||||
buf = Cont.to_coer_ws()
|
||||
return buf, Cont
|
||||
|
||||
def _to_oer(self):
|
||||
if not isinstance(self._val, bytes_types):
|
||||
buf, wrapped = self.__to_coer_buf()
|
||||
else:
|
||||
buf, wrapped = self._val, None
|
||||
|
||||
try:
|
||||
if (((self._const_sz._ev is None) and
|
||||
(self._const_sz.lb == self._const_sz.ub)) or
|
||||
(self._const_cont is not None)):
|
||||
return [(T_BYTES, buf, len(buf)*8)]
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# Means that it has variable constraint or no constraint
|
||||
GEN = ASN1CodecOER.encode_length_determinant(len(buf))
|
||||
GEN.append((T_BYTES, buf, len(buf) * 8))
|
||||
return GEN
|
||||
|
||||
def _to_oer_ws(self):
|
||||
if not isinstance(self._val, bytes_types):
|
||||
buf, wrapped = self.__to_coer_ws_buf()
|
||||
else:
|
||||
buf, wrapped = self._val, None
|
||||
|
||||
_gen = Buf('V', val=buf, bl=len(buf)*8)
|
||||
|
||||
try:
|
||||
if (((self._const_sz._ev is None) and
|
||||
(self._const_sz.lb == self._const_sz.ub)) or
|
||||
(self._const_cont)):
|
||||
self._struct = Envelope(self._name,
|
||||
GEN=(_gen,))
|
||||
return self._struct
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# Means that it has variable constraint or no constraint
|
||||
GEN = ASN1CodecOER.encode_length_determinant_ws(len(buf))
|
||||
GEN.append(_gen)
|
||||
self._struct = Envelope(self._name, GEN=(GEN,))
|
||||
return self._struct
|
||||
|
||||
#------------------------------------------------------------------------------#
|
||||
# All *String
|
||||
|
@ -2494,6 +2766,110 @@ Virtual parent for any ASN.1 *String object
|
|||
def _to_jval(self):
|
||||
return self._val
|
||||
|
||||
###
|
||||
# conversion between internal value and ASN.1 OER/COER encoding
|
||||
###
|
||||
|
||||
def _from_oer(self, char):
|
||||
try:
|
||||
if ((self._const_sz.rdyn == 0) and
|
||||
(self._const_sz._ev is None) and
|
||||
(self._clen is not None)):
|
||||
# Fixed size
|
||||
b_len = round_p2(self._clen) * self._const_sz.lb
|
||||
self._val = self._decode_oer_cont(char.get_bytes(b_len))
|
||||
return
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# All other variants
|
||||
l_det = ASN1CodecOER.decode_length_determinant(char)
|
||||
self._val = self._decode_oer_cont(char.get_bytes(l_det * 8))
|
||||
|
||||
def _from_oer_ws(self, char):
|
||||
try:
|
||||
if ((self._const_sz.rdyn == 0) and
|
||||
(self._const_sz._ev is None) and
|
||||
(self._clen is not None)):
|
||||
# Fixed size
|
||||
b_len = round_p2(self._clen) * self._const_sz.lb
|
||||
buf = Buf('V', bl=b_len)
|
||||
buf._from_char(char)
|
||||
self._struct = Envelope(self._name, GEN=(buf,))
|
||||
self._val = self._decode_oer_cont(buf.to_bytes())
|
||||
return
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# All other variants
|
||||
l_det, _gen = ASN1CodecOER.decode_length_determinant_ws(char)
|
||||
_gen = [_gen]
|
||||
buf = Buf('V', bl=l_det*8)
|
||||
buf._from_char(char)
|
||||
_gen.append(buf)
|
||||
self._struct = Envelope(self._name, GEN=tuple(_gen))
|
||||
self._val = self._decode_oer_cont(buf.to_bytes())
|
||||
|
||||
def _decode_oer_cont(self, content_bytes):
|
||||
if self._codec is None:
|
||||
raise(ASN1NotSuppErr('{0}: ISO 2022 codec not supported' \
|
||||
.format(self.fullname())))
|
||||
try:
|
||||
return content_bytes.decode(self._codec)
|
||||
except Exception as err:
|
||||
raise(ASN1OERDecodeErr('{0}: invalid character, Python codec error, {1}' \
|
||||
.format(self.fullname(), err)))
|
||||
|
||||
def _encode_oer_cont(self):
|
||||
if self._codec is None:
|
||||
raise(ASN1NotSuppErr('{0}: ISO 2022 codec not supported' \
|
||||
.format(self.fullname())))
|
||||
try:
|
||||
return self._val.encode(self._codec)
|
||||
except Exception as err:
|
||||
raise(ASN1OEREncodeErr('{0}: invalid character, Python codec error, {1}' \
|
||||
.format(self.fullname(), err)))
|
||||
|
||||
def _to_oer(self):
|
||||
buf = self._encode_oer_cont()
|
||||
l_buf = len(buf)
|
||||
buf = [(T_BYTES, buf, l_buf * 8)]
|
||||
|
||||
try:
|
||||
if ((self._const_sz.rdyn == 0) and
|
||||
(self._const_sz._ev is None) and
|
||||
(self._clen is not None)):
|
||||
# Fixed size
|
||||
return buf
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# All other variants
|
||||
GEN = ASN1CodecOER.encode_length_determinant(l_buf)
|
||||
GEN.extend(buf)
|
||||
return GEN
|
||||
|
||||
def _to_oer_ws(self):
|
||||
buf = self._encode_oer_cont()
|
||||
l_buf = len(buf)
|
||||
buf = Buf('V', val=buf, bl=l_buf * 8)
|
||||
|
||||
try:
|
||||
if ((self._const_sz.rdyn == 0) and
|
||||
(self._const_sz._ev is None) and
|
||||
(self._clen is not None)):
|
||||
# Fixed size
|
||||
self._struct = Envelope(self._name, GEN=(buf,))
|
||||
return self._struct
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# All other variants
|
||||
GEN = [ASN1CodecOER.encode_length_determinant_ws(l_buf)]
|
||||
GEN.append(buf)
|
||||
self._struct = Envelope(self._name, GEN=tuple(GEN))
|
||||
return self._struct
|
||||
|
||||
|
||||
# Python does not provide a complete support for ISO2022 encoding
|
||||
# so here, we use iso2022_jp_2004
|
||||
|
|
|
@ -1660,3 +1660,447 @@ class ASN1CodecGSER(ASN1Codec):
|
|||
# TODO: implement this
|
||||
pass
|
||||
|
||||
|
||||
class ASN1CodecOER(ASN1Codec):
|
||||
|
||||
# canonicity is used to decide whether to encode default values or not in
|
||||
# constructed object
|
||||
CANONICAL = True
|
||||
|
||||
TRUE = 0xFF
|
||||
FALSE = 0x00
|
||||
|
||||
LenFormLUT = {0: 'short', 1: 'long'}
|
||||
REAL_IEEE754_32_MANTIS_MIN = -2 ** 24 + 1
|
||||
REAL_IEEE754_32_MANTIS_MAX = 2 ** 24 - 1
|
||||
REAL_IEEE754_64_MANTIS_MIN = -2 ** 53 - 1
|
||||
REAL_IEEE754_64_MANTIS_MAX = 2 ** 53 - 1
|
||||
REAL_IEEE754_32_EXP_MIN = -126
|
||||
REAL_IEEE754_32_EXP_MAX = 127
|
||||
REAL_IEEE754_64_EXP_MIN = -1022
|
||||
REAL_IEEE754_64_EXP_MAX = 1023
|
||||
|
||||
# tag classes
|
||||
TagClassLUT = {0b00: TAG_UNIVERSAL,
|
||||
0b01: TAG_APPLICATION,
|
||||
0b10: TAG_CONTEXT_SPEC,
|
||||
0b11: TAG_PRIVATE,
|
||||
TAG_UNIVERSAL: 0b00,
|
||||
TAG_APPLICATION: 0b01,
|
||||
TAG_CONTEXT_SPEC: 0b10,
|
||||
TAG_PRIVATE: 0b11}
|
||||
|
||||
GET_DEFVAL = True
|
||||
|
||||
@classmethod
|
||||
def encode_tag(cls, tag, tag_class=TAG_CONTEXT_SPEC):
|
||||
try:
|
||||
tag_enc = [(T_UINT, cls.TagClassLUT[tag_class], 2)]
|
||||
except KeyError:
|
||||
ASN1OEREncodeErr("Unknown tag class: {0}".format(tag_class))
|
||||
|
||||
if tag < 63:
|
||||
# Tag encoded in 6b:
|
||||
tag_enc.append((T_UINT, tag, 6))
|
||||
else:
|
||||
# Multi-octet tag encoding
|
||||
tag_enc.append((T_UINT, 0b111111, 6)) # Initial octet
|
||||
tag_temp = []
|
||||
# Last byte (going in reverse)
|
||||
tag_temp.append((T_UINT, tag & 0b1111111, 7))
|
||||
tag_temp.append((T_UINT, 0, 1))
|
||||
tag = tag >> 7
|
||||
|
||||
# All the other bytes
|
||||
while tag.bit_length() > 0:
|
||||
tag_temp.append((T_UINT, tag & 0b1111111, 7))
|
||||
tag_temp.append((T_UINT, 1, 1))
|
||||
tag = tag >> 7
|
||||
|
||||
tag_enc.extend(tag_temp[::-1])
|
||||
|
||||
return tag_enc
|
||||
|
||||
@classmethod
|
||||
def encode_tag_ws(cls, tag, tag_class=TAG_CONTEXT_SPEC):
|
||||
try:
|
||||
tag_enc = [Uint('Class', val=cls.TagClassLUT[tag_class], bl=2)]
|
||||
except KeyError:
|
||||
ASN1OEREncodeErr("Unknown tag class: {0}".format(tag_class))
|
||||
|
||||
if tag < 63:
|
||||
# Tag encoded in 6b:
|
||||
tag_enc.append(Uint('Val', val=tag, bl=6))
|
||||
else:
|
||||
# Multi-octet tag encoding
|
||||
tag_enc.append(Uint('Multi-octet', val=0b111111, bl=6)) # Initial octet
|
||||
tag_temp = []
|
||||
# Last byte (going in reverse)
|
||||
tag_temp.append(Uint('Val', val=tag & 0b1111111, bl=7))
|
||||
tag_temp.append(Uint('Cont',val=0, bl=1))
|
||||
tag = tag >> 7
|
||||
|
||||
# All the other bytes
|
||||
while tag.bit_length() > 0:
|
||||
tag_temp.append(Uint('Val', val=tag & 0b1111111, bl=7))
|
||||
tag_temp.append(Uint('Cont', val=1, bl=1))
|
||||
tag = tag >> 7
|
||||
|
||||
tag_enc.extend(tag_temp[::-1])
|
||||
|
||||
return Envelope('T', GEN=tuple(tag_enc))
|
||||
|
||||
@classmethod
|
||||
def decode_tag(cls, char):
|
||||
tag_class = char.get_uint(2)
|
||||
try:
|
||||
tag_class = cls.TagClassLUT[tag_class]
|
||||
except KeyError:
|
||||
ASN1OEREncodeErr("Unknown tag class: {0}".format(tag_class))
|
||||
|
||||
first_octet = char.get_uint(6)
|
||||
if first_octet < 63:
|
||||
# Tag encoded in 6b:
|
||||
tag_val = first_octet
|
||||
else:
|
||||
# Multi-octet tag encoding
|
||||
tag_val = []
|
||||
while True:
|
||||
val_cont = char.get_uint(1)
|
||||
tag_val.extend(char.get_bitlist(7))
|
||||
if not val_cont:
|
||||
break
|
||||
|
||||
tag_val = bitlist_to_uint(tag_val)
|
||||
|
||||
return tag_class, tag_val
|
||||
|
||||
@classmethod
|
||||
def decode_tag_ws(cls, char):
|
||||
tag_class = Uint('Class', bl=2)
|
||||
tag_class._from_char(char)
|
||||
try:
|
||||
tag_class_val = cls.TagClassLUT[tag_class.get_val()]
|
||||
except KeyError:
|
||||
ASN1OEREncodeErr("Unknown tag class: {0}".format(tag_class.get_val()))
|
||||
|
||||
tag_struct = [tag_class]
|
||||
|
||||
first_val = Uint('Val', bl=6)
|
||||
first_val._from_char(char)
|
||||
tag_struct.append(first_val)
|
||||
|
||||
if first_val.get_val() < 63:
|
||||
# Tag encoded in 6b:
|
||||
tag_val = first_val.get_val()
|
||||
else:
|
||||
first_val._name = 'Multi-octet'
|
||||
tag_val = 0
|
||||
while True:
|
||||
tmp_cont = Uint('Cont', bl=1)
|
||||
tmp_cont._from_char(char)
|
||||
tmp_val = Uint('Val', bl=7)
|
||||
tmp_val._from_char(char)
|
||||
|
||||
tag_val = tag_val << 7
|
||||
tag_val = tag_val | tmp_val.get_val()
|
||||
tag_struct.append(tmp_cont)
|
||||
tag_struct.append(tmp_val)
|
||||
|
||||
if not tmp_cont.get_val():
|
||||
break
|
||||
|
||||
return tag_class_val, tag_val, Envelope('T', GEN=tuple(tag_struct))
|
||||
|
||||
@classmethod
|
||||
def encode_length_determinant(cls, length):
|
||||
# Always canonical (implementing non-canonical doesn't make sense)
|
||||
determinant = []
|
||||
if length > 127:
|
||||
# long determinant
|
||||
dl = uint_bytelen(length)
|
||||
determinant.extend([(T_UINT, 1, 1),
|
||||
(T_UINT, dl, 7),
|
||||
(T_UINT, length, dl*8)
|
||||
])
|
||||
else:
|
||||
# short determinant
|
||||
determinant.append((T_UINT, length, 8))
|
||||
|
||||
return determinant
|
||||
|
||||
@classmethod
|
||||
def encode_length_determinant_ws(cls, length):
|
||||
# Always canonical (implementing non-canonical doesn't make sense)
|
||||
if length > 127:
|
||||
# long determinant
|
||||
dl = uint_bytelen(length)
|
||||
determinant = (
|
||||
Uint('Form', val=1, bl=1, dic=cls.LenFormLUT),
|
||||
Uint('Len', val=dl, bl=7),
|
||||
Uint('Val', val=length, bl=dl*8)
|
||||
)
|
||||
else:
|
||||
# short determinant
|
||||
determinant = (
|
||||
Uint('Form', val=0, bl=1, dic=cls.LenFormLUT),
|
||||
Uint('Val', val=length, bl=7)
|
||||
)
|
||||
|
||||
return Envelope('L', GEN=determinant)
|
||||
|
||||
@classmethod
|
||||
def decode_length_determinant(cls, char):
|
||||
long_form = char.get_uint(1)
|
||||
length = char.get_uint(7)
|
||||
if long_form:
|
||||
length = char.get_uint(length*8)
|
||||
return length
|
||||
|
||||
@classmethod
|
||||
def decode_length_determinant_ws(cls, char):
|
||||
length = Envelope('L', GEN=(
|
||||
Uint('Form', bl=1, dic=cls.LenFormLUT),
|
||||
Uint('Val', bl=7)
|
||||
))
|
||||
length._from_char(char)
|
||||
long_form = length[0].get_val()
|
||||
ll = length[1].get_val()
|
||||
if long_form:
|
||||
length[1]._name = "Len"
|
||||
val = Uint('Val', bl=8*ll)
|
||||
val._from_char(char)
|
||||
ll = val.get_val()
|
||||
length.append(val)
|
||||
return ll, length
|
||||
|
||||
@classmethod
|
||||
def encode_intunconst(cls, val, signed=True):
|
||||
if val < 0:
|
||||
signed = True
|
||||
vl = int_bytelen(val) if signed else uint_bytelen(val)
|
||||
GEN = cls.encode_length_determinant(vl)
|
||||
vt = T_INT if signed else T_UINT
|
||||
GEN.append((vt, val, vl * 8))
|
||||
return GEN
|
||||
|
||||
@classmethod
|
||||
def encode_intunconst_ws(cls, val, signed=True):
|
||||
if val < 0:
|
||||
signed = True
|
||||
vl = int_bytelen(val) if signed else uint_bytelen(val)
|
||||
GEN = cls.encode_length_determinant_ws(vl)
|
||||
vt = Int if signed else Uint
|
||||
GEN.append(vt('V', val=val, bl=vl*8))
|
||||
return (GEN,)
|
||||
|
||||
@classmethod
|
||||
def decode_intunconst(cls, char, signed=True):
|
||||
vl = cls.decode_length_determinant(char)
|
||||
if signed:
|
||||
return char.get_int(vl*8)
|
||||
else:
|
||||
return char.get_uint(vl*8)
|
||||
|
||||
@classmethod
|
||||
def decode_intunconst_ws(cls, char, signed=True):
|
||||
vl, det_st = cls.decode_length_determinant_ws(char)
|
||||
vt = Int if signed else Uint
|
||||
val = vt('V', bl=vl * 8)
|
||||
val._from_char(char)
|
||||
return val.get_val(), (det_st, val)
|
||||
|
||||
@classmethod
|
||||
def encode_intconst(cls, val, const_val):
|
||||
if const_val.lb is not None:
|
||||
if const_val.lb >= 0:
|
||||
# 10.3 a ~ d Check on the upper bound
|
||||
if const_val.ub is not None:
|
||||
ubl = round_p2(uint_bytelen(const_val.ub))
|
||||
if ubl <= 8:
|
||||
return [(T_UINT, val, ubl*8)]
|
||||
# No other conditions are fulfilled
|
||||
return cls.encode_intunconst(val, signed=False)
|
||||
else:
|
||||
# 10.4 a ~ d
|
||||
if const_val.ub is not None:
|
||||
dbl = round_p2(max(int_bytelen(const_val.lb),
|
||||
int_bytelen(const_val.ub)))
|
||||
if dbl <= 8:
|
||||
return [(T_INT, val, dbl*8)]
|
||||
# No upper bound etc.
|
||||
return cls.encode_intunconst(val)
|
||||
else:
|
||||
# No lower bound -> encode with length determinant
|
||||
return cls.encode_intunconst(val)
|
||||
|
||||
@classmethod
|
||||
def encode_intconst_ws(cls, val, const_val):
|
||||
if const_val.lb is not None:
|
||||
if const_val.lb >= 0:
|
||||
# 10.3 a ~ d Check on the upper bound
|
||||
if const_val.ub is not None:
|
||||
ubl = round_p2(uint_bytelen(const_val.ub))
|
||||
if ubl <= 8:
|
||||
return (Uint('V', val=val, bl=ubl*8),)
|
||||
# No other conditions are fulfilled
|
||||
return cls.encode_intunconst_ws(val, signed=False)
|
||||
else:
|
||||
# 10.4 a ~ d
|
||||
if const_val.ub is not None:
|
||||
dbl = round_p2(max(int_bytelen(const_val.lb),
|
||||
int_bytelen(const_val.ub)))
|
||||
if dbl <= 8:
|
||||
return (Int('V', val=val, bl=dbl*8),)
|
||||
# No upper bound etc.
|
||||
return cls.encode_intunconst_ws(val)
|
||||
else:
|
||||
# No lower bound -> encode with length determinant
|
||||
return cls.encode_intunconst_ws(val)
|
||||
|
||||
@classmethod
|
||||
def decode_intconst(cls, char, const_val):
|
||||
if const_val.lb is not None:
|
||||
if const_val.lb >= 0:
|
||||
# 10.3 a ~ d Check on the upper bound
|
||||
if const_val.ub is not None:
|
||||
ubl = round_p2(uint_bytelen(const_val.ub))
|
||||
if ubl <= 8:
|
||||
return char.get_uint(ubl*8)
|
||||
# No other conditions are fulfilled
|
||||
return cls.decode_intunconst(char, signed=False)
|
||||
else:
|
||||
# 10.4 a ~ d
|
||||
if const_val.ub is not None:
|
||||
dbl = round_p2(max(int_bytelen(const_val.lb),
|
||||
int_bytelen(const_val.ub)))
|
||||
if dbl <= 8:
|
||||
return char.get_int(dbl*8)
|
||||
# No upper bound etc.
|
||||
return cls.decode_intunconst(char)
|
||||
else:
|
||||
# No lower bound -> encode with length determinant
|
||||
return cls.decode_intunconst(char)
|
||||
|
||||
@classmethod
|
||||
def decode_intconst_ws(cls, char, const_val):
|
||||
if const_val.lb is not None:
|
||||
if const_val.lb >= 0:
|
||||
# 10.3 a ~ d Check on the upper bound
|
||||
if const_val.ub is not None:
|
||||
ubl = round_p2(uint_bytelen(const_val.ub))
|
||||
if ubl <= 8:
|
||||
val = Uint('V', bl=ubl*8)
|
||||
val._from_char(char)
|
||||
return val.get_val(), (val,)
|
||||
# No other conditions are fulfilled
|
||||
return cls.decode_intunconst_ws(char, signed=False)
|
||||
else:
|
||||
# 10.4 a ~ d
|
||||
if const_val.ub is not None:
|
||||
dbl = round_p2(max(int_bytelen(const_val.lb),
|
||||
int_bytelen(const_val.ub)))
|
||||
if dbl <= 8:
|
||||
val = Int('V', bl=dbl*8)
|
||||
val._from_char(char)
|
||||
return val.get_val(), (val,)
|
||||
# No upper bound etc.
|
||||
return cls.decode_intunconst_ws(char)
|
||||
else:
|
||||
# No lower bound -> encode with length determinant
|
||||
return cls.decode_intunconst_ws(char)
|
||||
|
||||
@classmethod
|
||||
def encode_enumerated(cls, val):
|
||||
# Always canonical (implementing non-canonical doesn't make sense)
|
||||
_gen = []
|
||||
if 0 <= val <= 127:
|
||||
# short form
|
||||
_gen.append((T_UINT, val, 8))
|
||||
else:
|
||||
# long form
|
||||
dl = int_bytelen(val)
|
||||
_gen.extend([(T_UINT, 1, 1),
|
||||
(T_UINT, dl, 7),
|
||||
(T_INT, val, dl * 8)
|
||||
])
|
||||
|
||||
return _gen
|
||||
|
||||
@classmethod
|
||||
def encode_enumerated_ws(cls, val):
|
||||
if 0 <= val <= 127:
|
||||
# short form
|
||||
_gen = (
|
||||
Uint('Form', val=0, bl=1, dic=cls.LenFormLUT),
|
||||
Uint('Val', val=val, bl=7)
|
||||
)
|
||||
else:
|
||||
# long form
|
||||
dl = int_bytelen(val)
|
||||
_gen = (
|
||||
Uint('Form', val=1, bl=1, dic=cls.LenFormLUT),
|
||||
Uint('Len', val=dl, bl=7),
|
||||
Int('Val', val=val, bl=dl*8)
|
||||
)
|
||||
|
||||
return Envelope('L', GEN=_gen)
|
||||
|
||||
@classmethod
|
||||
def decode_enumerated(cls, char):
|
||||
long_form = char.get_uint(1)
|
||||
val = char.get_uint(7)
|
||||
if long_form:
|
||||
val = char.get_int(val*8)
|
||||
return val
|
||||
|
||||
@classmethod
|
||||
def decode_enumerated_ws(cls, char):
|
||||
t_enum = Envelope('L', GEN=(
|
||||
Uint('Form', bl=1, dic=cls.LenFormLUT),
|
||||
Uint('Val', bl=7)
|
||||
))
|
||||
t_enum._from_char(char)
|
||||
long_form = t_enum[0].get_val()
|
||||
enum_val = t_enum[1].get_val()
|
||||
if long_form:
|
||||
t_enum[1]._name = "Len"
|
||||
val = Int('Val', bl=8*enum_val)
|
||||
val._from_char(char)
|
||||
enum_val = val.get_val()
|
||||
t_enum.append(val)
|
||||
return enum_val, t_enum
|
||||
|
||||
@classmethod
|
||||
def encode_open_type(cls, value_bytes):
|
||||
# The standard is quite unclear to me about this. But tested on CHOICE
|
||||
# with extension type using ASN1 Playground, it seems it is the correct
|
||||
# implementation.
|
||||
l_val = len(value_bytes)
|
||||
tmp = (cls.encode_length_determinant(l_val))
|
||||
tmp.append((T_BYTES, value_bytes, l_val*8))
|
||||
return tmp
|
||||
|
||||
@classmethod
|
||||
def encode_open_type_ws(cls, value_bytes):
|
||||
l_val = len(value_bytes)
|
||||
_gen = [cls.encode_length_determinant_ws(l_val)]
|
||||
_gen.append(Buf('V', val=value_bytes, bl=l_val*8))
|
||||
return Envelope("Open-Type", GEN=tuple(_gen))
|
||||
|
||||
@classmethod
|
||||
def decode_open_type(cls, char):
|
||||
l_val = cls.decode_length_determinant(char)
|
||||
val_bytes = char.get_bytes(l_val * 8)
|
||||
return val_bytes
|
||||
|
||||
@classmethod
|
||||
def decode_open_type_ws(cls, char):
|
||||
l_val, l_struct = cls.decode_length_determinant_ws(char)
|
||||
_gen = [l_struct]
|
||||
val_struct = Buf('V', bl=l_val*8)
|
||||
val_struct._from_char(char)
|
||||
_gen.append(val_struct)
|
||||
val_bytes = val_struct.get_val()
|
||||
return val_bytes, Envelope("Open-Type", GEN=tuple(_gen))
|
||||
|
||||
|
|
|
@ -85,3 +85,8 @@ class ASN1JERDecodeErr(ASN1CodecErr):
|
|||
#class ASN1GSERDecodeErr(ASN1CodecErr):
|
||||
# pass
|
||||
|
||||
class ASN1OERDecodeErr(ASN1CodecErr):
|
||||
pass
|
||||
|
||||
class ASN1OEREncodeErr(ASN1CodecErr):
|
||||
pass
|
||||
|
|
|
@ -2113,3 +2113,60 @@ def pack_val(*val):
|
|||
#
|
||||
# 7) return the length in bits and bytes buffer
|
||||
return b''.join(concat), len_bit
|
||||
|
||||
# OER related REAL handling
|
||||
|
||||
def decode_ieee754_32(char):
|
||||
""" Converts IEE754 single precision float to a pycrate REAL tuple:
|
||||
"""
|
||||
sign = (-1) ** char.get_uint(1)
|
||||
exponent = char.get_uint(8) - 127
|
||||
fraction = char.get_uint(23)
|
||||
lsb = 0
|
||||
ifrac = 1
|
||||
for i in range(23):
|
||||
lb = fraction & 1
|
||||
if lb and (lsb == 0):
|
||||
lsb = 23 - i
|
||||
ifrac += 2 ** (-(23 - i)) * lb
|
||||
fraction = fraction >> 1
|
||||
|
||||
# Convert the normalized mantissa (1.xxx) to a integer mantissa by multiplying 2
|
||||
ifrac = int((sign * ifrac) * (2 ** lsb))
|
||||
return (ifrac, 2, exponent - lsb)
|
||||
|
||||
|
||||
def encode_ieee754_32(val):
|
||||
""" Converts pycrate REAL tuple into IEEE754 single precision value.
|
||||
"""
|
||||
# There is of course a more efficient method going straight from mantissa,
|
||||
# but sorry, no time. This at least works for arbitrary base.
|
||||
return pack('>f', val[0] * (val[1] ** val[2]))
|
||||
|
||||
|
||||
def decode_ieee754_64(char):
|
||||
""" Converts IEE754 single precision float to a pycrate REAL tuple:
|
||||
"""
|
||||
sign = (-1) ** char.get_uint(1)
|
||||
exponent = char.get_uint(11) - 1023
|
||||
fraction = char.get_uint(52)
|
||||
lsb = 0
|
||||
ifrac = 1
|
||||
for i in range(52):
|
||||
lb = fraction & 1
|
||||
if lb and (lsb == 0):
|
||||
lsb = 53 - i
|
||||
ifrac += 2 ** (-(52 - i)) * lb
|
||||
fraction = fraction >> 1
|
||||
|
||||
# Convert the normalized mantissa (1.xxx) to a integer mantissa by multiplying 2
|
||||
ifrac = int((sign * ifrac) * (2 ** lsb))
|
||||
return (ifrac, 2, exponent - lsb)
|
||||
|
||||
|
||||
def encode_ieee754_64(val):
|
||||
""" Converts pycrate REAL tuple into IEEE754 single precision value.
|
||||
"""
|
||||
# There is of course a more efficient method going straight from mantissa,
|
||||
# but sorry, no time. This at least works for arbitrary base.
|
||||
return pack('>d', val[0] * (val[1] ** val[2]))
|
||||
|
|
|
@ -44,14 +44,16 @@ BEGIN
|
|||
Bst03 ::= BIT STRING (SIZE (0..24, ...))
|
||||
Bst04 ::= BIT STRING (SIZE (65536..16777216))
|
||||
Bst05 ::= BIT STRING (CONTAINING Enu01)
|
||||
|
||||
Bst06 ::= BIT STRING (SIZE (16))
|
||||
|
||||
-- OCTET STRING
|
||||
Ost01 ::= OCTET STRING
|
||||
Ost02 ::= OCTET STRING (SIZE (0..24))
|
||||
Ost03 ::= OCTET STRING (SIZE (0..24, ...))
|
||||
Ost04 ::= OCTET STRING (SIZE (65536..16777216))
|
||||
Ost05 ::= OCTET STRING (CONTAINING Enu01)
|
||||
|
||||
Ost06 ::= OCTET STRING (SIZE (16))
|
||||
|
||||
-- String
|
||||
Nus01 ::= NumericString
|
||||
Nus02 ::= NumericString (FROM ("0123"))
|
||||
|
@ -60,6 +62,7 @@ BEGIN
|
|||
Ias01 ::= IA5String
|
||||
Ias02 ::= IA5String (SIZE (0..24))
|
||||
Ias03 ::= IA5String (SIZE (0..65535, ...))
|
||||
Ias04 ::= IA5String (SIZE (32))
|
||||
U8s01 ::= UTF8String
|
||||
U8s02 ::= UTF8String (SIZE (0..24))
|
||||
U8s03 ::= UTF8String (SIZE (0..65535, ...))
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,120 +16,126 @@ from pycrate_asn1rt.init import init_modules
|
|||
|
||||
class Test_Asn1rt:
|
||||
|
||||
_name_ = u'Test-Asn1rt'
|
||||
_name_ = 'Test-Asn1rt'
|
||||
_oid_ = []
|
||||
|
||||
_obj_ = [
|
||||
u'Null',
|
||||
u'Boo01',
|
||||
u'Boo02',
|
||||
u'Int01',
|
||||
u'Int02',
|
||||
u'Int03',
|
||||
u'Int04',
|
||||
u'Int05',
|
||||
u'Int06',
|
||||
u'Int07',
|
||||
u'Int08',
|
||||
u'Int09',
|
||||
u'Int10',
|
||||
u'Int11',
|
||||
u'Int12',
|
||||
u'Int13',
|
||||
u'Int14',
|
||||
u'Rea01',
|
||||
u'Rea02',
|
||||
u'Enu01',
|
||||
u'Enu02',
|
||||
u'Enu03',
|
||||
u'Enu04',
|
||||
u'Oid01',
|
||||
u'Oid02',
|
||||
u'Bst01',
|
||||
u'Bst02',
|
||||
u'Bst03',
|
||||
u'Bst04',
|
||||
u'Bst05',
|
||||
u'Ost01',
|
||||
u'Ost02',
|
||||
u'Ost03',
|
||||
u'Ost04',
|
||||
u'Ost05',
|
||||
u'Nus01',
|
||||
u'Nus02',
|
||||
u'Prs01',
|
||||
u'Prs02',
|
||||
u'Ias01',
|
||||
u'Ias02',
|
||||
u'Ias03',
|
||||
u'U8s01',
|
||||
u'U8s02',
|
||||
u'U8s03',
|
||||
u'Uns01',
|
||||
u'Uns02',
|
||||
u'Uti01',
|
||||
u'Gti01',
|
||||
u'Int24',
|
||||
u'Cho01',
|
||||
u'Seq01',
|
||||
u'Seq02',
|
||||
u'Set01',
|
||||
'Null',
|
||||
'Boo01',
|
||||
'Boo02',
|
||||
'Int01',
|
||||
'Int02',
|
||||
'Int03',
|
||||
'Int04',
|
||||
'Int05',
|
||||
'Int06',
|
||||
'Int07',
|
||||
'Int08',
|
||||
'Int09',
|
||||
'Int10',
|
||||
'Int11',
|
||||
'Int12',
|
||||
'Int13',
|
||||
'Int14',
|
||||
'Rea01',
|
||||
'Rea02',
|
||||
'Enu01',
|
||||
'Enu02',
|
||||
'Enu03',
|
||||
'Enu04',
|
||||
'Oid01',
|
||||
'Oid02',
|
||||
'Bst01',
|
||||
'Bst02',
|
||||
'Bst03',
|
||||
'Bst04',
|
||||
'Bst05',
|
||||
'Bst06',
|
||||
'Ost01',
|
||||
'Ost02',
|
||||
'Ost03',
|
||||
'Ost04',
|
||||
'Ost05',
|
||||
'Ost06',
|
||||
'Nus01',
|
||||
'Nus02',
|
||||
'Prs01',
|
||||
'Prs02',
|
||||
'Ias01',
|
||||
'Ias02',
|
||||
'Ias03',
|
||||
'Ias04',
|
||||
'U8s01',
|
||||
'U8s02',
|
||||
'U8s03',
|
||||
'Uns01',
|
||||
'Uns02',
|
||||
'Uti01',
|
||||
'Gti01',
|
||||
'Int24',
|
||||
'Cho01',
|
||||
'Seq01',
|
||||
'Seq02',
|
||||
'Set01',
|
||||
]
|
||||
_type_ = [
|
||||
u'Null',
|
||||
u'Boo01',
|
||||
u'Boo02',
|
||||
u'Int01',
|
||||
u'Int02',
|
||||
u'Int03',
|
||||
u'Int04',
|
||||
u'Int05',
|
||||
u'Int06',
|
||||
u'Int07',
|
||||
u'Int08',
|
||||
u'Int09',
|
||||
u'Int10',
|
||||
u'Int11',
|
||||
u'Int12',
|
||||
u'Int13',
|
||||
u'Int14',
|
||||
u'Rea01',
|
||||
u'Rea02',
|
||||
u'Enu01',
|
||||
u'Enu02',
|
||||
u'Enu03',
|
||||
u'Enu04',
|
||||
u'Oid01',
|
||||
u'Oid02',
|
||||
u'Bst01',
|
||||
u'Bst02',
|
||||
u'Bst03',
|
||||
u'Bst04',
|
||||
u'Bst05',
|
||||
u'Ost01',
|
||||
u'Ost02',
|
||||
u'Ost03',
|
||||
u'Ost04',
|
||||
u'Ost05',
|
||||
u'Nus01',
|
||||
u'Nus02',
|
||||
u'Prs01',
|
||||
u'Prs02',
|
||||
u'Ias01',
|
||||
u'Ias02',
|
||||
u'Ias03',
|
||||
u'U8s01',
|
||||
u'U8s02',
|
||||
u'U8s03',
|
||||
u'Uns01',
|
||||
u'Uns02',
|
||||
u'Uti01',
|
||||
u'Gti01',
|
||||
u'Int24',
|
||||
u'Cho01',
|
||||
u'Seq01',
|
||||
u'Seq02',
|
||||
u'Set01',
|
||||
'Null',
|
||||
'Boo01',
|
||||
'Boo02',
|
||||
'Int01',
|
||||
'Int02',
|
||||
'Int03',
|
||||
'Int04',
|
||||
'Int05',
|
||||
'Int06',
|
||||
'Int07',
|
||||
'Int08',
|
||||
'Int09',
|
||||
'Int10',
|
||||
'Int11',
|
||||
'Int12',
|
||||
'Int13',
|
||||
'Int14',
|
||||
'Rea01',
|
||||
'Rea02',
|
||||
'Enu01',
|
||||
'Enu02',
|
||||
'Enu03',
|
||||
'Enu04',
|
||||
'Oid01',
|
||||
'Oid02',
|
||||
'Bst01',
|
||||
'Bst02',
|
||||
'Bst03',
|
||||
'Bst04',
|
||||
'Bst05',
|
||||
'Bst06',
|
||||
'Ost01',
|
||||
'Ost02',
|
||||
'Ost03',
|
||||
'Ost04',
|
||||
'Ost05',
|
||||
'Ost06',
|
||||
'Nus01',
|
||||
'Nus02',
|
||||
'Prs01',
|
||||
'Prs02',
|
||||
'Ias01',
|
||||
'Ias02',
|
||||
'Ias03',
|
||||
'Ias04',
|
||||
'U8s01',
|
||||
'U8s02',
|
||||
'U8s03',
|
||||
'Uns01',
|
||||
'Uns02',
|
||||
'Uti01',
|
||||
'Gti01',
|
||||
'Int24',
|
||||
'Cho01',
|
||||
'Seq01',
|
||||
'Seq02',
|
||||
'Set01',
|
||||
]
|
||||
_set_ = [
|
||||
]
|
||||
|
@ -141,257 +147,269 @@ class Test_Asn1rt:
|
|||
]
|
||||
|
||||
#-----< Null >-----#
|
||||
Null = NULL(name=u'Null', mode=MODE_TYPE)
|
||||
Null = NULL(name='Null', mode=MODE_TYPE)
|
||||
|
||||
#-----< Boo01 >-----#
|
||||
Boo01 = BOOL(name=u'Boo01', mode=MODE_TYPE)
|
||||
Boo01 = BOOL(name='Boo01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Boo02 >-----#
|
||||
Boo02 = BOOL(name=u'Boo02', mode=MODE_TYPE)
|
||||
Boo02 = BOOL(name='Boo02', mode=MODE_TYPE)
|
||||
Boo02._const_val = ASN1Set(rv=[True], rr=[], ev=None, er=[])
|
||||
|
||||
#-----< Int01 >-----#
|
||||
Int01 = INT(name=u'Int01', mode=MODE_TYPE)
|
||||
Int01 = INT(name='Int01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Int02 >-----#
|
||||
Int02 = INT(name=u'Int02', mode=MODE_TYPE)
|
||||
Int02 = INT(name='Int02', mode=MODE_TYPE)
|
||||
Int02._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=None, ub=65535)], ev=None, er=[])
|
||||
|
||||
#-----< Int03 >-----#
|
||||
Int03 = INT(name=u'Int03', mode=MODE_TYPE)
|
||||
Int03 = INT(name='Int03', mode=MODE_TYPE)
|
||||
Int03._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=-1, ub=None)], ev=None, er=[])
|
||||
|
||||
#-----< Int04 >-----#
|
||||
Int04 = INT(name=u'Int04', mode=MODE_TYPE)
|
||||
Int04 = INT(name='Int04', mode=MODE_TYPE)
|
||||
Int04._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=1, ub=None)], ev=None, er=[])
|
||||
|
||||
#-----< Int05 >-----#
|
||||
Int05 = INT(name=u'Int05', mode=MODE_TYPE)
|
||||
Int05 = INT(name='Int05', mode=MODE_TYPE)
|
||||
Int05._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=None)], ev=None, er=[])
|
||||
|
||||
#-----< Int06 >-----#
|
||||
Int06 = INT(name=u'Int06', mode=MODE_TYPE)
|
||||
Int06 = INT(name='Int06', mode=MODE_TYPE)
|
||||
Int06._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=3, ub=6)], ev=None, er=[])
|
||||
|
||||
#-----< Int07 >-----#
|
||||
Int07 = INT(name=u'Int07', mode=MODE_TYPE)
|
||||
Int07 = INT(name='Int07', mode=MODE_TYPE)
|
||||
Int07._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=4000, ub=4254)], ev=None, er=[])
|
||||
|
||||
#-----< Int08 >-----#
|
||||
Int08 = INT(name=u'Int08', mode=MODE_TYPE)
|
||||
Int08 = INT(name='Int08', mode=MODE_TYPE)
|
||||
Int08._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=4000, ub=4255)], ev=None, er=[])
|
||||
|
||||
#-----< Int09 >-----#
|
||||
Int09 = INT(name=u'Int09', mode=MODE_TYPE)
|
||||
Int09 = INT(name='Int09', mode=MODE_TYPE)
|
||||
Int09._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=32000)], ev=None, er=[])
|
||||
|
||||
#-----< Int10 >-----#
|
||||
Int10 = INT(name=u'Int10', mode=MODE_TYPE)
|
||||
Int10 = INT(name='Int10', mode=MODE_TYPE)
|
||||
Int10._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=1, ub=65538)], ev=None, er=[])
|
||||
|
||||
#-----< Int11 >-----#
|
||||
Int11 = INT(name=u'Int11', mode=MODE_TYPE)
|
||||
Int11 = INT(name='Int11', mode=MODE_TYPE)
|
||||
Int11._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=None, ub=65535)], ev=[], er=[])
|
||||
|
||||
#-----< Int12 >-----#
|
||||
Int12 = INT(name=u'Int12', mode=MODE_TYPE)
|
||||
Int12 = INT(name='Int12', mode=MODE_TYPE)
|
||||
Int12._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=-1, ub=None)], ev=[], er=[])
|
||||
|
||||
#-----< Int13 >-----#
|
||||
Int13 = INT(name=u'Int13', mode=MODE_TYPE)
|
||||
Int13 = INT(name='Int13', mode=MODE_TYPE)
|
||||
Int13._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=3, ub=6)], ev=[], er=[])
|
||||
|
||||
#-----< Int14 >-----#
|
||||
Int14 = INT(name=u'Int14', mode=MODE_TYPE)
|
||||
Int14 = INT(name='Int14', mode=MODE_TYPE)
|
||||
Int14._const_val = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=1, ub=65538)], ev=[], er=[])
|
||||
|
||||
#-----< Rea01 >-----#
|
||||
Rea01 = REAL(name=u'Rea01', mode=MODE_TYPE, typeref=ASN1RefType(('_IMPL_', 'REAL')))
|
||||
Rea01 = REAL(name='Rea01', mode=MODE_TYPE, typeref=ASN1RefType(('_IMPL_', 'REAL')))
|
||||
|
||||
#-----< Rea02 >-----#
|
||||
Rea02 = REAL(name=u'Rea02', mode=MODE_TYPE, typeref=ASN1RefType(('_IMPL_', 'REAL')))
|
||||
Rea02 = REAL(name='Rea02', mode=MODE_TYPE, typeref=ASN1RefType(('_IMPL_', 'REAL')))
|
||||
Rea02._const_val = ASN1Set(rv=[], rr=[ASN1RangeReal(lb=(0, 10, -2), ub=(999, 10, -11), lb_incl=True, ub_incl=True)], ev=None, er=[])
|
||||
|
||||
#-----< Enu01 >-----#
|
||||
Enu01 = ENUM(name=u'Enu01', mode=MODE_TYPE)
|
||||
Enu01._cont = ASN1Dict([(u'cheese', 0), (u'cake', 1), (u'coffee', 2), (u'tea', 3)])
|
||||
Enu01 = ENUM(name='Enu01', mode=MODE_TYPE)
|
||||
Enu01._cont = ASN1Dict([('cheese', 0), ('cake', 1), ('coffee', 2), ('tea', 3)])
|
||||
Enu01._ext = None
|
||||
|
||||
#-----< Enu02 >-----#
|
||||
Enu02 = ENUM(name=u'Enu02', mode=MODE_TYPE)
|
||||
Enu02._cont = ASN1Dict([(u'cheese', 0)])
|
||||
Enu02 = ENUM(name='Enu02', mode=MODE_TYPE)
|
||||
Enu02._cont = ASN1Dict([('cheese', 0)])
|
||||
Enu02._ext = None
|
||||
|
||||
#-----< Enu03 >-----#
|
||||
Enu03 = ENUM(name=u'Enu03', mode=MODE_TYPE)
|
||||
Enu03._cont = ASN1Dict([(u'cheese', 0)])
|
||||
Enu03 = ENUM(name='Enu03', mode=MODE_TYPE)
|
||||
Enu03._cont = ASN1Dict([('cheese', 0)])
|
||||
Enu03._ext = []
|
||||
|
||||
#-----< Enu04 >-----#
|
||||
Enu04 = ENUM(name=u'Enu04', mode=MODE_TYPE)
|
||||
Enu04._cont = ASN1Dict([(u'cheese', 0), (u'cake', 1), (u'coffee', 2), (u'tea', 3)])
|
||||
Enu04._ext = [u'cake', u'coffee', u'tea']
|
||||
Enu04 = ENUM(name='Enu04', mode=MODE_TYPE)
|
||||
Enu04._cont = ASN1Dict([('cheese', 0), ('cake', 1), ('coffee', 2), ('tea', 3)])
|
||||
Enu04._ext = ['cake', 'coffee', 'tea']
|
||||
|
||||
#-----< Oid01 >-----#
|
||||
Oid01 = OID(name=u'Oid01', mode=MODE_TYPE)
|
||||
Oid01 = OID(name='Oid01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Oid02 >-----#
|
||||
Oid02 = REL_OID(name=u'Oid02', mode=MODE_TYPE)
|
||||
Oid02 = REL_OID(name='Oid02', mode=MODE_TYPE)
|
||||
|
||||
#-----< Bst01 >-----#
|
||||
Bst01 = BIT_STR(name=u'Bst01', mode=MODE_TYPE)
|
||||
Bst01 = BIT_STR(name='Bst01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Bst02 >-----#
|
||||
Bst02 = BIT_STR(name=u'Bst02', mode=MODE_TYPE)
|
||||
Bst02 = BIT_STR(name='Bst02', mode=MODE_TYPE)
|
||||
Bst02._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=24)], ev=None, er=[])
|
||||
|
||||
#-----< Bst03 >-----#
|
||||
Bst03 = BIT_STR(name=u'Bst03', mode=MODE_TYPE)
|
||||
Bst03 = BIT_STR(name='Bst03', mode=MODE_TYPE)
|
||||
Bst03._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=24)], ev=[], er=[])
|
||||
|
||||
#-----< Bst04 >-----#
|
||||
Bst04 = BIT_STR(name=u'Bst04', mode=MODE_TYPE)
|
||||
Bst04 = BIT_STR(name='Bst04', mode=MODE_TYPE)
|
||||
Bst04._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=65536, ub=16777216)], ev=None, er=[])
|
||||
|
||||
#-----< Bst05 >-----#
|
||||
Bst05 = BIT_STR(name=u'Bst05', mode=MODE_TYPE)
|
||||
Bst05 = BIT_STR(name='Bst05', mode=MODE_TYPE)
|
||||
_Bst05_contain = ENUM(name='_cont_Bst05', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')))
|
||||
Bst05._const_cont = _Bst05_contain
|
||||
|
||||
#-----< Bst06 >-----#
|
||||
Bst06 = BIT_STR(name='Bst06', mode=MODE_TYPE)
|
||||
Bst06._const_sz = ASN1Set(rv=[16], rr=[], ev=None, er=[])
|
||||
|
||||
#-----< Ost01 >-----#
|
||||
Ost01 = OCT_STR(name=u'Ost01', mode=MODE_TYPE)
|
||||
Ost01 = OCT_STR(name='Ost01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Ost02 >-----#
|
||||
Ost02 = OCT_STR(name=u'Ost02', mode=MODE_TYPE)
|
||||
Ost02 = OCT_STR(name='Ost02', mode=MODE_TYPE)
|
||||
Ost02._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=24)], ev=None, er=[])
|
||||
|
||||
#-----< Ost03 >-----#
|
||||
Ost03 = OCT_STR(name=u'Ost03', mode=MODE_TYPE)
|
||||
Ost03 = OCT_STR(name='Ost03', mode=MODE_TYPE)
|
||||
Ost03._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=24)], ev=[], er=[])
|
||||
|
||||
#-----< Ost04 >-----#
|
||||
Ost04 = OCT_STR(name=u'Ost04', mode=MODE_TYPE)
|
||||
Ost04 = OCT_STR(name='Ost04', mode=MODE_TYPE)
|
||||
Ost04._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=65536, ub=16777216)], ev=None, er=[])
|
||||
|
||||
#-----< Ost05 >-----#
|
||||
Ost05 = OCT_STR(name=u'Ost05', mode=MODE_TYPE)
|
||||
Ost05 = OCT_STR(name='Ost05', mode=MODE_TYPE)
|
||||
_Ost05_contain = ENUM(name='_cont_Ost05', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')))
|
||||
Ost05._const_cont = _Ost05_contain
|
||||
|
||||
#-----< Ost06 >-----#
|
||||
Ost06 = OCT_STR(name='Ost06', mode=MODE_TYPE)
|
||||
Ost06._const_sz = ASN1Set(rv=[16], rr=[], ev=None, er=[])
|
||||
|
||||
#-----< Nus01 >-----#
|
||||
Nus01 = STR_NUM(name=u'Nus01', mode=MODE_TYPE)
|
||||
Nus01 = STR_NUM(name='Nus01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Nus02 >-----#
|
||||
Nus02 = STR_NUM(name=u'Nus02', mode=MODE_TYPE)
|
||||
Nus02._const_alpha = ASN1Set(rv=[u'0', u'1', u'2', u'3'], rr=[], ev=None, er=[])
|
||||
Nus02 = STR_NUM(name='Nus02', mode=MODE_TYPE)
|
||||
Nus02._const_alpha = ASN1Set(rv=['0', '1', '2', '3'], rr=[], ev=None, er=[])
|
||||
|
||||
#-----< Prs01 >-----#
|
||||
Prs01 = STR_PRINT(name=u'Prs01', mode=MODE_TYPE)
|
||||
Prs01 = STR_PRINT(name='Prs01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Prs02 >-----#
|
||||
Prs02 = STR_PRINT(name=u'Prs02', mode=MODE_TYPE)
|
||||
Prs02._const_alpha = ASN1Set(rv=[u'A', u'T', u'C', u'G'], rr=[], ev=None, er=[])
|
||||
Prs02 = STR_PRINT(name='Prs02', mode=MODE_TYPE)
|
||||
Prs02._const_alpha = ASN1Set(rv=['A', 'T', 'C', 'G'], rr=[], ev=None, er=[])
|
||||
|
||||
#-----< Ias01 >-----#
|
||||
Ias01 = STR_IA5(name=u'Ias01', mode=MODE_TYPE)
|
||||
Ias01 = STR_IA5(name='Ias01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Ias02 >-----#
|
||||
Ias02 = STR_IA5(name=u'Ias02', mode=MODE_TYPE)
|
||||
Ias02 = STR_IA5(name='Ias02', mode=MODE_TYPE)
|
||||
Ias02._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=24)], ev=None, er=[])
|
||||
|
||||
#-----< Ias03 >-----#
|
||||
Ias03 = STR_IA5(name=u'Ias03', mode=MODE_TYPE)
|
||||
Ias03 = STR_IA5(name='Ias03', mode=MODE_TYPE)
|
||||
Ias03._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=65535)], ev=[], er=[])
|
||||
|
||||
#-----< Ias04 >-----#
|
||||
Ias04 = STR_IA5(name='Ias04', mode=MODE_TYPE)
|
||||
Ias04._const_sz = ASN1Set(rv=[32], rr=[], ev=None, er=[])
|
||||
|
||||
#-----< U8s01 >-----#
|
||||
U8s01 = STR_UTF8(name=u'U8s01', mode=MODE_TYPE)
|
||||
U8s01 = STR_UTF8(name='U8s01', mode=MODE_TYPE)
|
||||
|
||||
#-----< U8s02 >-----#
|
||||
U8s02 = STR_UTF8(name=u'U8s02', mode=MODE_TYPE)
|
||||
U8s02 = STR_UTF8(name='U8s02', mode=MODE_TYPE)
|
||||
U8s02._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=24)], ev=None, er=[])
|
||||
|
||||
#-----< U8s03 >-----#
|
||||
U8s03 = STR_UTF8(name=u'U8s03', mode=MODE_TYPE)
|
||||
U8s03 = STR_UTF8(name='U8s03', mode=MODE_TYPE)
|
||||
U8s03._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=65535)], ev=[], er=[])
|
||||
|
||||
#-----< Uns01 >-----#
|
||||
Uns01 = STR_UNIV(name=u'Uns01', mode=MODE_TYPE)
|
||||
Uns01 = STR_UNIV(name='Uns01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Uns02 >-----#
|
||||
Uns02 = STR_UNIV(name=u'Uns02', mode=MODE_TYPE)
|
||||
Uns02 = STR_UNIV(name='Uns02', mode=MODE_TYPE)
|
||||
Uns02._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=0, ub=255)], ev=[], er=[])
|
||||
|
||||
#-----< Uti01 >-----#
|
||||
Uti01 = TIME_UTC(name=u'Uti01', mode=MODE_TYPE)
|
||||
Uti01 = TIME_UTC(name='Uti01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Gti01 >-----#
|
||||
Gti01 = TIME_GEN(name=u'Gti01', mode=MODE_TYPE)
|
||||
Gti01 = TIME_GEN(name='Gti01', mode=MODE_TYPE)
|
||||
|
||||
#-----< Int24 >-----#
|
||||
Int24 = INT(name=u'Int24', mode=MODE_TYPE, tag=(80, TAG_APPLICATION, TAG_EXPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int04')))
|
||||
Int24 = INT(name='Int24', mode=MODE_TYPE, tag=(80, TAG_APPLICATION, TAG_EXPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int04')))
|
||||
|
||||
#-----< Cho01 >-----#
|
||||
Cho01 = CHOICE(name=u'Cho01', mode=MODE_TYPE)
|
||||
_Cho01_boo = BOOL(name=u'boo', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
_Cho01_int = INT(name=u'int', mode=MODE_TYPE, tag=(10, TAG_CONTEXT_SPEC, TAG_EXPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int24')))
|
||||
_Cho01_enu = ENUM(name=u'enu', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')))
|
||||
_Cho01_bst = BIT_STR(name=u'bst', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Bst03')))
|
||||
Cho01 = CHOICE(name='Cho01', mode=MODE_TYPE)
|
||||
_Cho01_boo = BOOL(name='boo', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
_Cho01_int = INT(name='int', mode=MODE_TYPE, tag=(10, TAG_CONTEXT_SPEC, TAG_EXPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int24')))
|
||||
_Cho01_enu = ENUM(name='enu', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')))
|
||||
_Cho01_bst = BIT_STR(name='bst', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Bst03')))
|
||||
Cho01._cont = ASN1Dict([
|
||||
(u'boo', _Cho01_boo),
|
||||
(u'int', _Cho01_int),
|
||||
(u'enu', _Cho01_enu),
|
||||
(u'bst', _Cho01_bst),
|
||||
('boo', _Cho01_boo),
|
||||
('int', _Cho01_int),
|
||||
('enu', _Cho01_enu),
|
||||
('bst', _Cho01_bst),
|
||||
])
|
||||
Cho01._ext = [u'bst']
|
||||
Cho01._ext = ['bst']
|
||||
|
||||
#-----< Seq01 >-----#
|
||||
Seq01 = SEQ(name=u'Seq01', mode=MODE_TYPE)
|
||||
_Seq01_boo = BOOL(name=u'boo', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
_Seq01_int = INT(name=u'int', mode=MODE_TYPE, tag=(128, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int24')), default=10)
|
||||
_Seq01_enu = ENUM(name=u'enu', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')), opt=True)
|
||||
_Seq01_bst = BIT_STR(name=u'bst', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Bst01')), group=0)
|
||||
_Seq01_ost = OCT_STR(name=u'ost', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Ost02')), group=0)
|
||||
Seq01 = SEQ(name='Seq01', mode=MODE_TYPE)
|
||||
_Seq01_boo = BOOL(name='boo', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
_Seq01_int = INT(name='int', mode=MODE_TYPE, tag=(128, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int24')), default=10)
|
||||
_Seq01_enu = ENUM(name='enu', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')), opt=True)
|
||||
_Seq01_bst = BIT_STR(name='bst', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Bst01')), group=0)
|
||||
_Seq01_ost = OCT_STR(name='ost', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Ost02')), group=0)
|
||||
Seq01._cont = ASN1Dict([
|
||||
(u'boo', _Seq01_boo),
|
||||
(u'int', _Seq01_int),
|
||||
(u'enu', _Seq01_enu),
|
||||
(u'bst', _Seq01_bst),
|
||||
(u'ost', _Seq01_ost),
|
||||
('boo', _Seq01_boo),
|
||||
('int', _Seq01_int),
|
||||
('enu', _Seq01_enu),
|
||||
('bst', _Seq01_bst),
|
||||
('ost', _Seq01_ost),
|
||||
])
|
||||
Seq01._ext = [u'bst', u'ost']
|
||||
Seq01._ext = ['bst', 'ost']
|
||||
|
||||
#-----< Seq02 >-----#
|
||||
Seq02 = SEQ_OF(name=u'Seq02', mode=MODE_TYPE)
|
||||
Seq02 = SEQ_OF(name='Seq02', mode=MODE_TYPE)
|
||||
_Seq02__item_ = STR_IA5(name='_item_', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Ias02')))
|
||||
Seq02._cont = _Seq02__item_
|
||||
Seq02._const_sz = ASN1Set(rv=[], rr=[ASN1RangeInt(lb=2, ub=5)], ev=None, er=[])
|
||||
|
||||
#-----< Set01 >-----#
|
||||
Set01 = SET(name=u'Set01', mode=MODE_TYPE)
|
||||
_Set01_boo = BOOL(name=u'boo', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
_Set01_int = INT(name=u'int', mode=MODE_TYPE, tag=(64, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int04')), default=10)
|
||||
_Set01_cho = CHOICE(name=u'cho', mode=MODE_TYPE)
|
||||
__Set01_cho_boo = BOOL(name=u'boo', mode=MODE_TYPE, tag=(0, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
__Set01_cho_int = INT(name=u'int', mode=MODE_TYPE, tag=(1, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int04')))
|
||||
__Set01_cho_enu = ENUM(name=u'enu', mode=MODE_TYPE, tag=(2, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')))
|
||||
Set01 = SET(name='Set01', mode=MODE_TYPE)
|
||||
_Set01_boo = BOOL(name='boo', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
_Set01_int = INT(name='int', mode=MODE_TYPE, tag=(64, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int04')), default=10)
|
||||
_Set01_cho = CHOICE(name='cho', mode=MODE_TYPE)
|
||||
__Set01_cho_boo = BOOL(name='boo', mode=MODE_TYPE, tag=(0, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Boo01')))
|
||||
__Set01_cho_int = INT(name='int', mode=MODE_TYPE, tag=(1, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Int04')))
|
||||
__Set01_cho_enu = ENUM(name='enu', mode=MODE_TYPE, tag=(2, TAG_CONTEXT_SPEC, TAG_IMPLICIT), typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')))
|
||||
_Set01_cho._cont = ASN1Dict([
|
||||
(u'boo', __Set01_cho_boo),
|
||||
(u'int', __Set01_cho_int),
|
||||
(u'enu', __Set01_cho_enu),
|
||||
('boo', __Set01_cho_boo),
|
||||
('int', __Set01_cho_int),
|
||||
('enu', __Set01_cho_enu),
|
||||
])
|
||||
_Set01_cho._ext = None
|
||||
_Set01_enu = ENUM(name=u'enu', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')), opt=True)
|
||||
_Set01_bst = BIT_STR(name=u'bst', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Bst01')), group=0)
|
||||
_Set01_ost = OCT_STR(name=u'ost', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Ost02')), group=0)
|
||||
_Set01_enu = ENUM(name='enu', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Enu01')), opt=True)
|
||||
_Set01_bst = BIT_STR(name='bst', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Bst01')), group=0)
|
||||
_Set01_ost = OCT_STR(name='ost', mode=MODE_TYPE, typeref=ASN1RefType(('Test-Asn1rt', 'Ost02')), group=0)
|
||||
Set01._cont = ASN1Dict([
|
||||
(u'boo', _Set01_boo),
|
||||
(u'int', _Set01_int),
|
||||
(u'cho', _Set01_cho),
|
||||
(u'enu', _Set01_enu),
|
||||
(u'bst', _Set01_bst),
|
||||
(u'ost', _Set01_ost),
|
||||
('boo', _Set01_boo),
|
||||
('int', _Set01_int),
|
||||
('cho', _Set01_cho),
|
||||
('enu', _Set01_enu),
|
||||
('bst', _Set01_bst),
|
||||
('ost', _Set01_ost),
|
||||
])
|
||||
Set01._ext = [u'bst', u'ost']
|
||||
Set01._ext = ['bst', 'ost']
|
||||
|
||||
_all_ = [
|
||||
Null,
|
||||
|
@ -425,12 +443,14 @@ class Test_Asn1rt:
|
|||
Bst04,
|
||||
_Bst05_contain,
|
||||
Bst05,
|
||||
Bst06,
|
||||
Ost01,
|
||||
Ost02,
|
||||
Ost03,
|
||||
Ost04,
|
||||
_Ost05_contain,
|
||||
Ost05,
|
||||
Ost06,
|
||||
Nus01,
|
||||
Nus02,
|
||||
Prs01,
|
||||
|
@ -438,6 +458,7 @@ class Test_Asn1rt:
|
|||
Ias01,
|
||||
Ias02,
|
||||
Ias03,
|
||||
Ias04,
|
||||
U8s01,
|
||||
U8s02,
|
||||
U8s03,
|
||||
|
|
Loading…
Reference in New Issue