summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Pipek <jan.pipek@gmail.com>2019-09-10 13:15:03 +0200
committerIlya Etingof <etingof@gmail.com>2019-11-15 19:31:42 +0100
commit0005c889b2e9b5a33e0109372c31474da610ebfd (patch)
treec248ffb73f08a4f371ef292d8d84ef1ada43cd90
parent5522ba40fd4b0e066cf9415868bfd4aed5508799 (diff)
downloadpyasn1-git-0005c889b2e9b5a33e0109372c31474da610ebfd.tar.gz
UnsupportedSubstrateError
-rw-r--r--pyasn1/codec/ber/decoder.py13
-rw-r--r--pyasn1/error.py4
2 files changed, 12 insertions, 5 deletions
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py
index 06ef683..3c7473c 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):
@@ -1696,7 +1696,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