Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py: 64%
33 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +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 @abc.abstractmethod
36 def verify(self, signature: bytes, data: bytes) -> None:
37 """
38 Verify the signature.
39 """
42class Ed448PrivateKey(metaclass=abc.ABCMeta):
43 @classmethod
44 def generate(cls) -> "Ed448PrivateKey":
45 from cryptography.hazmat.backends.openssl.backend import backend
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()
54 @classmethod
55 def from_private_bytes(cls, data: bytes) -> "Ed448PrivateKey":
56 from cryptography.hazmat.backends.openssl.backend import backend
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 )
64 return backend.ed448_load_private_bytes(data)
66 @abc.abstractmethod
67 def public_key(self) -> Ed448PublicKey:
68 """
69 The Ed448PublicKey derived from the private key.
70 """
72 @abc.abstractmethod
73 def sign(self, data: bytes) -> bytes:
74 """
75 Signs the data.
76 """
78 @abc.abstractmethod
79 def private_bytes(
80 self,
81 encoding: _serialization.Encoding,
82 format: _serialization.PrivateFormat,
83 encryption_algorithm: _serialization.KeySerializationEncryption,
84 ) -> bytes:
85 """
86 The serialized bytes of the private key.
87 """