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 /pyasn1/codec | |
parent | 66d329acaaf204eff63ae595fd7d6f56cd530c72 (diff) | |
download | pyasn1-git-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 'pyasn1/codec')
-rw-r--r-- | pyasn1/codec/ber/decoder.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py index 2e4afbb..8c556fc 100644 --- a/pyasn1/codec/ber/decoder.py +++ b/pyasn1/codec/ber/decoder.py @@ -1016,7 +1016,16 @@ class AnyDecoder(AbstractSimpleDecoder): tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): - if asn1Spec is None or asn1Spec is not None and tagSet != asn1Spec.tagSet: + if asn1Spec is None: + isUntagged = True + + elif asn1Spec.__class__ is tagmap.TagMap: + isUntagged = tagSet not in asn1Spec.tagMap + + else: + isUntagged = tagSet != asn1Spec.tagSet + + if isUntagged: fullSubstrate = options['fullSubstrate'] # untagged Any container, recover inner header substrate @@ -1038,7 +1047,16 @@ class AnyDecoder(AbstractSimpleDecoder): tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): - if asn1Spec is not None and tagSet == asn1Spec.tagSet: + if asn1Spec is None: + isTagged = False + + elif asn1Spec.__class__ is tagmap.TagMap: + isTagged = tagSet in asn1Spec.tagMap + + else: + isTagged = tagSet == asn1Spec.tagSet + + if isTagged: # tagged Any type -- consume header substrate header = null @@ -1208,7 +1226,7 @@ for typeDecoder in tagMap.values(): class Decoder(object): defaultErrorState = stErrorCondition - # defaultErrorState = stDumpRawValue + #defaultErrorState = stDumpRawValue defaultRawDecoder = AnyDecoder() supportIndefLength = True @@ -1509,7 +1527,9 @@ class Decoder(object): break if state is stTryAsExplicitTag: - if tagSet and tagSet[0].tagFormat == tag.tagFormatConstructed and tagSet[0].tagClass != tag.tagClassUniversal: + if (tagSet and + tagSet[0].tagFormat == tag.tagFormatConstructed and + tagSet[0].tagClass != tag.tagClassUniversal): # Assume explicit tagging concreteDecoder = explicitTagDecoder state = stDecodeValue |