Beispiel #1
0
 def do_dec(
         cls,
         s,  # type: bytes
         context=None,  # type: Optional[Type[ASN1_Class]]
         safe=False  # type: bool
 ):
     # type: (...) -> Tuple[ASN1_Object[Any], bytes]
     if context is not None:
         _context = context
     else:
         _context = cls.tag.context
     cls.check_string(s)
     p, remainder = BER_id_dec(s)
     if p not in _context:  # type: ignore
         t = s
         if len(t) > 18:
             t = t[:15] + b"..."
         raise BER_Decoding_Error("Unknown prefix [%02x] for [%r]" % (p, t),
                                  remaining=s)
     tag = _context[p]  # type: ignore
     codec = cast('Type[BERcodec_Object[_K]]',
                  tag.get_codec(ASN1_Codecs.BER))
     if codec == BERcodec_Object:
         # Value type defined as Unknown
         l, s = BER_num_dec(remainder)
         return ASN1_BADTAG(s[:l]), s[l:]
     return codec.dec(s, _context, safe)
Beispiel #2
0
 def dec(cls, s, context=None, safe=False):
     if not safe:
         return cls.do_dec(s, context, safe)
     try:
         return cls.do_dec(s, context, safe)
     except BER_BadTag_Decoding_Error, e:
         o, remain = BERcodec_Object.dec(e.remaining, context, safe)
         return ASN1_BADTAG(o), remain
Beispiel #3
0
 def dec(cls, s, context=None, safe=False):
     if not safe:
         return cls.do_dec(s, context, safe)
     try:
         return cls.do_dec(s, context, safe)
     except BER_BadTag_Decoding_Error as e:
         o, remain = BERcodec_Object.dec(e.remaining, context, safe)
         return ASN1_BADTAG(o), remain
     except BER_Decoding_Error as e:
         return ASN1_DECODING_ERROR(s, exc=e), ""
     except ASN1_Error as e:
         return ASN1_DECODING_ERROR(s, exc=e), ""
Beispiel #4
0
 def do_dec(cls, s, context=None, safe=False):
     if context is None:
         context = cls.tag.context
     cls.check_string(s)
     p, remainder = BER_id_dec(s)
     if p not in context:
         t = s
         if len(t) > 18:
             t = t[:15] + b"..."
         raise BER_Decoding_Error("Unknown prefix [%02x] for [%r]" %
                                  (p, t), remaining=s)
     codec = context[p].get_codec(ASN1_Codecs.BER)
     if codec == BERcodec_Object:
         # Value type defined as Unknown
         l, s = BER_num_dec(remainder)
         return ASN1_BADTAG(s[:l]), s[l:]
     return codec.dec(s, context, safe)
Beispiel #5
0
 def dec(cls,
         s,  # type: bytes
         context=None,  # type: Optional[Type[ASN1_Class]]
         safe=False,  # type: bool
         ):
     # type: (...) -> Tuple[Union[_ASN1_ERROR, ASN1_Object[_K]], bytes]
     if not safe:
         return cls.do_dec(s, context, safe)
     try:
         return cls.do_dec(s, context, safe)
     except BER_BadTag_Decoding_Error as e:
         o, remain = BERcodec_Object.dec(
             e.remaining, context, safe
         )  # type: Tuple[ASN1_Object[Any], bytes]
         return ASN1_BADTAG(o), remain
     except BER_Decoding_Error as e:
         return ASN1_DECODING_ERROR(s, exc=e), b""
     except ASN1_Error as e:
         return ASN1_DECODING_ERROR(s, exc=e), b""