diff options
| author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-05-29 08:29:45 -0500 | 
|---|---|---|
| committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-05-29 08:29:45 -0500 | 
| commit | 1b4e751292d694d411d806116eca1a2a325b3c5c (patch) | |
| tree | 6bd32e7f21e7a58b074d032f5abfea63ac3e1d70 /cryptography | |
| parent | 2f7f5e9691d8c61e042b4a7e6762c5982984fdca (diff) | |
| download | cryptography-1b4e751292d694d411d806116eca1a2a325b3c5c.tar.gz cryptography-1b4e751292d694d411d806116eca1a2a325b3c5c.tar.bz2 cryptography-1b4e751292d694d411d806116eca1a2a325b3c5c.zip | |
move rsa param verification to shared function
Diffstat (limited to 'cryptography')
| -rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 9 | ||||
| -rw-r--r-- | cryptography/hazmat/primitives/asymmetric/rsa.py | 21 | 
2 files changed, 13 insertions, 17 deletions
| diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index 8d76160d..9387c933 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -355,14 +355,7 @@ class Backend(object):              return bn_ptr[0]      def generate_rsa_private_key(self, public_exponent, key_size): -        if public_exponent < 3: -            raise ValueError("public_exponent must be >= 3.") - -        if public_exponent & 1 == 0: -            raise ValueError("public_exponent must be odd.") - -        if key_size < 512: -            raise ValueError("key_size must be at least 512-bits.") +        rsa._verify_rsa_parameters(public_exponent, key_size)          ctx = self._lib.RSA_new()          assert ctx != self._ffi.NULL diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py index e3ad5f1d..9e11c58a 100644 --- a/cryptography/hazmat/primitives/asymmetric/rsa.py +++ b/cryptography/hazmat/primitives/asymmetric/rsa.py @@ -21,6 +21,17 @@ from cryptography.hazmat.backends.interfaces import RSABackend  from cryptography.hazmat.primitives import interfaces +def _verify_rsa_parameters(public_exponent, key_size): +    if public_exponent < 3: +        raise ValueError("public_exponent must be >= 3.") + +    if public_exponent & 1 == 0: +        raise ValueError("public_exponent must be odd.") + +    if key_size < 512: +        raise ValueError("key_size must be at least 512-bits.") + +  @utils.register_interface(interfaces.RSAPublicKey)  class RSAPublicKey(object):      def __init__(self, public_exponent, modulus): @@ -187,15 +198,7 @@ class RSAPrivateKey(object):                  _Reasons.BACKEND_MISSING_INTERFACE              ) -        if public_exponent < 3: -            raise ValueError("public_exponent must be >= 3.") - -        if public_exponent & 1 == 0: -            raise ValueError("public_exponent must be odd.") - -        if key_size < 512: -            raise ValueError("key_size must be at least 512-bits.") - +        _verify_rsa_parameters(public_exponent, key_size)          return backend.generate_rsa_private_key(public_exponent, key_size)      def signer(self, padding, algorithm, backend): | 
