Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bad TagSet initializer at OctetString encoder #107

Merged
merged 4 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

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
-----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pyasn1/__init__.py
Original file line number Diff line number Diff line change
@@ -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')
57 changes: 42 additions & 15 deletions pyasn1/codec/ber/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,15 @@ def encodeValue(self, value, asn1Spec, encodeFun, **options):
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
Expand All @@ -175,28 +178,52 @@ def encodeValue(self, value, asn1Spec, encodeFun, **options):


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:
Expand Down