From 6a4342c18ca0507f3d1842591553bddac6eb9189 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 7 Dec 2014 13:52:39 -0600 Subject: directly test r, s for integer-ness --- src/cryptography/hazmat/primitives/asymmetric/utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') 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) -- cgit v1.2.3