Skip to content

Commit

Permalink
make PrivateKeyWithSerialization an alias of PrivateKey (#5722)
Browse files Browse the repository at this point in the history
* make PrivateKeyWithSerialization an alias of PrivateKey

* black
  • Loading branch information
reaperhulk authored Jan 31, 2021
1 parent f5940f0 commit 6a8c0b5
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 101 deletions.
16 changes: 8 additions & 8 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,9 @@ Changelog
:meth:`~cryptography.hazmat.primitives.ciphers.CipherContext.update_into` on
:class:`~cryptography.hazmat.primitives.ciphers.CipherContext`.
* Added
:meth:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKeyWithSerialization.private_bytes`
:meth:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey.private_bytes`
to
:class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKeyWithSerialization`.
:class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey`.
* Added
:meth:`~cryptography.hazmat.primitives.asymmetric.dh.DHPublicKey.public_bytes`
to
Expand Down Expand Up @@ -1287,23 +1287,23 @@ Changelog
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization`
and deprecated ``EllipticCurvePrivateKeyWithNumbers``.
* Added
:meth:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization.private_bytes`
:meth:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.private_bytes`
to
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization`.
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`.
* Added
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization`
and deprecated ``RSAPrivateKeyWithNumbers``.
* Added
:meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`
:meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.private_bytes`
to
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization`.
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`.
* Added
:class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKeyWithSerialization`
and deprecated ``DSAPrivateKeyWithNumbers``.
* Added
:meth:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKeyWithSerialization.private_bytes`
:meth:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey.private_bytes`
to
:class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKeyWithSerialization`.
:class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`.
* Added
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKeyWithSerialization`
and deprecated ``RSAPublicKeyWithNumbers``.
Expand Down
19 changes: 7 additions & 12 deletions docs/hazmat/primitives/asymmetric/dh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ Key interfaces

.. versionadded:: 1.7

A DH private key that is not an :term:`opaque key` also implements
:class:`DHPrivateKeyWithSerialization` to provide serialization methods.

.. attribute:: key_size

The bit length of the prime modulus.
Expand All @@ -223,15 +220,6 @@ Key interfaces

:return bytes: The agreed key. The bytes are ordered in 'big' endian.


.. class:: DHPrivateKeyWithSerialization

.. versionadded:: 1.7

This interface contains additional methods relating to serialization.
Any object with this interface also has all the methods from
:class:`DHPrivateKey`.

.. method:: private_numbers()

Return the numbers that make up this private key.
Expand Down Expand Up @@ -266,6 +254,13 @@ Key interfaces
:return bytes: Serialized key.


.. class:: DHPrivateKeyWithSerialization

.. versionadded:: 1.7

Alias for :class:`DHPrivateKey`.


.. class:: DHPublicKey

.. versionadded:: 1.7
Expand Down
20 changes: 8 additions & 12 deletions docs/hazmat/primitives/asymmetric/dsa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ Key interfaces

.. versionadded:: 0.3

A `DSA`_ private key. A DSA private key that is not an
:term:`opaque key` also implements :class:`DSAPrivateKeyWithSerialization`
to provide serialization methods.
A `DSA`_ private key.

.. method:: public_key()

Expand Down Expand Up @@ -330,15 +328,6 @@ Key interfaces

:return bytes: Signature.


.. class:: DSAPrivateKeyWithSerialization

.. versionadded:: 0.8

This interface contains additional methods relating to serialization.
Any object with this interface also has all the methods from
:class:`DSAPrivateKey`.

.. method:: private_numbers()

Create a
Expand Down Expand Up @@ -378,6 +367,13 @@ Key interfaces
:return bytes: Serialized key.


.. class:: DSAPrivateKeyWithSerialization

.. versionadded:: 0.8

Alias for :class:`DSAPrivateKey`.


.. class:: DSAPublicKey

.. versionadded:: 0.3
Expand Down
16 changes: 7 additions & 9 deletions docs/hazmat/primitives/asymmetric/ec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,6 @@ Key Interfaces
Size (in :term:`bits`) of a secret scalar for the curve (as generated
by :func:`generate_private_key`).


.. class:: EllipticCurvePrivateKeyWithSerialization

.. versionadded:: 0.8

This interface contains additional methods relating to serialization.
Any object with this interface also has all the methods from
:class:`EllipticCurvePrivateKey`.

.. method:: private_numbers()

Create a :class:`EllipticCurvePrivateNumbers` object.
Expand Down Expand Up @@ -670,6 +661,13 @@ Key Interfaces
:return bytes: Serialized key.


.. class:: EllipticCurvePrivateKeyWithSerialization

.. versionadded:: 0.8

Alias for :class:`EllipticCurvePrivateKey`.


.. class:: EllipticCurvePublicKey

.. versionadded:: 0.5
Expand Down
26 changes: 10 additions & 16 deletions docs/hazmat/primitives/asymmetric/rsa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ There is also support for :func:`loading public keys in the SSH format
Key serialization
~~~~~~~~~~~~~~~~~

If you have a private key that you've loaded or generated which implements the
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization`
interface you can use
:meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`
If you have a private key that you've loaded you can use
:meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.private_bytes`
to serialize the key.

.. doctest::
Expand Down Expand Up @@ -536,9 +534,7 @@ Key interfaces

.. versionadded:: 0.2

An `RSA`_ private key. An RSA private key that is not an
:term:`opaque key` also implements :class:`RSAPrivateKeyWithSerialization`
to provide serialization methods.
An `RSA`_ private key.

.. method:: decrypt(ciphertext, padding)

Expand Down Expand Up @@ -587,15 +583,6 @@ Key interfaces

:return bytes: Signature.


.. class:: RSAPrivateKeyWithSerialization

.. versionadded:: 0.8

This interface contains additional methods relating to serialization.
Any object with this interface also has all the methods from
:class:`RSAPrivateKey`.

.. method:: private_numbers()

Create a
Expand Down Expand Up @@ -635,6 +622,13 @@ Key interfaces
:return bytes: Serialized key.


.. class:: RSAPrivateKeyWithSerialization

.. versionadded:: 0.8

Alias for :class:`RSAPrivateKey`.


.. class:: RSAPublicKey

.. versionadded:: 0.2
Expand Down
11 changes: 5 additions & 6 deletions docs/hazmat/primitives/asymmetric/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -924,15 +924,14 @@ Serialization Encryption Types

Objects with this interface are usable as encryption types with methods
like ``private_bytes`` available on
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization`
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`
,
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization`
, :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKeyWithSerialization`
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
, :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey`
and
:class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKeyWithSerialization`.
:class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`.
All other classes in this section represent the available choices for
encryption and have this interface. They are used with
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`.
encryption and have this interface.

.. class:: BestAvailableEncryption(password)

Expand Down
6 changes: 3 additions & 3 deletions src/cryptography/hazmat/backends/openssl/dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _dh_cdata_to_parameters(dh_cdata, backend):
return _DHParameters(backend, param_cdata)


@utils.register_interface(dh.DHParametersWithSerialization)
@utils.register_interface(dh.DHParameters)
class _DHParameters(object):
def __init__(self, backend, dh_cdata):
self._backend = backend
Expand Down Expand Up @@ -85,7 +85,7 @@ def _get_dh_num_bits(backend, dh_cdata):
return backend._lib.BN_num_bits(p[0])


@utils.register_interface(dh.DHPrivateKeyWithSerialization)
@utils.register_interface(dh.DHPrivateKey)
class _DHPrivateKey(object):
def __init__(self, backend, dh_cdata, evp_pkey):
self._backend = backend
Expand Down Expand Up @@ -204,7 +204,7 @@ def private_bytes(self, encoding, format, encryption_algorithm):
)


