Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py: 61%
31 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 X448PublicKey(metaclass=abc.ABCMeta):
13 @classmethod
14 def from_public_bytes(cls, data: bytes) -> "X448PublicKey":
15 from cryptography.hazmat.backends.openssl.backend import backend
17 if not backend.x448_supported():
18 raise UnsupportedAlgorithm(
19 "X448 is not supported by this version of OpenSSL.",
20 _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
21 )
23 return backend.x448_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 """
36class X448PrivateKey(metaclass=abc.ABCMeta):
37 @classmethod
38 def generate(cls) -> "X448PrivateKey":
39 from cryptography.hazmat.backends.openssl.backend import backend
41 if not backend.x448_supported():
42 raise UnsupportedAlgorithm(
43 "X448 is not supported by this version of OpenSSL.",
44 _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
45 )
46 return backend.x448_generate_key()
48 @classmethod
49 def from_private_bytes(cls, data: bytes) -> "X448PrivateKey":
50 from cryptography.hazmat.backends.openssl.backend import backend
52 if not backend.x448_supported():
53 raise UnsupportedAlgorithm(
54 "X448 is not supported by this version of OpenSSL.",
55 _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
56 )
58 return backend.x448_load_private_bytes(data)
60 @abc.abstractmethod
61 def public_key(self) -> X448PublicKey:
62 """
63 The serialized bytes of the public key.
64 """
66 @abc.abstractmethod
67 def private_bytes(
68 self,
69 encoding: _serialization.Encoding,
70 format: _serialization.PrivateFormat,
71 encryption_algorithm: _serialization.KeySerializationEncryption,
72 ) -> bytes:
73 """
74 The serialized bytes of the private key.
75 """
77 @abc.abstractmethod
78 def exchange(self, peer_public_key: X448PublicKey) -> bytes:
79 """
80 Performs a key exchange operation using the provided peer's public key.
81 """