diff options
| author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2019-01-14 21:50:17 -0600 | 
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2019-01-14 22:50:17 -0500 | 
| commit | c6c25c21496858271fbc4c89fb102074fd3d5f60 (patch) | |
| tree | 009896d2b53e2d45f050b35320609bf348f0e31c /docs/hazmat/primitives/asymmetric | |
| parent | aeb3acbe9abffba68da3cc8b6bc0f3c2acb9bd9d (diff) | |
| download | cryptography-c6c25c21496858271fbc4c89fb102074fd3d5f60.tar.gz cryptography-c6c25c21496858271fbc4c89fb102074fd3d5f60.tar.bz2 cryptography-c6c25c21496858271fbc4c89fb102074fd3d5f60.zip  | |
Serialization x25519 (#4688)
* modify x25519 serialization to match x448
supports raw and pkcs8 encoding on private_bytes
supports raw and subjectpublickeyinfo on public_bytes
deprecates zero argument call to public_bytes
* add docs
* this is public now
* don't need that
* review feedback
Diffstat (limited to 'docs/hazmat/primitives/asymmetric')
| -rw-r--r-- | docs/hazmat/primitives/asymmetric/x25519.rst | 88 | 
1 files changed, 84 insertions, 4 deletions
diff --git a/docs/hazmat/primitives/asymmetric/x25519.rst b/docs/hazmat/primitives/asymmetric/x25519.rst index 67ed2809..ea01fbaa 100644 --- a/docs/hazmat/primitives/asymmetric/x25519.rst +++ b/docs/hazmat/primitives/asymmetric/x25519.rst @@ -66,6 +66,29 @@ Key interfaces          :returns: :class:`X25519PrivateKey` +    .. classmethod:: from_private_bytes(data) + +        .. versionadded:: 2.5 + +        A class method for loading an X25519 key encoded as +        :attr:`~cryptography.hazmat.primitives.serialization.Encoding.Raw`. + +        :param bytes data: 32 byte private key. + +        :returns: :class:`X25519PrivateKey` + +        .. doctest:: + +            >>> from cryptography.hazmat.primitives import serialization +            >>> from cryptography.hazmat.primitives.asymmetric import x25519 +            >>> private_key = x25519.X25519PrivateKey.generate() +            >>> private_bytes = private_key.private_bytes( +            ...     encoding=serialization.Encoding.Raw, +            ...     format=serialization.PrivateFormat.Raw, +            ...     encryption_algorithm=serialization.NoEncryption() +            ... ) +            >>> loaded_private_key = x25519.X25519PrivateKey.from_private_bytes(private_bytes) +      .. method:: public_key()          :returns: :class:`X25519PublicKey` @@ -77,6 +100,38 @@ Key interfaces          :returns bytes: A shared key. +    .. method:: private_bytes(encoding, format, encryption_algorithm) + +        .. versionadded:: 2.5 + +        Allows serialization of the key to bytes. Encoding ( +        :attr:`~cryptography.hazmat.primitives.serialization.Encoding.PEM`, +        :attr:`~cryptography.hazmat.primitives.serialization.Encoding.DER`, or +        :attr:`~cryptography.hazmat.primitives.serialization.Encoding.Raw`) and +        format ( +        :attr:`~cryptography.hazmat.primitives.serialization.PrivateFormat.PKCS8` +        or +        :attr:`~cryptography.hazmat.primitives.serialization.PrivateFormat.Raw` +        ) are chosen to define the exact serialization. + +        :param encoding: A value from the +            :class:`~cryptography.hazmat.primitives.serialization.Encoding` enum. + +        :param format: A value from the +            :class:`~cryptography.hazmat.primitives.serialization.PrivateFormat` +            enum. If the ``encoding`` is +            :attr:`~cryptography.hazmat.primitives.serialization.Encoding.Raw` +            then ``format`` must be +            :attr:`~cryptography.hazmat.primitives.serialization.PrivateFormat.Raw` +            , otherwise it must be +            :attr:`~cryptography.hazmat.primitives.serialization.PrivateFormat.PKCS8`. + +        :param encryption_algorithm: An instance of an object conforming to the +            :class:`~cryptography.hazmat.primitives.serialization.KeySerializationEncryption` +            interface. + +        :return bytes: Serialized key. +  .. class:: X25519PublicKey      .. versionadded:: 2.0 @@ -92,12 +147,37 @@ Key interfaces              >>> from cryptography.hazmat.primitives.asymmetric import x25519              >>> private_key = x25519.X25519PrivateKey.generate()              >>> public_key = private_key.public_key() -            >>> public_bytes = public_key.public_bytes() +            >>> public_bytes = public_key.public_bytes( +            ...     encoding=serialization.Encoding.Raw, +            ...     format=serialization.PublicFormat.Raw +            ... )              >>> loaded_public_key = x25519.X25519PublicKey.from_public_bytes(public_bytes) -    .. method:: public_bytes() - -        :returns bytes: The raw bytes of the public key. +    .. method:: public_bytes(encoding, format) + +        Allows serialization of the key to bytes. Encoding ( +        :attr:`~cryptography.hazmat.primitives.serialization.Encoding.PEM`, +        :attr:`~cryptography.hazmat.primitives.serialization.Encoding.DER`, or +        :attr:`~cryptography.hazmat.primitives.serialization.Encoding.Raw`) and +        format ( +        :attr:`~cryptography.hazmat.primitives.serialization.PublicFormat.SubjectPublicKeyInfo` +        or +        :attr:`~cryptography.hazmat.primitives.serialization.PublicFormat.Raw` +        ) are chosen to define the exact serialization. + +        :param encoding: A value from the +            :class:`~cryptography.hazmat.primitives.serialization.Encoding` enum. + +        :param format: A value from the +            :class:`~cryptography.hazmat.primitives.serialization.PublicFormat` +            enum. If the ``encoding`` is +            :attr:`~cryptography.hazmat.primitives.serialization.Encoding.Raw` +            then ``format`` must be +            :attr:`~cryptography.hazmat.primitives.serialization.PublicFormat.Raw` +            , otherwise it must be +            :attr:`~cryptography.hazmat.primitives.serialization.PublicFormat.SubjectPublicKeyInfo`. + +        :returns bytes: The public key bytes.  .. _`Diffie-Hellman key exchange`: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange  | 