@utils.register_interface(dh.DHPublicKeyWithSerialization)
@utils.register_interface(dh.DHPublicKey)
class _DHPublicKey(object):
def __init__(self, backend, dh_cdata, evp_pkey):
self._backend = backend
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography/hazmat/backends/openssl/dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def generate_private_key(self):
return self._backend.generate_dsa_private_key(self)


@utils.register_interface(dsa.DSAPrivateKeyWithSerialization)
@utils.register_interface(dsa.DSAPrivateKey)
class _DSAPrivateKey(object):
def __init__(self, backend, dsa_cdata, evp_pkey):
self._backend = backend
Expand Down Expand Up @@ -197,7 +197,7 @@ def sign(self, data, algorithm):
return _dsa_sig_sign(self._backend, self, data)


@utils.register_interface(dsa.DSAPublicKeyWithSerialization)
@utils.register_interface(dsa.DSAPublicKey)
class _DSAPublicKey(object):
def __init__(self, backend, dsa_cdata, evp_pkey):
self._backend = backend
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography/hazmat/backends/openssl/ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def verify(self):
)


@utils.register_interface(ec.EllipticCurvePrivateKeyWithSerialization)
@utils.register_interface(ec.EllipticCurvePrivateKey)
class _EllipticCurvePrivateKey(object):
def __init__(self, backend, ec_key_cdata, evp_pkey):
self._backend = backend
Expand Down Expand Up @@ -236,7 +236,7 @@ def sign(self, data, signature_algorithm):
return _ecdsa_sig_sign(self._backend, self, data)


