Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py: 73%
45 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:05 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:05 +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.
5from __future__ import annotations
7import abc
9from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
10from cryptography.hazmat.bindings._rust import openssl as rust_openssl
11from cryptography.hazmat.primitives import _serialization
14class Ed448PublicKey(metaclass=abc.ABCMeta):
15 @classmethod
16 def from_public_bytes(cls, data: bytes) -> Ed448PublicKey:
17 from cryptography.hazmat.backends.openssl.backend import backend
19 if not backend.ed448_supported():
20 raise UnsupportedAlgorithm(
21 "ed448 is not supported by this version of OpenSSL.",
22 _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
23 )
25 return backend.ed448_load_public_bytes(data)
27 @abc.abstractmethod
28 def public_bytes(
29 self,
30 encoding: _serialization.Encoding,
31 format: _serialization.PublicFormat,
32 ) -> bytes:
33 """
34 The serialized bytes of the public key.
35 """
37 @abc.abstractmethod
38 def public_bytes_raw(self) -> bytes:
39 """
40 The raw bytes of the public key.
41 Equivalent to public_bytes(Raw, Raw).
42 """
44 @abc.abstractmethod
45 def verify(self, signature: bytes, data: bytes) -> None:
46 """
47 Verify the signature.
48 """
50 @abc.abstractmethod
51 def __eq__(self, other: object) -> bool:
52 """
53 Checks equality.
54 """
57if hasattr(rust_openssl, "ed448"):
58 Ed448PublicKey.register(rust_openssl.ed448.Ed448PublicKey)
61class Ed448PrivateKey(metaclass=abc.ABCMeta):
62 @classmethod
63 def generate(cls) -> Ed448PrivateKey:
64 from cryptography.hazmat.backends.openssl.backend import backend
66 if not backend.ed448_supported():
67 raise UnsupportedAlgorithm(
68 "ed448 is not supported by this version of OpenSSL.",
69 _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
70 )
71 return backend.ed448_generate_key()
73 @classmethod
74 def from_private_bytes(cls, data: bytes) -> Ed448PrivateKey:
75 from cryptography.hazmat.backends.openssl.backend import backend
77 if not backend.ed448_supported():
78 raise UnsupportedAlgorithm(
79 "ed448 is not supported by this version of OpenSSL.",
80 _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
81 )
83 return backend.ed448_load_private_bytes(data)
85 @abc.abstractmethod
86 def public_key(self) -> Ed448PublicKey:
87 """
88 The Ed448PublicKey derived from the private key.
89 """
91 @abc.abstractmethod
92 def sign(self, data: bytes) -> bytes:
93 """
94 Signs the data.
95 """
97 @abc.abstractmethod
98 def private_bytes(
99 self,
100 encoding: _serialization.Encoding,
101 format: _serialization.PrivateFormat,
102 encryption_algorithm: _serialization.KeySerializationEncryption,
103 ) -> bytes:
104 """
105 The serialized bytes of the private key.
106 """
108 @abc.abstractmethod
109 def private_bytes_raw(self) -> bytes:
110 """
111 The raw bytes of the private key.
112 Equivalent to private_bytes(Raw, Raw, NoEncryption()).
113 """
116if hasattr(rust_openssl, "x448"):
117 Ed448PrivateKey.register(rust_openssl.ed448.Ed448PrivateKey)