diff options
author | Jan Pipek <jan.pipek@gmail.com> | 2019-09-10 13:15:03 +0200 |
---|---|---|
committer | Jan Pipek <jan.pipek@gmail.com> | 2019-09-10 13:15:03 +0200 |
commit | 6e0186a0979acd07f8e29ebc0867fec7710d118a (patch) | |
tree | 41b2f6e84f4fd8c47cf515aa44a5cb664f987929 | |
parent | 545b1b42cefab351e37c769e79d7516e5935cd9b (diff) | |
download | pyasn1-git-6e0186a0979acd07f8e29ebc0867fec7710d118a.tar.gz |
UnsupportedSubstrateError
-rw-r--r-- | pyasn1/codec/ber/decoder.py | 13 | ||||
-rw-r--r-- | pyasn1/error.py | 4 |
2 files changed, 12 insertions, 5 deletions
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py index 62f5616..df4e049 100644 --- a/pyasn1/codec/ber/decoder.py +++ b/pyasn1/codec/ber/decoder.py @@ -13,7 +13,7 @@ from pyasn1 import error from pyasn1.codec.ber import eoo from pyasn1.compat.integer import from_bytes from pyasn1.compat.octets import oct2int, octs2ints, ints2octs, null -from pyasn1.error import PyAsn1Error +from pyasn1.error import PyAsn1Error, UnsupportedSubstrateError from pyasn1.type import base from pyasn1.type import char from pyasn1.type import tag @@ -50,9 +50,9 @@ def asSeekableStream(substrate): return substrate else: # TODO: Implement for non-seekable streams - raise NotImplementedError("Cannot use non-seekable bit stream: " + substrate.__class__.__name__) - except AttributeError as f: - raise TypeError("Cannot convert " + substrate.__class__.__name__ + " to a seekable bit stream.") + raise UnsupportedSubstrateError("Cannot use non-seekable bit stream: " + substrate.__class__.__name__) + except AttributeError: + raise UnsupportedSubstrateError("Cannot convert " + substrate.__class__.__name__ + " to a seekable bit stream.") def endOfStream(substrate): @@ -1668,7 +1668,10 @@ _decode = Decoder(tagMap, typeMap) def decodeStream(substrate, asn1Spec=None, **kwargs): """Iterator of objects in a substrate.""" # TODO: This should become `decode` after API-breaking approved - substrate = asSeekableStream(substrate) + try: + substrate = asSeekableStream(substrate) + except TypeError: + raise PyAsn1Error while True: result = _decode(substrate, asn1Spec, **kwargs) if result is None: diff --git a/pyasn1/error.py b/pyasn1/error.py index 4f48db2..85a31ff 100644 --- a/pyasn1/error.py +++ b/pyasn1/error.py @@ -34,6 +34,10 @@ class SubstrateUnderrunError(PyAsn1Error): """ +class UnsupportedSubstrateError(PyAsn1Error): + """Unsupported substrate type to parse as ASN.1 data.""" + + class PyAsn1UnicodeError(PyAsn1Error, UnicodeError): """Unicode text processing error |