X-Git-Url: http://www.git.cypherpunks.ru/?p=pyderasn.git;a=blobdiff_plain;f=pyderasn.py;h=3cbe67ddd1fbc7386f1df1556f700a54a360c242;hp=6e772e09b5870c743b5c9228d3027a8d1cef35bf;hb=d8f05bb5f06096c6e061c82d40aeb9f43bbb1a21;hpb=038b5d9eab3e5dc2a203f064f22caa854f5b68ae diff --git a/pyderasn.py b/pyderasn.py index 6e772e0..3cbe67d 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -850,6 +850,7 @@ class Obj(object): "llen", "vlen", "bered", + "expl_bered", ) def __init__( @@ -872,6 +873,7 @@ class Obj(object): self.offset, self.llen, self.vlen = _decoded self.default = None self.bered = False + self.expl_bered = False @property def ready(self): # pragma: no cover @@ -982,6 +984,35 @@ class Obj(object): ) try: l, llen, v = len_decode(lv) + except LenIndefiniteForm as err: + if not ctx.get("bered", False): + raise err.__class__( + msg=err.msg, + klass=self.__class__, + decode_path=decode_path, + offset=offset, + ) + llen, v = 1, lv[1:] + offset += tlen + llen + result = self._decode( + v, + offset=offset, + decode_path=decode_path, + ctx=ctx, + tag_only=tag_only, + ) + if tag_only: + return + obj, tail = result + eoc_expected, tail = tail[:EOC_LEN], tail[EOC_LEN:] + if eoc_expected.tobytes() != EOC: + raise DecodeError( + msg="no EOC", + decode_path=decode_path, + offset=offset, + ) + obj.vlen += EOC_LEN + obj.expl_bered = True except DecodeError as err: raise err.__class__( msg=err.msg, @@ -989,23 +1020,24 @@ class Obj(object): decode_path=decode_path, offset=offset, ) - if l > len(v): - raise NotEnoughData( - "encoded length is longer than data", - klass=self.__class__, + else: + if l > len(v): + raise NotEnoughData( + "encoded length is longer than data", + klass=self.__class__, + decode_path=decode_path, + offset=offset, + ) + result = self._decode( + v, + offset=offset + tlen + llen, decode_path=decode_path, - offset=offset, + ctx=ctx, + tag_only=tag_only, ) - result = self._decode( - v, - offset=offset + tlen + llen, - decode_path=decode_path, - ctx=ctx, - tag_only=tag_only, - ) - if tag_only: - return - obj, tail = result + if tag_only: + return + obj, tail = result return obj, (tail if leavemm else tail.tobytes()) @property @@ -1022,6 +1054,8 @@ class Obj(object): @property def expl_llen(self): + if self.expl_bered: + return 1 return len(len_encode(self.tlvlen)) @property