"offset",
"llen",
"vlen",
+ "lenindef",
+ "expl_lenindef",
"bered",
- "expl_bered",
)
def __init__(
self.optional = optional
self.offset, self.llen, self.vlen = _decoded
self.default = None
+ self.lenindef = False
+ self.expl_lenindef = False
self.bered = False
- self.expl_bered = False
@property
def ready(self): # pragma: no cover
offset=offset,
)
obj.vlen += EOC_LEN
- obj.expl_bered = True
+ obj.expl_lenindef = True
except DecodeError as err:
raise err.__class__(
msg=err.msg,
@property
def expl_llen(self):
- if self.expl_bered:
+ if self.expl_lenindef:
return 1
return len(len_encode(self.tlvlen))
)
if tag_only:
return
- eoc_expected = False
+ lenindef = False
try:
l, llen, v = len_decode(lv)
except LenIndefiniteForm:
llen, l, v = 1, 0, lv[1:]
- eoc_expected = True
+ lenindef = True
except DecodeError as err:
raise err.__class__(
msg=err.msg,
decode_path=decode_path,
offset=offset,
)
- if not eoc_expected and l == 0:
+ if not lenindef and l == 0:
raise NotEnoughData(
"zero length",
klass=self.__class__,
sub_offset = offset + tlen + llen
vlen = 0
while True:
- if eoc_expected:
+ if lenindef:
if v[:EOC_LEN].tobytes() == EOC:
break
else:
default=self.default,
optional=self.optional,
_specs=self.specs,
- _decoded=(offset, llen, vlen + (EOC_LEN if eoc_expected else 0)),
+ _decoded=(offset, llen, vlen + (EOC_LEN if lenindef else 0)),
)
+ obj.lenindef = lenindef
obj.bered = True
- return obj, v[EOC_LEN if eoc_expected else 0:]
+ return obj, (v[EOC_LEN:] if lenindef else v)
raise TagMismatch(
klass=self.__class__,
decode_path=decode_path,
)
if tag_only:
return
- eoc_expected = False
+ lenindef = False
try:
l, llen, v = len_decode(lv)
except LenIndefiniteForm:
llen, l, v = 1, 0, lv[1:]
- eoc_expected = True
+ lenindef = True
except DecodeError as err:
raise err.__class__(
msg=err.msg,
decode_path=decode_path,
offset=offset,
)
- if not eoc_expected and l == 0:
+ if not lenindef and l == 0:
raise NotEnoughData(
"zero length",
klass=self.__class__,
sub_offset = offset + tlen + llen
vlen = 0
while True:
- if eoc_expected:
+ if lenindef:
if v[:EOC_LEN].tobytes() == EOC:
break
else:
expl=self._expl,
default=self.default,
optional=self.optional,
- _decoded=(offset, llen, vlen + (EOC_LEN if eoc_expected else 0)),
+ _decoded=(offset, llen, vlen + (EOC_LEN if lenindef else 0)),
)
except DecodeError as err:
raise DecodeError(
decode_path=decode_path,
offset=offset,
)
+ obj.lenindef = lenindef
obj.bered = True
- return obj, v[EOC_LEN if eoc_expected else 0:]
+ return obj, (v[EOC_LEN:] if lenindef else v)
raise TagMismatch(
klass=self.__class__,
decode_path=decode_path,
optional=self.optional,
_decoded=(offset, 0, tlvlen),
)
- obj.bered = True
+ obj.lenindef = True
obj.tag = t
return obj, v[EOC_LEN:]
else:
)
if tag_only:
return
- eoc_expected = False
+ lenindef = False
try:
l, llen, v = len_decode(lv)
except LenIndefiniteForm as err:
offset=offset,
)
l, llen, v = 0, 1, lv[1:]
- eoc_expected = True
+ lenindef = True
except DecodeError as err:
raise err.__class__(
msg=err.msg,
decode_path=decode_path,
offset=offset,
)
- if not eoc_expected:
+ if not lenindef:
v, tail = v[:l], v[l:]
vlen = 0
sub_offset = offset + tlen + llen
values = {}
for name, spec in self.specs.items():
if spec.optional and (
- (eoc_expected and v[:EOC_LEN].tobytes() == EOC) or
+ (lenindef and v[:EOC_LEN].tobytes() == EOC) or
len(v) == 0
):
continue
abs_decode_path(sub_decode_path[:-1], rel_path),
(value, defined),
))
- if eoc_expected:
+ if lenindef:
if v[:EOC_LEN].tobytes() != EOC:
raise DecodeError(
"no EOC",
_decoded=(offset, llen, vlen),
)
obj._value = values
- if eoc_expected:
- obj.bered = True
+ obj.lenindef = lenindef
return obj, tail
def __repr__(self):
)
if tag_only:
return
- eoc_expected = False
+ lenindef = False
try:
l, llen, v = len_decode(lv)
except LenIndefiniteForm as err:
offset=offset,
)
l, llen, v = 0, 1, lv[1:]
- eoc_expected = True
+ lenindef = True
except DecodeError as err:
raise err.__class__(
msg=err.msg,
klass=self.__class__,
offset=offset,
)
- if not eoc_expected:
+ if not lenindef:
v, tail = v[:l], v[l:]
vlen = 0
sub_offset = offset + tlen + llen
values = {}
specs_items = self.specs.items
while len(v) > 0:
- if eoc_expected and v[:EOC_LEN].tobytes() == EOC:
+ if lenindef and v[:EOC_LEN].tobytes() == EOC:
break
for name, spec in specs_items():
sub_decode_path = decode_path + (name,)
expl=self._expl,
default=self.default,
optional=self.optional,
- _decoded=(offset, llen, vlen + (EOC_LEN if eoc_expected else 0)),
+ _decoded=(offset, llen, vlen + (EOC_LEN if lenindef else 0)),
)
obj._value = values
if not obj.ready:
decode_path=decode_path,
offset=offset,
)
- if eoc_expected:
- obj.bered = True
- tail = v[EOC_LEN:]
- return obj, tail
+ obj.lenindef = lenindef
+ return obj, (v[EOC_LEN:] if lenindef else tail)
class SequenceOf(Obj):
)
if tag_only:
return
- eoc_expected = False
+ lenindef = False
try:
l, llen, v = len_decode(lv)
except LenIndefiniteForm as err:
offset=offset,
)
l, llen, v = 0, 1, lv[1:]
- eoc_expected = True
+ lenindef = True
except DecodeError as err:
raise err.__class__(
msg=err.msg,
decode_path=decode_path,
offset=offset,
)
- if not eoc_expected:
+ if not lenindef:
v, tail = v[:l], v[l:]
vlen = 0
sub_offset = offset + tlen + llen
_value = []
spec = self.spec
while len(v) > 0:
- if eoc_expected and v[:EOC_LEN].tobytes() == EOC:
+ if lenindef and v[:EOC_LEN].tobytes() == EOC:
break
value, v_tail = spec.decode(
v,
optional=self.optional,
_decoded=(offset, llen, vlen),
)
- if eoc_expected:
- obj.bered = True
- tail = v[EOC_LEN:]
- return obj, tail
+ obj.lenindef = lenindef
+ return obj, (v[EOC_LEN:] if lenindef else tail)
def __repr__(self):
return "%s[%s]" % (