|
| 1 | +from abc import ABCMeta, abstractmethod |
| 2 | +from typing import Any, Optional, Union |
| 3 | + |
| 4 | +from cryptography.hazmat.primitives.asymmetric.dh import ( |
| 5 | + DHParameterNumbers, |
| 6 | + DHParameters, |
| 7 | + DHPrivateKey, |
| 8 | + DHPrivateNumbers, |
| 9 | + DHPublicKey, |
| 10 | + DHPublicNumbers, |
| 11 | +) |
| 12 | +from cryptography.hazmat.primitives.asymmetric.dsa import ( |
| 13 | + DSAParameterNumbers, |
| 14 | + DSAParameters, |
| 15 | + DSAPrivateKey, |
| 16 | + DSAPrivateNumbers, |
| 17 | + DSAPublicKey, |
| 18 | + DSAPublicNumbers, |
| 19 | +) |
| 20 | +from cryptography.hazmat.primitives.asymmetric.ec import ( |
| 21 | + EllipticCurve, |
| 22 | + EllipticCurvePrivateKey, |
| 23 | + EllipticCurvePrivateNumbers, |
| 24 | + EllipticCurvePublicKey, |
| 25 | + EllipticCurvePublicNumbers, |
| 26 | + EllipticCurveSignatureAlgorithm, |
| 27 | +) |
| 28 | +from cryptography.hazmat.primitives.asymmetric.padding import AsymmetricPadding |
| 29 | +from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPrivateNumbers, RSAPublicKey, RSAPublicNumbers |
| 30 | +from cryptography.hazmat.primitives.ciphers import BlockCipherAlgorithm, CipherAlgorithm, CipherContext |
| 31 | +from cryptography.hazmat.primitives.ciphers.modes import Mode |
| 32 | +from cryptography.hazmat.primitives.hashes import HashAlgorithm, HashContext |
| 33 | +from cryptography.x509 import ( |
| 34 | + Certificate, |
| 35 | + CertificateBuilder, |
| 36 | + CertificateRevocationList, |
| 37 | + CertificateRevocationListBuilder, |
| 38 | + CertificateSigningRequest, |
| 39 | + CertificateSigningRequestBuilder, |
| 40 | + Name, |
| 41 | + RevokedCertificate, |
| 42 | + RevokedCertificateBuilder, |
| 43 | +) |
| 44 | + |
| 45 | +class CipherBackend(metaclass=ABCMeta): |
| 46 | + @abstractmethod |
| 47 | + def cipher_supported(self, cipher: CipherAlgorithm, mode: Mode) -> bool: ... |
| 48 | + @abstractmethod |
| 49 | + def create_symmetric_encryption_ctx(self, cipher: CipherAlgorithm, mode: Mode) -> CipherContext: ... |
| 50 | + @abstractmethod |
| 51 | + def create_symmetric_decryption_ctx(self, cipher: CipherAlgorithm, mode: Mode) -> CipherContext: ... |
| 52 | + |
| 53 | +class CMACBackend(metaclass=ABCMeta): |
| 54 | + @abstractmethod |
| 55 | + def cmac_algorithm_supported(self, algorithm: BlockCipherAlgorithm) -> bool: ... |
| 56 | + @abstractmethod |
| 57 | + def create_cmac_ctx(self, algorithm: BlockCipherAlgorithm) -> Any: ... |
| 58 | + |
| 59 | +class DERSerializationBackend(metaclass=ABCMeta): |
| 60 | + @abstractmethod |
| 61 | + def load_der_parameters(self, data: bytes) -> Any: ... |
| 62 | + @abstractmethod |
| 63 | + def load_der_private_key(self, data: bytes, password: Optional[bytes]) -> Any: ... |
| 64 | + @abstractmethod |
| 65 | + def load_der_public_key(self, data: bytes) -> Any: ... |
| 66 | + |
| 67 | +class DHBackend(metaclass=ABCMeta): |
| 68 | + @abstractmethod |
| 69 | + def dh_parameters_supported(self, p: int, g: int, q: Optional[int]) -> bool: ... |
| 70 | + @abstractmethod |
| 71 | + def dh_x942_serialization_supported(self) -> bool: ... |
| 72 | + @abstractmethod |
| 73 | + def generate_dh_parameters(self, generator: int, key_size: int) -> DHParameters: ... |
| 74 | + @abstractmethod |
| 75 | + def generate_dh_private_key(self, parameters: DHParameters) -> DHPrivateKey: ... |
| 76 | + @abstractmethod |
| 77 | + def generate_dh_private_key_and_parameters(self, generator: int, key_size: int) -> DHPrivateKey: ... |
| 78 | + @abstractmethod |
| 79 | + def load_dh_parameter_numbers(self, numbers: DHParameterNumbers) -> DHParameters: ... |
| 80 | + @abstractmethod |
| 81 | + def load_dh_private_numbers(self, numbers: DHPrivateNumbers) -> DHPrivateKey: ... |
| 82 | + @abstractmethod |
| 83 | + def load_dh_public_numbers(self, numbers: DHPublicNumbers) -> DHPublicKey: ... |
| 84 | + |
| 85 | +class DSABackend(metaclass=ABCMeta): |
| 86 | + @abstractmethod |
| 87 | + def dsa_hash_supported(self, algorithm: HashAlgorithm) -> bool: ... |
| 88 | + @abstractmethod |
| 89 | + def dsa_parameters_supported(self, p: int, q: int, g: int) -> bool: ... |
| 90 | + @abstractmethod |
| 91 | + def generate_dsa_parameters(self, key_size: int) -> DSAParameters: ... |
| 92 | + @abstractmethod |
| 93 | + def generate_dsa_private_key(self, parameters: DSAParameters) -> DSAPrivateKey: ... |
| 94 | + @abstractmethod |
| 95 | + def generate_dsa_private_key_and_parameters(self, key_size: int) -> DSAPrivateKey: ... |
| 96 | + @abstractmethod |
| 97 | + def load_dsa_parameter_numbers(self, numbers: DSAParameterNumbers) -> DSAParameters: ... |
| 98 | + @abstractmethod |
| 99 | + def load_dsa_private_numbers(self, numbers: DSAPrivateNumbers) -> DSAPrivateKey: ... |
| 100 | + @abstractmethod |
| 101 | + def load_dsa_public_numbers(self, numbers: DSAPublicNumbers) -> DSAPublicKey: ... |
| 102 | + |
| 103 | +class EllipticCurveBackend(metaclass=ABCMeta): |
| 104 | + @abstractmethod |
| 105 | + def derive_elliptic_curve_private_key(self, private_value: int, curve: EllipticCurve) -> EllipticCurvePrivateKey: ... |
| 106 | + @abstractmethod |
| 107 | + def elliptic_curve_signature_algorithm_supported( |
| 108 | + self, signature_algorithm: EllipticCurveSignatureAlgorithm, curve: EllipticCurve |
| 109 | + ) -> bool: ... |
| 110 | + @abstractmethod |
| 111 | + def elliptic_curve_supported(self, curve: EllipticCurve) -> bool: ... |
| 112 | + @abstractmethod |
| 113 | + def generate_elliptic_curve_private_key(self, curve: EllipticCurve) -> EllipticCurvePrivateKey: ... |
| 114 | + @abstractmethod |
| 115 | + def load_elliptic_curve_private_numbers(self, numbers: EllipticCurvePrivateNumbers) -> EllipticCurvePrivateKey: ... |
| 116 | + @abstractmethod |
| 117 | + def load_elliptic_curve_public_numbers(self, numbers: EllipticCurvePublicNumbers) -> EllipticCurvePublicKey: ... |
| 118 | + |
| 119 | +class HMACBackend(metaclass=ABCMeta): |
| 120 | + @abstractmethod |
| 121 | + def create_hmac_ctx(self, key: bytes, algorithm: HashAlgorithm) -> HashContext: ... |
| 122 | + @abstractmethod |
| 123 | + def cmac_algorithm_supported(self, algorithm: HashAlgorithm) -> bool: ... |
| 124 | + |
| 125 | +class HashBackend(metaclass=ABCMeta): |
| 126 | + @abstractmethod |
| 127 | + def create_hash_ctx(self, algorithm: HashAlgorithm) -> HashContext: ... |
| 128 | + @abstractmethod |
| 129 | + def hash_supported(self, algorithm: HashAlgorithm) -> bool: ... |
| 130 | + |
| 131 | +class PBKDF2HMACBackend(metaclass=ABCMeta): |
| 132 | + @abstractmethod |
| 133 | + def derive_pbkdf2_hmac( |
| 134 | + self, algorithm: HashAlgorithm, length: int, salt: bytes, iterations: int, key_material: bytes |
| 135 | + ) -> bytes: ... |
| 136 | + @abstractmethod |
| 137 | + def pbkdf2_hmac_supported(self, algorithm: HashAlgorithm) -> bool: ... |
| 138 | + |
| 139 | +class PEMSerializationBackend(metaclass=ABCMeta): |
| 140 | + @abstractmethod |
| 141 | + def load_pem_parameters(self, data: bytes) -> Any: ... |
| 142 | + @abstractmethod |
| 143 | + def load_pem_private_key(self, data: bytes, password: Optional[bytes]) -> Any: ... |
| 144 | + @abstractmethod |
| 145 | + def load_pem_public_key(self, data: bytes) -> Any: ... |
| 146 | + |
| 147 | +class RSABackend(metaclass=ABCMeta): |
| 148 | + @abstractmethod |
| 149 | + def generate_rsa_parameters_supported(self, public_exponent: int, key_size: int) -> bool: ... |
| 150 | + @abstractmethod |
| 151 | + def generate_rsa_private_key(self, public_exponent: int, key_size: int) -> RSAPrivateKey: ... |
| 152 | + @abstractmethod |
| 153 | + def load_rsa_public_numbers(self, numbers: RSAPublicNumbers) -> RSAPublicKey: ... |
| 154 | + @abstractmethod |
| 155 | + def load_rsa_private_numbers(self, numbers: RSAPrivateNumbers) -> RSAPrivateKey: ... |
| 156 | + @abstractmethod |
| 157 | + def rsa_padding_supported(self, padding: AsymmetricPadding) -> bool: ... |
| 158 | + |
| 159 | +class ScryptBackend(metaclass=ABCMeta): |
| 160 | + @abstractmethod |
| 161 | + def derive_scrypt(self, key_material: bytes, salt: bytes, length: int, n: int, r: int, p: int) -> bytes: ... |
| 162 | + |
| 163 | +class X509Backend(metaclass=ABCMeta): |
| 164 | + @abstractmethod |
| 165 | + def create_x509_certificate( |
| 166 | + self, |
| 167 | + builder: CertificateBuilder, |
| 168 | + private_key: Union[DSAPrivateKey, EllipticCurvePrivateKey, RSAPrivateKey], |
| 169 | + algorithm: HashAlgorithm, |
| 170 | + ) -> Certificate: ... |
| 171 | + @abstractmethod |
| 172 | + def create_x509_crl( |
| 173 | + self, |
| 174 | + builder: CertificateRevocationListBuilder, |
| 175 | + private_key: Union[DSAPrivateKey, EllipticCurvePrivateKey, RSAPrivateKey], |
| 176 | + algorithm: HashAlgorithm, |
| 177 | + ) -> CertificateRevocationList: ... |
| 178 | + @abstractmethod |
| 179 | + def create_x509_csr( |
| 180 | + self, |
| 181 | + builder: CertificateSigningRequestBuilder, |
| 182 | + private_key: Union[DSAPrivateKey, EllipticCurvePrivateKey, RSAPrivateKey], |
| 183 | + algorithm: HashAlgorithm, |
| 184 | + ) -> CertificateSigningRequest: ... |
| 185 | + @abstractmethod |
| 186 | + def create_x509_revoked_certificate(self, builder: RevokedCertificateBuilder) -> RevokedCertificate: ... |
| 187 | + @abstractmethod |
| 188 | + def load_der_x509_certificate(self, data: bytes) -> Certificate: ... |
| 189 | + @abstractmethod |
| 190 | + def load_der_x509_csr(self, data: bytes) -> CertificateSigningRequest: ... |
| 191 | + @abstractmethod |
| 192 | + def load_pem_x509_certificate(self, data: bytes) -> Certificate: ... |
| 193 | + @abstractmethod |
| 194 | + def load_pem_x509_csr(self, data: bytes) -> CertificateSigningRequest: ... |
| 195 | + @abstractmethod |
| 196 | + def x509_name_bytes(self, name: Name) -> bytes: ... |
0 commit comments