@utils.register_interface(ec.EllipticCurvePublicKeyWithSerialization)
@utils.register_interface(ec.EllipticCurvePublicKey)
class _EllipticCurvePublicKey(object):
def __init__(self, backend, ec_key_cdata, evp_pkey):
self._backend = backend
Expand Down
8 changes: 4 additions & 4 deletions src/cryptography/hazmat/backends/openssl/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
calculate_max_pss_salt_length,
)
from cryptography.hazmat.primitives.asymmetric.rsa import (
RSAPrivateKeyWithSerialization,
RSAPublicKeyWithSerialization,
RSAPrivateKey,
RSAPublicKey,
)


Expand Down Expand Up @@ -351,7 +351,7 @@ def verify(self):
)


@utils.register_interface(RSAPrivateKeyWithSerialization)
@utils.register_interface(RSAPrivateKey)
class _RSAPrivateKey(object):
def __init__(self, backend, rsa_cdata, evp_pkey):
res = backend._lib.RSA_check_key(rsa_cdata)
Expand Down Expand Up @@ -451,7 +451,7 @@ def sign(self, data, padding, algorithm):
return _rsa_sig_sign(self._backend, padding, algorithm, self, data)


@utils.register_interface(RSAPublicKeyWithSerialization)
@utils.register_interface(RSAPublicKey)
class _RSAPublicKey(object):
def __init__(self, backend, rsa_cdata, evp_pkey):
self._backend = backend
Expand Down
5 changes: 3 additions & 2 deletions src/cryptography/hazmat/primitives/asymmetric/dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ def exchange(self, peer_public_key):
return shared key as bytes.
"""


class DHPrivateKeyWithSerialization(DHPrivateKey, metaclass=abc.ABCMeta):
@abc.abstractmethod
def private_numbers(self):
"""
Expand All @@ -186,6 +184,9 @@ def private_bytes(self, encoding, format, encryption_algorithm):
"""


DHPrivateKeyWithSerialization = DHPrivateKey


class DHPublicKey(metaclass=abc.ABCMeta):
@abc.abstractproperty
def key_size(self):
Expand Down
5 changes: 3 additions & 2 deletions src/cryptography/hazmat/primitives/asymmetric/dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def sign(self, data, algorithm):
Signs the data
"""


class DSAPrivateKeyWithSerialization(DSAPrivateKey, metaclass=abc.ABCMeta):
@abc.abstractmethod
def private_numbers(self):
"""
Expand All @@ -71,6 +69,9 @@ def private_bytes(self, encoding, format, encryption_algorithm):
"""


DSAPrivateKeyWithSerialization = DSAPrivateKey


class DSAPublicKey(metaclass=abc.ABCMeta):
@abc.abstractproperty
def key_size(self):
Expand Down
7 changes: 3 additions & 4 deletions src/cryptography/hazmat/primitives/asymmetric/ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ def sign(self, data, signature_algorithm):
Signs the data
"""


class EllipticCurvePrivateKeyWithSerialization(
EllipticCurvePrivateKey, metaclass=abc.ABCMeta
):
@abc.abstractmethod
def private_numbers(self):
"""
Expand All @@ -110,6 +106,9 @@ def private_bytes(self, encoding, format, encryption_algorithm):
"""


EllipticCurvePrivateKeyWithSerialization = EllipticCurvePrivateKey


class EllipticCurvePublicKey(metaclass=abc.ABCMeta):
@abc.abstractmethod
def verifier(self, signature, signature_algorithm):
Expand Down
5 changes: 3 additions & 2 deletions src/cryptography/hazmat/primitives/asymmetric/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def sign(self, data, padding, algorithm):
Signs the data.
"""


class RSAPrivateKeyWithSerialization(RSAPrivateKey, metaclass=abc.ABCMeta):
@abc.abstractmethod
def private_numbers(self):
"""
Expand All @@ -58,6 +56,9 @@ def private_bytes(self, encoding, format, encryption_algorithm):
"""


RSAPrivateKeyWithSerialization = RSAPrivateKey


class RSAPublicKey(metaclass=abc.ABCMeta):
@abc.abstractmethod
def verifier(self, signature, padding, algorithm):
Expand Down
Loading

0 comments on commit 6a8c0b5

Please sign in to comment.