From 8d41a94bba7674cfcb120ce7a76b7c3df5c2bb73 Mon Sep 17 00:00:00 2001 From: Mathias Ertl Date: Mon, 15 Mar 2021 23:44:02 +0100 Subject: typehint x509.base (#5899) * start typing x509.base * statically type x509.base * typehint X509Backend interface * typehint at least the X509Backend interface * make _CertificateRevocationList/_CertificateSigningRequest actual subclasses of the interface (as done before for Certificate in f16bff2cb) * tell mypy to ignore lines with deliberately wrong types * signature_hash_algorithm always returns a hash algorithm (it's not optional) * Revert "signature_hash_algorithm always returns a hash algorithm (it's not optional)" This reverts commit f6a5b172b416f8ddea561203c0cf03b55e4ec50e. * hash algorithm is actually optional * fix import style * typehint parsed_version to int, which it de facto always is * minimize changes * break import cycle with conditional imports * ignore access to private members of openssl implementation * reformat code with Black * test check for missing public key --- tests/hazmat/backends/test_openssl.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests/hazmat') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index e6abadbd0..a559998f1 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -478,7 +478,20 @@ class TestOpenSSLSignX509Certificate(object): with pytest.raises(TypeError): backend.create_x509_certificate( - object(), private_key, DummyHashAlgorithm() + object(), # type: ignore[arg-type] + private_key, + DummyHashAlgorithm(), + ) + + def test_builder_requires_public_key(self): + builder = x509.CertificateBuilder() + private_key = RSA_KEY_2048.private_key(backend) + + with pytest.raises(TypeError): + backend.create_x509_certificate( + builder, + private_key, + DummyHashAlgorithm(), ) @@ -488,7 +501,9 @@ class TestOpenSSLSignX509CSR(object): with pytest.raises(TypeError): backend.create_x509_csr( - object(), private_key, DummyHashAlgorithm() + object(), # type: ignore[arg-type] + private_key, + DummyHashAlgorithm(), ) @@ -497,13 +512,19 @@ class TestOpenSSLSignX509CertificateRevocationList(object): private_key = RSA_KEY_2048.private_key(backend) with pytest.raises(TypeError): - backend.create_x509_crl(object(), private_key, hashes.SHA256()) + backend.create_x509_crl( + object(), # type: ignore[arg-type] + private_key, + hashes.SHA256(), + ) class TestOpenSSLCreateRevokedCertificate(object): def test_invalid_builder(self): with pytest.raises(TypeError): - backend.create_x509_revoked_certificate(object()) + backend.create_x509_revoked_certificate( + object() # type: ignore[arg-type] + ) class TestOpenSSLSerializationWithOpenSSL(object): -- cgit v1.2.1