diff options
author | Alex Stapleton <alexs@prol.etari.at> | 2014-02-05 19:47:00 +0000 |
---|---|---|
committer | Alex Stapleton <alexs@prol.etari.at> | 2014-02-05 19:51:27 +0000 |
commit | 5d17ab3b354fe96e94689ad012163f42cc598a27 (patch) | |
tree | 6a6f64e20e39b78dd3be973ac3d24fdfe15ee643 /tests/hazmat | |
parent | 52026b85c3df15476d38f308cee59a29a9b43195 (diff) | |
download | cryptography-5d17ab3b354fe96e94689ad012163f42cc598a27.tar.gz cryptography-5d17ab3b354fe96e94689ad012163f42cc598a27.tar.bz2 cryptography-5d17ab3b354fe96e94689ad012163f42cc598a27.zip |
Sanity check keys.
Taken from RFC 3447.
Diffstat (limited to 'tests/hazmat')
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index e50417b8..c725c5f0 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -50,9 +50,43 @@ class TestRSA(object): assert skey.key_size == pkey.key_size assert skey.key_size == pkey2.key_size - def test_invalid_arguments(self): + def test_invalid_argument_types(self): with pytest.raises(TypeError): rsa.RSAPrivateKey(None, None, None, None, None) with pytest.raises(TypeError): rsa.RSAPublicKey(None, None) + + def test_invalid_argument_values(self): + # tiny example key + rsa.RSAPrivateKey(3, 5, 14, 8, 15) + + # modulus too small + with pytest.raises(ValueError): + rsa.RSAPrivateKey(3, 5, 14, 8, 2) + + # private exp too high + with pytest.raises(ValueError): + rsa.RSAPrivateKey(3, 5, 16, 8, 15) + + # public exp too low + with pytest.raises(ValueError): + rsa.RSAPrivateKey(3, 5, 14, 2, 15) + + # public exp too high + with pytest.raises(ValueError): + rsa.RSAPrivateKey(3, 5, 14, 16, 15) + + rsa.RSAPublicKey(8, 15) + + # modulus too small + with pytest.raises(ValueError): + rsa.RSAPublicKey(8, 2) + + # public exp too low + with pytest.raises(ValueError): + rsa.RSAPublicKey(2, 15) + + # public exp too high + with pytest.raises(ValueError): + rsa.RSAPublicKey(16, 15) |