aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGregory Haynes <greg@greghaynes.net>2015-01-02 09:01:00 -0800
committerGregory Haynes <greg@greghaynes.net>2015-01-02 09:01:00 -0800
commit480b4f58631406b8ec9aac5732a49a4e5a1428e5 (patch)
tree30f8572b185bed948e76191f2bc986007bb0c491 /src
parent5ffea405885710c6836d1318c00b67162cb4faf9 (diff)
downloadcryptography-480b4f58631406b8ec9aac5732a49a4e5a1428e5.tar.gz
cryptography-480b4f58631406b8ec9aac5732a49a4e5a1428e5.tar.bz2
cryptography-480b4f58631406b8ec9aac5732a49a4e5a1428e5.zip
Split out asymmetric key interfaces
Splitting out RSA, DSA, and EllipticalCurve interfaces as part of #1495.
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/__init__.py259
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py5
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py93
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py87
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/rsa.py75
5 files changed, 290 insertions, 229 deletions
diff --git a/src/cryptography/hazmat/primitives/interfaces/__init__.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py
index fd1b25f3..8b6b1f8c 100644
--- a/src/cryptography/hazmat/primitives/interfaces/__init__.py
+++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py
@@ -8,6 +8,19 @@ import abc
import six
+from cryptography.hazmat.primitives.interfaces.asymmetric.dsa import (
+ DSAParameters, DSAParametersWithNumbers, DSAPrivateKey,
+ DSAPrivateKeyWithNumbers, DSAPublicKey, DSAPublicKeyWithNumbers
+)
+from cryptography.hazmat.primitives.interfaces.asymmetric.ec import (
+ EllipticCurve, EllipticCurvePrivateKey, EllipticCurvePrivateKeyWithNumbers,
+ EllipticCurvePublicKey, EllipticCurvePublicKeyWithNumbers,
+ EllipticCurveSignatureAlgorithm
+)
+from cryptography.hazmat.primitives.interfaces.asymmetric.rsa import (
+ RSAPrivateKey, RSAPrivateKeyWithNumbers, RSAPublicKey,
+ RSAPublicKeyWithNumbers
+)
from cryptography.hazmat.primitives.interfaces.ciphers import (
BlockCipherAlgorithm, CipherAlgorithm, Mode,
ModeWithAuthenticationTag, ModeWithInitializationVector, ModeWithNonce
@@ -16,10 +29,26 @@ from cryptography.hazmat.primitives.interfaces.ciphers import (
__all__ = [
"BlockCipherAlgorithm",
"CipherAlgorithm",
+ "DSAParameters",
+ "DSAParametersWithNumbers",
+ "DSAPrivateKey",
+ "DSAPrivateKeyWithNumbers",
+ "DSAPublicKey",
+ "DSAPublicKeyWithNumbers",
+ "EllipticCurve",
+ "EllipticCurvePrivateKey",
+ "EllipticCurvePrivateKeyWithNumbers",
+ "EllipticCurvePublicKey",
+ "EllipticCurvePublicKeyWithNumbers",
+ "EllipticCurveSignatureAlgorithm",
"Mode",
"ModeWithAuthenticationTag",
"ModeWithInitializationVector",
- "ModeWithNonce"
+ "ModeWithNonce",
+ "RSAPrivateKey",
+ "RSAPrivateKeyWithNumbers",
+ "RSAPublicKey",
+ "RSAPublicKeyWithNumbers"
]
@@ -122,156 +151,6 @@ 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.
- """
-
- @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
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAParameters(object):
- @abc.abstractmethod
- def generate_private_key(self):
- """
- Generates and returns a DSAPrivateKey.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAParametersWithNumbers(DSAParameters):
- @abc.abstractmethod
- def parameter_numbers(self):
- """
- Returns a DSAParameterNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPrivateKey(object):
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the prime modulus.
- """
-
- @abc.abstractmethod
- def public_key(self):
- """
- The DSAPublicKey associated with this private key.
- """
-
- @abc.abstractmethod
- def parameters(self):
- """
- The DSAParameters object associated with this private key.
- """
-
- @abc.abstractmethod
- def signer(self, signature_algorithm):
- """
- Returns an AsymmetricSignatureContext used for signing data.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPrivateKeyWithNumbers(DSAPrivateKey):
- @abc.abstractmethod
- def private_numbers(self):
- """
- Returns a DSAPrivateNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPublicKey(object):
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the prime modulus.
- """
-
- @abc.abstractmethod
- def parameters(self):
- """
- The DSAParameters object associated with this public key.
- """
-
- @abc.abstractmethod
- def verifier(self, signature, signature_algorithm):
- """
- Returns an AsymmetricVerificationContext used for signing data.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPublicKeyWithNumbers(DSAPublicKey):
- @abc.abstractmethod
- def public_numbers(self):
- """
- Returns a DSAPublicNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
class AsymmetricSignatureContext(object):
@abc.abstractmethod
def update(self, data):
@@ -329,84 +208,6 @@ class KeyDerivationFunction(object):
@six.add_metaclass(abc.ABCMeta)
-class EllipticCurve(object):
- @abc.abstractproperty
- def name(self):
- """
- The name of the curve. e.g. secp256r1.
- """
-
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the base point of the curve.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurveSignatureAlgorithm(object):
- @abc.abstractproperty
- def algorithm(self):
- """
- The digest algorithm used with this signature.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePrivateKey(object):
- @abc.abstractmethod
- def signer(self, signature_algorithm):
- """
- Returns an AsymmetricSignatureContext used for signing data.
- """
-
- @abc.abstractmethod
- def public_key(self):
- """
- The EllipticCurvePublicKey for this private key.
- """
-
- @abc.abstractproperty
- def curve(self):
- """
- The EllipticCurve that this key is on.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePrivateKeyWithNumbers(EllipticCurvePrivateKey):
- @abc.abstractmethod
- def private_numbers(self):
- """
- Returns an EllipticCurvePrivateNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePublicKey(object):
- @abc.abstractmethod
- def verifier(self, signature, signature_algorithm):
- """
- Returns an AsymmetricVerificationContext used for signing data.
- """
-
- @abc.abstractproperty
- def curve(self):
- """
- The EllipticCurve that this key is on.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePublicKeyWithNumbers(EllipticCurvePublicKey):
- @abc.abstractmethod
- def public_numbers(self):
- """
- Returns an EllipticCurvePublicNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
class MACContext(object):
@abc.abstractmethod
def update(self, data):
diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py
new file mode 100644
index 00000000..4b540884
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py
@@ -0,0 +1,5 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py
new file mode 100644
index 00000000..acfc8973
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py
@@ -0,0 +1,93 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import abc
+
+import six
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAParameters(object):
+ @abc.abstractmethod
+ def generate_private_key(self):
+ """
+ Generates and returns a DSAPrivateKey.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAParametersWithNumbers(DSAParameters):
+ @abc.abstractmethod
+ def parameter_numbers(self):
+ """
+ Returns a DSAParameterNumbers.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPrivateKey(object):
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the prime modulus.
+ """
+
+ @abc.abstractmethod
+ def public_key(self):
+ """
+ The DSAPublicKey associated with this private key.
+ """
+
+ @abc.abstractmethod
+ def parameters(self):
+ """
+ The DSAParameters object associated with this private key.
+ """
+
+ @abc.abstractmethod
+ def signer(self, signature_algorithm):
+ """
+ Returns an AsymmetricSignatureContext used for signing data.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPrivateKeyWithNumbers(DSAPrivateKey):
+ @abc.abstractmethod
+ def private_numbers(self):
+ """
+ Returns a DSAPrivateNumbers.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPublicKey(object):
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the prime modulus.
+ """
+
+ @abc.abstractmethod
+ def parameters(self):
+ """
+ The DSAParameters object associated with this public key.
+ """
+
+ @abc.abstractmethod
+ def verifier(self, signature, signature_algorithm):
+ """
+ Returns an AsymmetricVerificationContext used for signing data.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPublicKeyWithNumbers(DSAPublicKey):
+ @abc.abstractmethod
+ def public_numbers(self):
+ """
+ Returns a DSAPublicNumbers.
+ """
diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py
new file mode 100644
index 00000000..2a624576
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py
@@ -0,0 +1,87 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import abc
+
+import six
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurve(object):
+ @abc.abstractproperty
+ def name(self):
+ """
+ The name of the curve. e.g. secp256r1.
+ """
+
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the base point of the curve.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurveSignatureAlgorithm(object):
+ @abc.abstractproperty
+ def algorithm(self):
+ """
+ The digest algorithm used with this signature.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePrivateKey(object):
+ @abc.abstractmethod
+ def signer(self, signature_algorithm):
+ """
+ Returns an AsymmetricSignatureContext used for signing data.
+ """
+
+ @abc.abstractmethod
+ def public_key(self):
+ """
+ The EllipticCurvePublicKey for this private key.
+ """
+
+ @abc.abstractproperty
+ def curve(self):
+ """
+ The EllipticCurve that this key is on.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePrivateKeyWithNumbers(EllipticCurvePrivateKey):
+ @abc.abstractmethod
+ def private_numbers(self):
+ """
+ Returns an EllipticCurvePrivateNumbers.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePublicKey(object):
+ @abc.abstractmethod
+ def verifier(self, signature, signature_algorithm):
+ """
+ Returns an AsymmetricVerificationContext used for signing data.
+ """
+
+ @abc.abstractproperty
+ def curve(self):
+ """
+ The EllipticCurve that this key is on.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePublicKeyWithNumbers(EllipticCurvePublicKey):
+ @abc.abstractmethod
+ def public_numbers(self):
+ """
+ Returns an EllipticCurvePublicNumbers.
+ """
diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/rsa.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/rsa.py
new file mode 100644
index 00000000..35c3e9e6
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/asymmetric/rsa.py
@@ -0,0 +1,75 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import abc
+
+import six
+
+
+@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
+ """