• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
4
5from __future__ import absolute_import, division, print_function
6
7import abc
8
9import six
10
11from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
12
13
14@six.add_metaclass(abc.ABCMeta)
15class Ed448PublicKey(object):
16    @classmethod
17    def from_public_bytes(cls, data):
18        from cryptography.hazmat.backends.openssl.backend import backend
19
20        if not backend.ed448_supported():
21            raise UnsupportedAlgorithm(
22                "ed448 is not supported by this version of OpenSSL.",
23                _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
24            )
25
26        return backend.ed448_load_public_bytes(data)
27
28    @abc.abstractmethod
29    def public_bytes(self, encoding, format):
30        """
31        The serialized bytes of the public key.
32        """
33
34    @abc.abstractmethod
35    def verify(self, signature, data):
36        """
37        Verify the signature.
38        """
39
40
41@six.add_metaclass(abc.ABCMeta)
42class Ed448PrivateKey(object):
43    @classmethod
44    def generate(cls):
45        from cryptography.hazmat.backends.openssl.backend import backend
46
47        if not backend.ed448_supported():
48            raise UnsupportedAlgorithm(
49                "ed448 is not supported by this version of OpenSSL.",
50                _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
51            )
52        return backend.ed448_generate_key()
53
54    @classmethod
55    def from_private_bytes(cls, data):
56        from cryptography.hazmat.backends.openssl.backend import backend
57
58        if not backend.ed448_supported():
59            raise UnsupportedAlgorithm(
60                "ed448 is not supported by this version of OpenSSL.",
61                _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
62            )
63
64        return backend.ed448_load_private_bytes(data)
65
66    @abc.abstractmethod
67    def public_key(self):
68        """
69        The Ed448PublicKey derived from the private key.
70        """
71
72    @abc.abstractmethod
73    def sign(self, data):
74        """
75        Signs the data.
76        """
77
78    @abc.abstractmethod
79    def private_bytes(self, encoding, format, encryption_algorithm):
80        """
81        The serialized bytes of the private key.
82        """
83