Put the exchange method on the correct interface (#3591)
* Put the exchange method on the correct interface
* fixed links in docs
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 81aca4e..c212bb5 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -88,7 +88,7 @@
* Support for OpenSSL 1.0.0 has been removed. Users on older version of OpenSSL
will need to upgrade.
* Added support for Diffie-Hellman key exchange using
- :meth:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKeyWithSerialization.exchange`
+ :meth:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey.exchange`.
* The OS random engine for OpenSSL has been rewritten to improve compatibility
with embedded Python and other edge cases. More information about this change
can be found in the
diff --git a/docs/hazmat/primitives/asymmetric/dh.rst b/docs/hazmat/primitives/asymmetric/dh.rst
index 759b265..58ff663 100644
--- a/docs/hazmat/primitives/asymmetric/dh.rst
+++ b/docs/hazmat/primitives/asymmetric/dh.rst
@@ -29,8 +29,7 @@
DHE (or EDH), the ephemeral form of this exchange, is **strongly
preferred** over simple DH and provides `forward secrecy`_ when used.
You must generate a new private key using :func:`~DHParameters.generate_private_key` for
-each :meth:`~DHPrivateKeyWithSerialization.exchange` when performing an DHE key
-exchange.
+each :meth:`~DHPrivateKey.exchange` when performing an DHE key exchange.
To assemble a :class:`~DHParameters` and a :class:`~DHPublicKey` from
primitive integers, you must first create the
@@ -123,12 +122,22 @@
:return: A :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHParameters`.
+ .. method:: exchange(peer_public_key)
+
+ .. versionadded:: 1.7
+
+ :param DHPublicKeyWithSerialization peer_public_key: The public key for
+ the peer.
+
+ :return bytes: The agreed key. The bytes are ordered in 'big' endian.
+
.. class:: DHPrivateKeyWithSerialization
.. versionadded:: 0.9
- Inherits from :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey`.
+ Inherits from
+ :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey`.
.. method:: private_numbers()
@@ -136,15 +145,6 @@
:return: A :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateNumbers`.
- .. method:: exchange(peer_public_key)
-
- .. versionadded:: 1.7
-
- :param DHPublicKeyWithSerialization peer_public_key: The public key for the
- peer.
-
- :return bytes: The agreed key. The bytes are ordered in 'big' endian.
-
.. method:: private_bytes(encoding, format, encryption_algorithm)
.. versionadded:: 1.8
diff --git a/src/cryptography/hazmat/primitives/asymmetric/dh.py b/src/cryptography/hazmat/primitives/asymmetric/dh.py
index aa60a2d..d5e8260 100644
--- a/src/cryptography/hazmat/primitives/asymmetric/dh.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/dh.py
@@ -153,6 +153,13 @@
The DHParameters object associated with this private key.
"""
+ @abc.abstractmethod
+ def exchange(self, peer_public_key):
+ """
+ Given peer's DHPublicKey, carry out the key exchange and
+ return shared key as bytes.
+ """
+
@six.add_metaclass(abc.ABCMeta)
class DHPrivateKeyWithSerialization(DHPrivateKey):
@@ -162,13 +169,6 @@
Returns a DHPrivateNumbers.
"""
- @abc.abstractmethod
- def exchange(self, peer_public_key):
- """
- Given peer's DHPublicKey, carry out the key exchange and
- return shared key as bytes.
- """
-
@six.add_metaclass(abc.ABCMeta)
class DHPublicKey(object):