diff options
Diffstat (limited to 'tests/hazmat/primitives/test_rsa.py')
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index ea72f916..ba668bff 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -1664,3 +1664,117 @@ class TestRSAEncryption(object): ), backend ) + + +class TestRSANumbers(object): + def test_rsa_public_numbers(self): + public_numbers = rsa.RSAPublicNumbers(e=1, n=15) + assert public_numbers.e == 1 + assert public_numbers.n == 15 + + def test_rsa_private_numbers(self): + public_numbers = rsa.RSAPublicNumbers(e=1, n=15) + private_numbers = rsa.RSAPrivateNumbers( + p=3, + q=5, + d=1, + dmp1=1, + dmq1=1, + iqmp=2, + public_numbers=public_numbers + ) + + assert private_numbers.p == 3 + assert private_numbers.q == 5 + assert private_numbers.d == 1 + assert private_numbers.dmp1 == 1 + assert private_numbers.dmq1 == 1 + assert private_numbers.iqmp == 2 + assert private_numbers.public_numbers == public_numbers + + def test_public_numbers_invalid_types(self): + with pytest.raises(TypeError): + rsa.RSAPublicNumbers(e=None, n=15) + + with pytest.raises(TypeError): + rsa.RSAPublicNumbers(e=1, n=None) + + def test_private_numbers_invalid_types(self): + public_numbers = rsa.RSAPublicNumbers(e=1, n=15) + + with pytest.raises(TypeError): + rsa.RSAPrivateNumbers( + p=None, + q=5, + d=1, + dmp1=1, + dmq1=1, + iqmp=2, + public_numbers=public_numbers + ) + + with pytest.raises(TypeError): + rsa.RSAPrivateNumbers( + p=3, + q=None, + d=1, + dmp1=1, + dmq1=1, + iqmp=2, + public_numbers=public_numbers + ) + + with pytest.raises(TypeError): + rsa.RSAPrivateNumbers( + p=3, + q=5, + d=None, + dmp1=1, + dmq1=1, + iqmp=2, + public_numbers=public_numbers + ) + + with pytest.raises(TypeError): + rsa.RSAPrivateNumbers( + p=3, + q=5, + d=1, + dmp1=None, + dmq1=1, + iqmp=2, + public_numbers=public_numbers + ) + + with pytest.raises(TypeError): + rsa.RSAPrivateNumbers( + p=3, + q=5, + d=1, + dmp1=1, + dmq1=None, + iqmp=2, + public_numbers=public_numbers + ) + + with pytest.raises(TypeError): + rsa.RSAPrivateNumbers( + p=3, + q=5, + d=1, + dmp1=1, + dmq1=1, + iqmp=None, + public_numbers=public_numbers + ) + + with pytest.raises(TypeError): + rsa.RSAPrivateNumbers( + p=3, + q=5, + d=1, + dmp1=1, + dmq1=1, + iqmp=2, + public_numbers=None + ) |