diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/dsa.py | 26 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/dsa.py | 19 |
2 files changed, 38 insertions, 7 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/dsa.py b/src/cryptography/hazmat/backends/openssl/dsa.py index d2972e4a..8d02e492 100644 --- a/src/cryptography/hazmat/backends/openssl/dsa.py +++ b/src/cryptography/hazmat/backends/openssl/dsa.py @@ -11,9 +11,6 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import ( AsymmetricSignatureContext, AsymmetricVerificationContext, dsa ) -from cryptography.hazmat.primitives.interfaces import ( - DSAParametersWithNumbers, DSAPrivateKeyWithNumbers, DSAPublicKeyWithNumbers -) def _truncate_digest_for_dsa(dsa_cdata, digest, backend): @@ -94,7 +91,7 @@ class _DSASignatureContext(object): return self._backend._ffi.buffer(sig_buf)[:buflen[0]] -@utils.register_interface(DSAParametersWithNumbers) +@utils.register_interface(dsa.DSAParametersWithNumbers) class _DSAParameters(object): def __init__(self, backend, dsa_cdata): self._backend = backend @@ -111,7 +108,7 @@ class _DSAParameters(object): return self._backend.generate_dsa_private_key(self) -@utils.register_interface(DSAPrivateKeyWithNumbers) +@utils.register_interface(dsa.DSAPrivateKeyWithSerialization) class _DSAPrivateKey(object): def __init__(self, backend, dsa_cdata): self._backend = backend @@ -159,8 +156,25 @@ class _DSAPrivateKey(object): dsa_cdata.g = self._backend._lib.BN_dup(self._dsa_cdata.g) return _DSAParameters(self._backend, dsa_cdata) + def private_bytes(self, encoding, format, encryption_algorithm): + evp_pkey = self._backend._lib.EVP_PKEY_new() + assert evp_pkey != self._backend._ffi.NULL + evp_pkey = self._backend._ffi.gc( + evp_pkey, self._backend._lib.EVP_PKEY_free + ) + res = self._backend._lib.EVP_PKEY_set1_DSA(evp_pkey, self._dsa_cdata) + assert res == 1 + return self._backend._private_key_bytes( + encoding, + format, + encryption_algorithm, + self._backend._lib.PEM_write_bio_DSAPrivateKey, + evp_pkey, + self._dsa_cdata + ) + -@utils.register_interface(DSAPublicKeyWithNumbers) +@utils.register_interface(dsa.DSAPublicKeyWithNumbers) class _DSAPublicKey(object): def __init__(self, backend, dsa_cdata): self._backend = backend diff --git a/src/cryptography/hazmat/primitives/asymmetric/dsa.py b/src/cryptography/hazmat/primitives/asymmetric/dsa.py index 58058df9..084686e4 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/dsa.py +++ b/src/cryptography/hazmat/primitives/asymmetric/dsa.py @@ -57,13 +57,30 @@ class DSAPrivateKey(object): @six.add_metaclass(abc.ABCMeta) -class DSAPrivateKeyWithNumbers(DSAPrivateKey): +class DSAPrivateKeyWithSerialization(DSAPrivateKey): @abc.abstractmethod def private_numbers(self): """ Returns a DSAPrivateNumbers. """ + @abc.abstractmethod + def private_bytes(self, encoding, format, encryption_algorithm): + """ + Returns the key serialized as bytes. + """ + + +DSAPrivateKeyWithNumbers = utils.deprecated( + DSAPrivateKeyWithSerialization, + __name__, + ( + "The DSAPrivateKeyWithNumbers interface has been renamed to " + "DSAPrivateKeyWithSerialization" + ), + utils.DeprecatedIn08 +) + @six.add_metaclass(abc.ABCMeta) class DSAPublicKey(object): |