diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-11-23 19:48:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 19:48:19 +0100 |
commit | df3a2b7781c72ffc703e80d788618d93634e17ab (patch) | |
tree | 92e0a55875a84c9e1e115d84e7001c55f6e2fb6d /pyasn1 | |
parent | 136890e0482020375cdc6cde03da7ebaf4e937c6 (diff) | |
download | pyasn1-df3a2b7781c72ffc703e80d788618d93634e17ab.tar.gz |
Fixed bad TagSet initializer at OctetString encoder (#107)
localize explicit tag slitting to chunked mode at OctetString and BitString encoders
The inner chunks tagging logic is to be researched -- I'm not certain it works as it supposed to
Diffstat (limited to 'pyasn1')
-rw-r--r-- | pyasn1/__init__.py | 2 | ||||
-rw-r--r-- | pyasn1/codec/ber/encoder.py | 57 |
2 files changed, 43 insertions, 16 deletions
diff --git a/pyasn1/__init__.py b/pyasn1/__init__.py index 42f4704..1e99d6b 100644 --- a/pyasn1/__init__.py +++ b/pyasn1/__init__.py @@ -1,7 +1,7 @@ import sys # http://www.python.org/dev/peps/pep-0396/ -__version__ = '0.4.1' +__version__ = '0.4.2' if sys.version_info[:2] < (2, 4): raise RuntimeError('PyASN1 requires Python 2.4 or later') diff --git a/pyasn1/codec/ber/encoder.py b/pyasn1/codec/ber/encoder.py index 1f6c11c..28c5071 100644 --- a/pyasn1/codec/ber/encoder.py +++ b/pyasn1/codec/ber/encoder.py @@ -157,12 +157,15 @@ class BitStringEncoder(AbstractItemEncoder): substrate = alignedValue.asOctets() return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True - tagSet = value.tagSet + baseTag = value.tagSet.baseTag # strip off explicit tags - alignedValue = alignedValue.clone( - tagSet=tag.TagSet(tagSet.baseTag, tagSet.baseTag) - ) + if baseTag: + tagSet = tag.TagSet(baseTag, baseTag) + else: + tagSet = tag.TagSet() + + alignedValue = alignedValue.clone(tagSet=tagSet) stop = 0 substrate = null @@ -175,28 +178,52 @@ class BitStringEncoder(AbstractItemEncoder): class OctetStringEncoder(AbstractItemEncoder): + def encodeValue(self, value, asn1Spec, encodeFun, **options): - if asn1Spec is None: - # will strip off explicit tags - tagSet = value.tagSet - asn1Spec = value.clone(tagSet=tag.TagSet(tagSet.baseTag, tagSet.baseTag)) - value = value.asOctets() + if asn1Spec is None: + substrate = value.asOctets() elif not isOctetsType(value): - # will strip off explicit tags - tagSet = asn1Spec.tagSet - asn1Spec = asn1Spec.clone(tagSet=tag.TagSet(tagSet.baseTag, tagSet.baseTag)) + substrate = asn1Spec.clone(value).asOctets() - value = asn1Spec.clone(value).asOctets() + else: + substrate = value maxChunkSize = options.get('maxChunkSize', 0) - if not maxChunkSize or len(value) <= maxChunkSize: - return value, False, True + + if not maxChunkSize or len(substrate) <= maxChunkSize: + return substrate, False, True else: + + # strip off explicit tags for inner chunks + + if asn1Spec is None: + baseTag = value.tagSet.baseTag + + # strip off explicit tags + if baseTag: + tagSet = tag.TagSet(baseTag, baseTag) + else: + tagSet = tag.TagSet() + + asn1Spec = value.clone(tagSet=tagSet) + + elif not isOctetsType(value): + baseTag = asn1Spec.tagSet.baseTag + + # strip off explicit tags + if baseTag: + tagSet = tag.TagSet(baseTag, baseTag) + else: + tagSet = tag.TagSet() + + asn1Spec = asn1Spec.clone(tagSet=tagSet) + pos = 0 substrate = null + while True: chunk = value[pos:pos + maxChunkSize] if not chunk: |