Skip to content
Open
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
12 changes: 10 additions & 2 deletions pyasn1/codec/ber/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pyasn1.error import PyAsn1Error
from pyasn1.type import base
from pyasn1.type import char
from pyasn1.type import constraint
from pyasn1.type import tag
from pyasn1.type import tagmap
from pyasn1.type import univ
Expand Down Expand Up @@ -132,6 +133,14 @@ def valueDecoder(self, substrate, asn1Spec,
decodeFun=None, substrateFun=None,
**options):

def get_spec_signed(spec):
map_constraint = spec.getSubtypeSpec().getValueMap()
if len(map_constraint) == 1:
constr = next(iter(map_constraint))
if isinstance(constr, constraint.ValueRangeConstraint) and constr.start == 0:
return False
return True

if tagSet[0].tagFormat != tag.tagFormatSimple:
raise error.PyAsn1Error('Simple tag format expected')

Expand All @@ -140,8 +149,7 @@ def valueDecoder(self, substrate, asn1Spec,
yield chunk

if chunk:
value = from_bytes(chunk, signed=True)

value = from_bytes(chunk, signed=get_spec_signed(asn1Spec))
else:
value = 0

Expand Down