diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-06-28 22:48:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-28 22:48:40 +0200 |
commit | adf4c5b1ef11026102dad0bb77b54576e0ebd71c (patch) | |
tree | cc1891f2893b0ddd2dda337eabceeacecbdbb3a9 /tests | |
parent | 66d329acaaf204eff63ae595fd7d6f56cd530c72 (diff) | |
download | pyasn1-adf4c5b1ef11026102dad0bb77b54576e0ebd71c.tar.gz |
Fix `AnyDecoder` to accept `TagMap` as `asn1Spec` (#152)
Fixes `AnyDecoder` to accept `TagMap` as `asn1Spec`.
The use-case is to make `AnyDecoder` operational when
dumping raw value on error condition is enabled
Diffstat (limited to 'tests')
-rw-r--r-- | tests/codec/ber/test_decoder.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py index 8b6d590..bff246e 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/test_decoder.py @@ -1429,6 +1429,38 @@ class NonStringDecoderTestCase(BaseTestCase): assert self.s == s +class ErrorOnDecodingTestCase(BaseTestCase): + + def testErrorCondition(self): + decode = decoder.Decoder(decoder.tagMap, decoder.typeMap) + + try: + asn1Object, rest = decode(str2octs('abc')) + + except PyAsn1Error: + exc = sys.exc_info()[1] + assert (isinstance(exc, PyAsn1Error), + 'Unexpected exception raised %r' % (exc,)) + + else: + assert False, 'Unexpected decoder result %r' % (asn1Object,) + + def testRawDump(self): + decode = decoder.Decoder(decoder.tagMap, decoder.typeMap) + + decode.defaultErrorState = decoder.stDumpRawValue + + asn1Object, rest = decode(ints2octs( + (31, 8, 2, 1, 1, 131, 3, 2, 1, 12))) + + assert (isinstance(asn1Object, univ.Any), + 'Unexpected raw dump type %r' % (asn1Object,)) + assert (asn1Object.asNumbers() == (31, 8, 2, 1, 1), + 'Unexpected raw dump value %r' % (asn1Object,)) + assert (rest == ints2octs((131, 3, 2, 1, 12)), + 'Unexpected rest of substrate after raw dump %r' % rest) + + suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) if __name__ == '__main__': |