Skip to content
Snippets Groups Projects
Commit 387c4d4aa766 authored by Ilya Etingof's avatar Ilya Etingof
Browse files

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
parent 94668bee478b
No related branches found
No related tags found
No related merge requests found
Revision 0.4.2, released 23-11-2017
-----------------------------------
- Fixed explicit tag splitting in chunked encoding mode at
OctetString and BitString encoders
Revision 0.4.1, released 23-11-2017
-----------------------------------
......
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')
......@@ -157,6 +157,6 @@
substrate = alignedValue.asOctets()
return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True
tagSet = value.tagSet
baseTag = value.tagSet.baseTag
# strip off explicit tags
......@@ -161,8 +161,11 @@
# 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,4 +178,5 @@
class OctetStringEncoder(AbstractItemEncoder):
def encodeValue(self, value, asn1Spec, encodeFun, **options):
......@@ -178,2 +182,3 @@
def encodeValue(self, value, asn1Spec, encodeFun, **options):
if asn1Spec is None:
......@@ -179,8 +184,4 @@
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()
substrate = value.asOctets()
elif not isOctetsType(value):
......@@ -185,6 +186,4 @@
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()
......@@ -190,4 +189,5 @@
value = asn1Spec.clone(value).asOctets()
else:
substrate = value
maxChunkSize = options.get('maxChunkSize', 0)
......@@ -192,6 +192,7 @@
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:
......@@ -196,4 +197,29 @@
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
......@@ -198,5 +224,6 @@
pos = 0
substrate = null
while True:
chunk = value[pos:pos + maxChunkSize]
if not chunk:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment