aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-07 13:52:39 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-07 13:52:39 -0600
commit6a4342c18ca0507f3d1842591553bddac6eb9189 (patch)
tree0d67b35340056438aef3e79484d338b1c3fd4ad2
parenta43964a0e90d7788b81521c9e7b949cdc2b555a0 (diff)
downloadcryptography-6a4342c18ca0507f3d1842591553bddac6eb9189.tar.gz
cryptography-6a4342c18ca0507f3d1842591553bddac6eb9189.tar.bz2
cryptography-6a4342c18ca0507f3d1842591553bddac6eb9189.zip
directly test r, s for integer-ness
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/utils.py14
-rw-r--r--tests/hazmat/primitives/test_asym_utils.py1
2 files changed, 10 insertions, 5 deletions
diff --git a/src/cryptography/hazmat/primitives/asymmetric/utils.py b/src/cryptography/hazmat/primitives/asymmetric/utils.py
index cf5973a0..71f4ff8e 100644
--- a/src/cryptography/hazmat/primitives/asymmetric/utils.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/utils.py
@@ -8,6 +8,8 @@ from pyasn1.codec.der import decoder, encoder
from pyasn1.error import PyAsn1Error
from pyasn1.type import namedtype, univ
+import six
+
class _DSSSigValue(univ.Sequence):
componentType = namedtype.NamedTypes(
@@ -32,11 +34,13 @@ def decode_rfc6979_signature(signature):
def encode_rfc6979_signature(r, s):
- try:
- sig = _DSSSigValue()
- sig.setComponentByName('r', r)
- sig.setComponentByName('s', s)
- except PyAsn1Error:
+ if (
+ not isinstance(r, six.integer_types) or
+ not isinstance(s, six.integer_types)
+ ):
raise ValueError("Both r and s must be integers")
+ sig = _DSSSigValue()
+ sig.setComponentByName('r', r)
+ sig.setComponentByName('s', s)
return encoder.encode(sig)
diff --git a/tests/hazmat/primitives/test_asym_utils.py b/tests/hazmat/primitives/test_asym_utils.py
index 3598f78a..9403669c 100644
--- a/tests/hazmat/primitives/test_asym_utils.py
+++ b/tests/hazmat/primitives/test_asym_utils.py
@@ -39,6 +39,7 @@ def test_rfc6979_signature():
def test_encode_rfc6979_non_integer():
with pytest.raises(ValueError):
encode_rfc6979_signature("h", 3)
+ encode_rfc6979_signature("3", "2")
encode_rfc6979_signature(3, "h")
encode_rfc6979_signature(3.3, 1.2)
encode_rfc6979_signature("hello", "world")