aboutsummaryrefslogtreecommitdiff
path: root/asn1crypto
diff options
context:
space:
mode:
authorwbond <will@wbond.net>2019-09-27 19:56:20 -0400
committerwbond <will@wbond.net>2019-09-27 19:58:12 -0400
commit3b330ff4d0fc59bacccc69972f3828286c18c97c (patch)
treef36c922a7973b27ff87659e2c30eff5994e53af7 /asn1crypto
parenta8f3eef200e269eba0a0f2ea79ddbddd05a65d11 (diff)
downloadasn1crypto-3b330ff4d0fc59bacccc69972f3828286c18c97c.tar.gz
Restrict core.IntegerBitString() and core.IntegerOctetString() to positive integers
Diffstat (limited to 'asn1crypto')
-rw-r--r--asn1crypto/core.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/asn1crypto/core.py b/asn1crypto/core.py
index 8389461..881620e 100644
--- a/asn1crypto/core.py
+++ b/asn1crypto/core.py
@@ -2480,12 +2480,21 @@ class IntegerBitString(_IntegerBitString, Constructable, Castable, Primitive):
if not isinstance(value, int_types):
raise TypeError(unwrap(
'''
- %s value must be an integer, not %s
+ %s value must be a positive integer, not %s
''',
type_name(self),
type_name(value)
))
+ if value < 0:
+ raise ValueError(unwrap(
+ '''
+ %s value must be a positive integer, not %d
+ ''',
+ type_name(self),
+ value
+ ))
+
self._native = value
# Set the unused bits to 0
self.contents = b'\x00' + int_to_bytes(value, signed=True)
@@ -2620,12 +2629,21 @@ class IntegerOctetString(Constructable, Castable, Primitive):
if not isinstance(value, int_types):
raise TypeError(unwrap(
'''
- %s value must be an integer, not %s
+ %s value must be a positive integer, not %s
''',
type_name(self),
type_name(value)
))
+ if value < 0:
+ raise ValueError(unwrap(
+ '''
+ %s value must be a positive integer, not %d
+ ''',
+ type_name(self),
+ value
+ ))
+
self._native = value
self.contents = int_to_bytes(value, signed=False, width=self._encoded_width)
self._header = None