aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Stapleton <alexs@prol.etari.at>2014-12-30 12:50:14 +0000
committerAlex Stapleton <alexs@prol.etari.at>2015-01-24 14:50:32 +0000
commitf79c2313afdedae24b1b5b6d8fb8ff57f778a29b (patch)
tree0217de19e172701eef50dfef9dc43e2d7e22a3f4 /src
parentb9690abdb3b8afc0599a30deddd06a1681286d47 (diff)
downloadcryptography-f79c2313afdedae24b1b5b6d8fb8ff57f778a29b.tar.gz
cryptography-f79c2313afdedae24b1b5b6d8fb8ff57f778a29b.tar.bz2
cryptography-f79c2313afdedae24b1b5b6d8fb8ff57f778a29b.zip
Move RSA*Key interfaces to cryptography.hazmat.primitives.asymmetric.rsa
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/rsa.py67
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/__init__.py100
2 files changed, 104 insertions, 63 deletions
diff --git a/src/cryptography/hazmat/primitives/asymmetric/rsa.py b/src/cryptography/hazmat/primitives/asymmetric/rsa.py
index 47bdf5cb..332ad2c3 100644
--- a/src/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -4,6 +4,7 @@
from __future__ import absolute_import, division, print_function
+import abc
from fractions import gcd
import six
@@ -13,6 +14,72 @@ from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
from cryptography.hazmat.backends.interfaces import RSABackend
+@six.add_metaclass(abc.ABCMeta)
+class RSAPrivateKey(object):
+ @abc.abstractmethod
+ def signer(self, padding, algorithm):
+ """
+ Returns an AsymmetricSignatureContext used for signing data.
+ """
+
+ @abc.abstractmethod
+ def decrypt(self, ciphertext, padding):
+ """
+ Decrypts the provided ciphertext.
+ """
+
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the public modulus.
+ """
+
+ @abc.abstractmethod
+ def public_key(self):
+ """
+ The RSAPublicKey associated with this private key.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class RSAPrivateKeyWithNumbers(RSAPrivateKey):
+ @abc.abstractmethod
+ def private_numbers(self):
+ """
+ Returns an RSAPrivateNumbers.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class RSAPublicKey(object):
+ @abc.abstractmethod
+ def verifier(self, signature, padding, algorithm):
+ """
+ Returns an AsymmetricVerificationContext used for verifying signatures.
+ """
+
+ @abc.abstractmethod
+ def encrypt(self, plaintext, padding):
+ """
+ Encrypts the given plaintext.
+ """
+
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the public modulus.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class RSAPublicKeyWithNumbers(RSAPublicKey):
+ @abc.abstractmethod
+ def public_numbers(self):
+ """
+ Returns an RSAPublicNumbers
+ """
+
+
def generate_private_key(public_exponent, key_size, backend):
if not isinstance(backend, RSABackend):
raise UnsupportedAlgorithm(
diff --git a/src/cryptography/hazmat/primitives/interfaces/__init__.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py
index 7961cf15..e0bcb8f5 100644
--- a/src/cryptography/hazmat/primitives/interfaces/__init__.py
+++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py
@@ -9,9 +9,8 @@ import abc
import six
from cryptography import utils
-
from cryptography.hazmat.primitives.asymmetric import dsa
-
+from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.interfaces.asymmetric.ec import (
EllipticCurve, EllipticCurvePrivateKey, EllipticCurvePrivateKeyWithNumbers,
EllipticCurvePublicKey, EllipticCurvePublicKeyWithNumbers,
@@ -196,70 +195,45 @@ class HashContext(object):
"""
-@six.add_metaclass(abc.ABCMeta)
-class RSAPrivateKey(object):
- @abc.abstractmethod
- def signer(self, padding, algorithm):
- """
- Returns an AsymmetricSignatureContext used for signing data.
- """
-
- @abc.abstractmethod
- def decrypt(self, ciphertext, padding):
- """
- Decrypts the provided ciphertext.
- """
-
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the public modulus.
- """
-
- @abc.abstractmethod
- def public_key(self):
- """
- The RSAPublicKey associated with this private key.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class RSAPrivateKeyWithNumbers(RSAPrivateKey):
- @abc.abstractmethod
- def private_numbers(self):
- """
- Returns an RSAPrivateNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class RSAPublicKey(object):
- @abc.abstractmethod
- def verifier(self, signature, padding, algorithm):
- """
- Returns an AsymmetricVerificationContext used for verifying signatures.
- """
-
- @abc.abstractmethod
- def encrypt(self, plaintext, padding):
- """
- Encrypts the given plaintext.
- """
+RSAPrivateKey = utils.deprecated(
+ rsa.RSAPrivateKey,
+ __name__,
+ (
+ "The RSAPrivateKey interface has moved to the "
+ "cryptography.hazmat.primitives.asymmetric.rsa module"
+ ),
+ utils.DeprecatedIn08
+)
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the public modulus.
- """
+RSAPrivateKeyWithNumbers = utils.deprecated(
+ rsa.RSAPrivateKeyWithNumbers,
+ __name__,
+ (
+ "The RSAPrivateKeyWithNumbers interface has moved to the "
+ "cryptography.hazmat.primitives.asymmetric.rsa module"
+ ),
+ utils.DeprecatedIn08
+)
+RSAPublicKey = utils.deprecated(
+ rsa.RSAPublicKey,
+ __name__,
+ (
+ "The RSAPublicKeyWithNumbers interface has moved to the "
+ "cryptography.hazmat.primitives.asymmetric.rsa module"
+ ),
+ utils.DeprecatedIn08
+)
-@six.add_metaclass(abc.ABCMeta)
-class RSAPublicKeyWithNumbers(RSAPublicKey):
- @abc.abstractmethod
- def public_numbers(self):
- """
- Returns an RSAPublicNumbers
- """
+RSAPublicKeyWithNumbers = utils.deprecated(
+ rsa.RSAPublicKeyWithNumbers,
+ __name__,
+ (
+ "The RSAPublicKeyWithNumbers interface has moved to the "
+ "cryptography.hazmat.primitives.asymmetric.rsa module"
+ ),
+ utils.DeprecatedIn08
+)
@six.add_metaclass(abc.ABCMeta)