aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-06-06 21:43:08 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2014-06-06 21:43:08 -0700
commit6df90fb03b8ccb642028ba927fa3490ff71d965a (patch)
tree1839e533a1398f891d0c92f2f02b6b47781cc8c0
parentf1de2f78cfd2b19eb4e2485ff36008581b088292 (diff)
parentb2fa4b7499e9ca70568bdb33eae99a22e9ed2cc6 (diff)
downloadcryptography-6df90fb03b8ccb642028ba927fa3490ff71d965a.tar.gz
cryptography-6df90fb03b8ccb642028ba927fa3490ff71d965a.tar.bz2
cryptography-6df90fb03b8ccb642028ba927fa3490ff71d965a.zip
Merge pull request #1103 from reaperhulk/fix-1097
add load_rsa_*_numbers functions
-rw-r--r--cryptography/hazmat/primitives/serialization.py8
-rw-r--r--docs/hazmat/primitives/asymmetric/serialization.rst38
-rw-r--r--tests/hazmat/primitives/test_serialization.py32
3 files changed, 77 insertions, 1 deletions
diff --git a/cryptography/hazmat/primitives/serialization.py b/cryptography/hazmat/primitives/serialization.py
index ed73c4c4..056d4a06 100644
--- a/cryptography/hazmat/primitives/serialization.py
+++ b/cryptography/hazmat/primitives/serialization.py
@@ -24,3 +24,11 @@ def load_pem_pkcs8_private_key(data, password, backend):
return backend.load_pkcs8_pem_private_key(
data, password
)
+
+
+def load_rsa_private_numbers(numbers, backend):
+ return backend.load_rsa_private_numbers(numbers)
+
+
+def load_rsa_public_numbers(numbers, backend):
+ return backend.load_rsa_public_numbers(numbers)
diff --git a/docs/hazmat/primitives/asymmetric/serialization.rst b/docs/hazmat/primitives/asymmetric/serialization.rst
index 2b3eb511..e53d0d1f 100644
--- a/docs/hazmat/primitives/asymmetric/serialization.rst
+++ b/docs/hazmat/primitives/asymmetric/serialization.rst
@@ -98,3 +98,41 @@ header that mentions the type of the serialized key. e.g.
:raises UnsupportedAlgorithm: If the serialized key is of a type that
is not supported by the backend or if the key is encrypted with a
symmetric cipher that is not supported by the backend.
+
+
+RSA Numbers
+~~~~~~~~~~~
+
+.. function:: load_rsa_private_numbers(numbers, backend)
+
+ .. versionadded:: 0.5
+
+ Create a private key instance using the given backend and numbers.
+
+ :param numbers: An instance of
+ :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers`.
+
+ :param backend: A
+ :class:`~cryptography.hazmat.backends.interfaces.RSABackend` provider.
+
+ :returns: A new instance of a private key.
+
+ :raises UnsupportedAlgorithm: If the given backend does not support loading
+ numbers.
+
+.. function:: load_rsa_public_numbers(numbers, backend)
+
+ .. versionadded:: 0.5
+
+ Create a public key instance using the given backend and numbers.
+
+ :param numbers: An instance of
+ :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicNumbers`.
+
+ :param backend: A
+ :class:`~cryptography.hazmat.backends.interfaces.RSABackend` provider.
+
+ :returns: A new instance of a public key.
+
+ :raises UnsupportedAlgorithm: If the given backend does not support loading
+ numbers.
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py
index b19990e0..53a5806f 100644
--- a/tests/hazmat/primitives/test_serialization.py
+++ b/tests/hazmat/primitives/test_serialization.py
@@ -23,9 +23,12 @@ from cryptography.exceptions import _Reasons
from cryptography.hazmat.primitives.asymmetric import dsa, rsa
from cryptography.hazmat.primitives.serialization import (
load_pem_pkcs8_private_key,
- load_pem_traditional_openssl_private_key
+ load_pem_traditional_openssl_private_key,
+ load_rsa_private_numbers,
+ load_rsa_public_numbers
)
+from .fixtures_rsa import RSA_KEY_1024
from .utils import _check_rsa_private_key, load_vectors_from_file
from ...utils import raises_unsupported_algorithm
@@ -544,3 +547,30 @@ class TestPKCS8Serialisation(object):
pemfile.read().encode(), password, backend
)
)
+
+
+@pytest.mark.rsa
+class TestLoadRSANumbers(object):
+ def test_load_private_numbers(self, backend):
+ numbers = rsa.RSAPrivateNumbers(
+ p=RSA_KEY_1024["p"],
+ q=RSA_KEY_1024["q"],
+ d=RSA_KEY_1024["private_exponent"],
+ dmp1=RSA_KEY_1024["dmp1"],
+ dmq1=RSA_KEY_1024["dmq1"],
+ iqmp=RSA_KEY_1024["iqmp"],
+ public_numbers=rsa.RSAPublicNumbers(
+ n=RSA_KEY_1024["modulus"],
+ e=RSA_KEY_1024["public_exponent"]
+ )
+ )
+ private_key = load_rsa_private_numbers(numbers, backend)
+ assert private_key
+
+ def test_load_public_numbers(self, backend):
+ numbers = rsa.RSAPublicNumbers(
+ n=RSA_KEY_1024["modulus"],
+ e=RSA_KEY_1024["public_exponent"]
+ )
+ public_key = load_rsa_public_numbers(numbers, backend)
+ assert public_key