Skip to content

Commit

Permalink
Fix. Decode Unsigned Values as Unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
Глазов Николай committed Sep 20, 2022
1 parent db8f1a7 commit 58a4e99
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pyasn1/codec/ber/decoder.py
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

0 comments on commit 58a4e99

Please sign in to comment.