Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py: 62%
37 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:36 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:36 +0000
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.
6import abc
8from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
9from cryptography.hazmat.primitives import _serialization
12class Ed448PublicKey(metaclass=abc.ABCMeta):
13 @classmethod
14 def from_public_bytes(cls, data: bytes) -> "Ed448PublicKey":
15 from cryptography.hazmat.backends.openssl.backend import backend
17 if not backend.ed448_supported():
18 raise UnsupportedAlgorithm(
19 "ed448 is not supported by this version of OpenSSL.",
20 _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
21 )
23 return backend.ed448_load_public_bytes(data)
25 @abc.abstractmethod
26 def public_bytes(
27 self,
28 encoding: _serialization.Encoding,
29 format: _serialization.PublicFormat,
30 ) -> bytes:
31 """
32 The serialized bytes of the public key.
33 """
35 def public_bytes_raw(self) -> bytes:
36 """
37 The raw bytes of the public key.
38 Equivalent to public_bytes(Raw, Raw).
39 """
40 return self.public_bytes(
41 _serialization.Encoding.Raw, _serialization.PublicFormat.Raw
42 )
44 @abc.abstractmethod
45 def verify(self, signature: bytes, data: bytes) -> None:
46 """
47 Verify the signature.
48 """
51class Ed448PrivateKey(metaclass=abc.ABCMeta):
52 @classmethod
53 def generate(cls) -> "Ed448PrivateKey":
54 from cryptography.hazmat.backends.openssl.backend import backend
56 if not backend.ed448_supported():
57 raise UnsupportedAlgorithm(
58 "ed448 is not supported by this version of OpenSSL.",
59 _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
60 )
61 return backend.ed448_generate_key()
63 @classmethod
64 def from_private_bytes(cls, data: bytes) -> "Ed448PrivateKey":
65 from cryptography.hazmat.backends.openssl.backend import backend
67 if not backend.ed448_supported():
68 raise UnsupportedAlgorithm(
69 "ed448 is not supported by this version of OpenSSL.",
70 _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
71 )
73 return backend.ed448_load_private_bytes(data)
75 @abc.abstractmethod
76 def public_key(self) -> Ed448PublicKey:
77 """
78 The Ed448PublicKey derived from the private key.
79 """
81 @abc.abstractmethod
82 def sign(self, data: bytes) -> bytes:
83 """
84 Signs the data.
85 """
87 @abc.abstractmethod
88 def private_bytes(
89 self,
90 encoding: _serialization.Encoding,
91 format: _serialization.PrivateFormat,
92 encryption_algorithm: _serialization.KeySerializationEncryption,
93 ) -> bytes:
94 """
95 The serialized bytes of the private key.
96 """
98 def private_bytes_raw(self) -> bytes:
99 """
100 The raw bytes of the private key.
101 Equivalent to private_bytes(Raw, Raw, NoEncryption()).
102 """
103 return self.private_bytes(
104 _serialization.Encoding.Raw,
105 _serialization.PrivateFormat.Raw,
106 _serialization.NoEncryption(),
107 )