diff options
| author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2020-08-26 21:59:43 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-26 22:59:43 -0400 |
| commit | bda138768ae1231481a1c9a2f6afcbf016d934f1 (patch) | |
| tree | 4e3dc9ccf71206b1bfecb01781e135e74fc93040 /tests | |
| parent | 0b2435940eaa5be72cf385b59b35221c40152049 (diff) | |
| download | cryptography-bda138768ae1231481a1c9a2f6afcbf016d934f1.tar.gz | |
new black, actually slightly different than the old black (#5429)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/hazmat/backends/test_openssl.py | 6 | ||||
| -rw-r--r-- | tests/hazmat/backends/test_openssl_memleak.py | 5 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_block.py | 26 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_dh.py | 6 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_dsa.py | 3 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_ec.py | 3 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_hashes.py | 36 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_hmac.py | 4 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_hmac_vectors.py | 30 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_pbkdf2hmac_vectors.py | 5 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_pkcs12.py | 6 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 24 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_serialization.py | 69 | ||||
| -rw-r--r-- | tests/test_fernet.py | 14 | ||||
| -rw-r--r-- | tests/test_utils.py | 3 | ||||
| -rw-r--r-- | tests/wycheproof/test_rsa.py | 6 | ||||
| -rw-r--r-- | tests/x509/test_x509.py | 68 | ||||
| -rw-r--r-- | tests/x509/test_x509_ext.py | 6 |
18 files changed, 237 insertions, 83 deletions
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index acec247df..2f7e7bebf 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -91,7 +91,11 @@ class TestOpenSSL(object): type(mode), lambda backend, cipher, mode: backend._ffi.NULL, ) - cipher = Cipher(DummyCipherAlgorithm(), mode, backend=b,) + cipher = Cipher( + DummyCipherAlgorithm(), + mode, + backend=b, + ) with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER): cipher.encryptor() diff --git a/tests/hazmat/backends/test_openssl_memleak.py b/tests/hazmat/backends/test_openssl_memleak.py index 96b5f2ae0..d8bc8660a 100644 --- a/tests/hazmat/backends/test_openssl_memleak.py +++ b/tests/hazmat/backends/test_openssl_memleak.py @@ -135,7 +135,10 @@ def assert_no_memory_leaks(s, argv=[]): # Shell out to a fresh Python process because OpenSSL does not allow you to # install new memory hooks after the first malloc/free occurs. proc = subprocess.Popen( - argv, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + argv, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ) try: proc.wait() diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py index f827eee3b..593199315 100644 --- a/tests/hazmat/primitives/test_block.py +++ b/tests/hazmat/primitives/test_block.py @@ -136,10 +136,12 @@ class TestCipherContext(object): @pytest.mark.requires_backend_interface(interface=CipherBackend) class TestAEADCipherContext(object): test_aead_exceptions = generate_aead_exception_test( - algorithms.AES, modes.GCM, + algorithms.AES, + modes.GCM, ) test_aead_tag_exceptions = generate_aead_tag_exception_test( - algorithms.AES, modes.GCM, + algorithms.AES, + modes.GCM, ) @@ -148,31 +150,41 @@ class TestModeValidation(object): def test_cbc(self, backend): with pytest.raises(ValueError): Cipher( - algorithms.AES(b"\x00" * 16), modes.CBC(b"abc"), backend, + algorithms.AES(b"\x00" * 16), + modes.CBC(b"abc"), + backend, ) def test_ofb(self, backend): with pytest.raises(ValueError): Cipher( - algorithms.AES(b"\x00" * 16), modes.OFB(b"abc"), backend, + algorithms.AES(b"\x00" * 16), + modes.OFB(b"abc"), + backend, ) def test_cfb(self, backend): with pytest.raises(ValueError): Cipher( - algorithms.AES(b"\x00" * 16), modes.CFB(b"abc"), backend, + algorithms.AES(b"\x00" * 16), + modes.CFB(b"abc"), + backend, ) def test_cfb8(self, backend): with pytest.raises(ValueError): Cipher( - algorithms.AES(b"\x00" * 16), modes.CFB8(b"abc"), backend, + algorithms.AES(b"\x00" * 16), + modes.CFB8(b"abc"), + backend, ) def test_ctr(self, backend): with pytest.raises(ValueError): Cipher( - algorithms.AES(b"\x00" * 16), modes.CTR(b"abc"), backend, + algorithms.AES(b"\x00" * 16), + modes.CTR(b"abc"), + backend, ) def test_gcm(self): diff --git a/tests/hazmat/primitives/test_dh.py b/tests/hazmat/primitives/test_dh.py index 29b0e3ef6..63a7c642e 100644 --- a/tests/hazmat/primitives/test_dh.py +++ b/tests/hazmat/primitives/test_dh.py @@ -654,7 +654,8 @@ class TestDHPublicKeySerialization(object): ) pub_key = loader_func(key_bytes, backend) serialized = pub_key.public_bytes( - encoding, serialization.PublicFormat.SubjectPublicKeyInfo, + encoding, + serialization.PublicFormat.SubjectPublicKeyInfo, ) assert serialized == key_bytes @@ -780,7 +781,8 @@ class TestDHParameterSerialization(object): ) parameters = loader_func(param_bytes, backend) serialized = parameters.parameter_bytes( - encoding, serialization.ParameterFormat.PKCS3, + encoding, + serialization.ParameterFormat.PKCS3, ) assert serialized == param_bytes diff --git a/tests/hazmat/primitives/test_dsa.py b/tests/hazmat/primitives/test_dsa.py index 695069a32..bda275064 100644 --- a/tests/hazmat/primitives/test_dsa.py +++ b/tests/hazmat/primitives/test_dsa.py @@ -936,7 +936,8 @@ class TestDSAPEMPublicKeySerialization(object): ) key = loader_func(key_bytes, backend) serialized = key.public_bytes( - encoding, serialization.PublicFormat.SubjectPublicKeyInfo, + encoding, + serialization.PublicFormat.SubjectPublicKeyInfo, ) assert serialized == key_bytes diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py index be330c112..8361306f7 100644 --- a/tests/hazmat/primitives/test_ec.py +++ b/tests/hazmat/primitives/test_ec.py @@ -951,7 +951,8 @@ class TestEllipticCurvePEMPublicKeySerialization(object): ) key = loader_func(key_bytes, backend) serialized = key.public_bytes( - encoding, serialization.PublicFormat.SubjectPublicKeyInfo, + encoding, + serialization.PublicFormat.SubjectPublicKeyInfo, ) assert serialized == key_bytes diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index 256769212..eadd0febf 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -52,7 +52,10 @@ class TestHashContext(object): ) @pytest.mark.requires_backend_interface(interface=HashBackend) class TestSHA1(object): - test_sha1 = generate_base_hash_test(hashes.SHA1(), digest_size=20,) + test_sha1 = generate_base_hash_test( + hashes.SHA1(), + digest_size=20, + ) @pytest.mark.supported( @@ -61,7 +64,10 @@ class TestSHA1(object): ) @pytest.mark.requires_backend_interface(interface=HashBackend) class TestSHA224(object): - test_sha224 = generate_base_hash_test(hashes.SHA224(), digest_size=28,) + test_sha224 = generate_base_hash_test( + hashes.SHA224(), + digest_size=28, + ) @pytest.mark.supported( @@ -70,7 +76,10 @@ class TestSHA224(object): ) @pytest.mark.requires_backend_interface(interface=HashBackend) class TestSHA256(object): - test_sha256 = generate_base_hash_test(hashes.SHA256(), digest_size=32,) + test_sha256 = generate_base_hash_test( + hashes.SHA256(), + digest_size=32, + ) @pytest.mark.supported( @@ -79,7 +88,10 @@ class TestSHA256(object): ) @pytest.mark.requires_backend_interface(interface=HashBackend) class TestSHA384(object): - test_sha384 = generate_base_hash_test(hashes.SHA384(), digest_size=48,) + test_sha384 = generate_base_hash_test( + hashes.SHA384(), + digest_size=48, + ) @pytest.mark.supported( @@ -88,7 +100,10 @@ class TestSHA384(object): ) @pytest.mark.requires_backend_interface(interface=HashBackend) class TestSHA512(object): - test_sha512 = generate_base_hash_test(hashes.SHA512(), digest_size=64,) + test_sha512 = generate_base_hash_test( + hashes.SHA512(), + digest_size=64, + ) @pytest.mark.supported( @@ -97,7 +112,10 @@ class TestSHA512(object): ) @pytest.mark.requires_backend_interface(interface=HashBackend) class TestMD5(object): - test_md5 = generate_base_hash_test(hashes.MD5(), digest_size=16,) + test_md5 = generate_base_hash_test( + hashes.MD5(), + digest_size=16, + ) @pytest.mark.supported( @@ -109,7 +127,8 @@ class TestMD5(object): @pytest.mark.requires_backend_interface(interface=HashBackend) class TestBLAKE2b(object): test_blake2b = generate_base_hash_test( - hashes.BLAKE2b(digest_size=64), digest_size=64, + hashes.BLAKE2b(digest_size=64), + digest_size=64, ) def test_invalid_digest_size(self, backend): @@ -132,7 +151,8 @@ class TestBLAKE2b(object): @pytest.mark.requires_backend_interface(interface=HashBackend) class TestBLAKE2s(object): test_blake2s = generate_base_hash_test( - hashes.BLAKE2s(digest_size=32), digest_size=32, + hashes.BLAKE2s(digest_size=32), + digest_size=32, ) def test_invalid_digest_size(self, backend): diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py index e60ae16f2..7ea931aca 100644 --- a/tests/hazmat/primitives/test_hmac.py +++ b/tests/hazmat/primitives/test_hmac.py @@ -27,7 +27,9 @@ from ...utils import raises_unsupported_algorithm ) @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHMACCopy(object): - test_copy = generate_base_hmac_test(hashes.MD5(),) + test_copy = generate_base_hmac_test( + hashes.MD5(), + ) @pytest.mark.requires_backend_interface(interface=HMACBackend) diff --git a/tests/hazmat/primitives/test_hmac_vectors.py b/tests/hazmat/primitives/test_hmac_vectors.py index b46342736..b39df1a75 100644 --- a/tests/hazmat/primitives/test_hmac_vectors.py +++ b/tests/hazmat/primitives/test_hmac_vectors.py @@ -22,7 +22,10 @@ from ...utils import load_hash_vectors @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHMACMD5(object): test_hmac_md5 = generate_hmac_test( - load_hash_vectors, "HMAC", ["rfc-2202-md5.txt"], hashes.MD5(), + load_hash_vectors, + "HMAC", + ["rfc-2202-md5.txt"], + hashes.MD5(), ) @@ -33,7 +36,10 @@ class TestHMACMD5(object): @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHMACSHA1(object): test_hmac_sha1 = generate_hmac_test( - load_hash_vectors, "HMAC", ["rfc-2202-sha1.txt"], hashes.SHA1(), + load_hash_vectors, + "HMAC", + ["rfc-2202-sha1.txt"], + hashes.SHA1(), ) @@ -44,7 +50,10 @@ class TestHMACSHA1(object): @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHMACSHA224(object): test_hmac_sha224 = generate_hmac_test( - load_hash_vectors, "HMAC", ["rfc-4231-sha224.txt"], hashes.SHA224(), + load_hash_vectors, + "HMAC", + ["rfc-4231-sha224.txt"], + hashes.SHA224(), ) @@ -55,7 +64,10 @@ class TestHMACSHA224(object): @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHMACSHA256(object): test_hmac_sha256 = generate_hmac_test( - load_hash_vectors, "HMAC", ["rfc-4231-sha256.txt"], hashes.SHA256(), + load_hash_vectors, + "HMAC", + ["rfc-4231-sha256.txt"], + hashes.SHA256(), ) @@ -66,7 +78,10 @@ class TestHMACSHA256(object): @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHMACSHA384(object): test_hmac_sha384 = generate_hmac_test( - load_hash_vectors, "HMAC", ["rfc-4231-sha384.txt"], hashes.SHA384(), + load_hash_vectors, + "HMAC", + ["rfc-4231-sha384.txt"], + hashes.SHA384(), ) @@ -77,7 +92,10 @@ class TestHMACSHA384(object): @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHMACSHA512(object): test_hmac_sha512 = generate_hmac_test( - load_hash_vectors, "HMAC", ["rfc-4231-sha512.txt"], hashes.SHA512(), + load_hash_vectors, + "HMAC", + ["rfc-4231-sha512.txt"], + hashes.SHA512(), ) diff --git a/tests/hazmat/primitives/test_pbkdf2hmac_vectors.py b/tests/hazmat/primitives/test_pbkdf2hmac_vectors.py index 13bdbc5f3..4b97b0d13 100644 --- a/tests/hazmat/primitives/test_pbkdf2hmac_vectors.py +++ b/tests/hazmat/primitives/test_pbkdf2hmac_vectors.py @@ -20,5 +20,8 @@ from ...utils import load_nist_vectors @pytest.mark.requires_backend_interface(interface=PBKDF2HMACBackend) class TestPBKDF2HMACSHA1(object): test_pbkdf2_sha1 = generate_pbkdf2_test( - load_nist_vectors, "KDF", ["rfc-6070-PBKDF2-SHA1.txt"], hashes.SHA1(), + load_nist_vectors, + "KDF", + ["rfc-6070-PBKDF2-SHA1.txt"], + hashes.SHA1(), ) diff --git a/tests/hazmat/primitives/test_pkcs12.py b/tests/hazmat/primitives/test_pkcs12.py index 466dac5c1..297483e2f 100644 --- a/tests/hazmat/primitives/test_pkcs12.py +++ b/tests/hazmat/primitives/test_pkcs12.py @@ -262,6 +262,10 @@ class TestPKCS12Creation(object): cert, key = _load_ca(backend) with pytest.raises(ValueError) as exc: serialize_key_and_certificates( - None, key, cert, None, DummyKeySerializationEncryption(), + None, + key, + cert, + None, + DummyKeySerializationEncryption(), ) assert str(exc.value) == "Unsupported key encryption type" diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index b23a176fe..bfb946ee5 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -1103,7 +1103,9 @@ class TestRSAVerification(object): signature, b"sign me", padding.PSS( - mgf=padding.MGF1(algorithm=hashes.SHA1(),), + mgf=padding.MGF1( + algorithm=hashes.SHA1(), + ), salt_length=1000000, ), hashes.SHA1(), @@ -1163,7 +1165,9 @@ class TestRSAPSSMGF1Verification(object): ], hashes.SHA1(), lambda params, hash_alg: padding.PSS( - mgf=padding.MGF1(algorithm=hash_alg,), + mgf=padding.MGF1( + algorithm=hash_alg, + ), salt_length=params["salt_length"], ), ) @@ -1188,7 +1192,9 @@ class TestRSAPSSMGF1Verification(object): ], hashes.SHA224(), lambda params, hash_alg: padding.PSS( - mgf=padding.MGF1(algorithm=hash_alg,), + mgf=padding.MGF1( + algorithm=hash_alg, + ), salt_length=params["salt_length"], ), ) @@ -1213,7 +1219,9 @@ class TestRSAPSSMGF1Verification(object): ], hashes.SHA256(), lambda params, hash_alg: padding.PSS( - mgf=padding.MGF1(algorithm=hash_alg,), + mgf=padding.MGF1( + algorithm=hash_alg, + ), salt_length=params["salt_length"], ), ) @@ -1238,7 +1246,9 @@ class TestRSAPSSMGF1Verification(object): ], hashes.SHA384(), lambda params, hash_alg: padding.PSS( - mgf=padding.MGF1(algorithm=hash_alg,), + mgf=padding.MGF1( + algorithm=hash_alg, + ), salt_length=params["salt_length"], ), ) @@ -1263,7 +1273,9 @@ class TestRSAPSSMGF1Verification(object): ], hashes.SHA512(), lambda params, hash_alg: padding.PSS( - mgf=padding.MGF1(algorithm=hash_alg,), + mgf=padding.MGF1( + algorithm=hash_alg, + ), salt_length=params["salt_length"], ), ) diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 46694c648..2f56711d5 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -1467,11 +1467,15 @@ class TestEd25519Serialization(object): key = ed25519.Ed25519PrivateKey.generate() with pytest.raises(ValueError): key.private_bytes( - Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.PEM, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) with pytest.raises(ValueError): key.private_bytes( - Encoding.DER, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.DER, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) @@ -1543,11 +1547,15 @@ class TestX448Serialization(object): key = x448.X448PrivateKey.generate() with pytest.raises(ValueError): key.private_bytes( - Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.PEM, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) with pytest.raises(ValueError): key.private_bytes( - Encoding.DER, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.DER, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) def test_openssh_serialization_unsupported(self, backend): @@ -1630,11 +1638,15 @@ class TestX25519Serialization(object): key = x25519.X25519PrivateKey.generate() with pytest.raises(ValueError): key.private_bytes( - Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.PEM, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) with pytest.raises(ValueError): key.private_bytes( - Encoding.DER, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.DER, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) def test_openssh_serialization_unsupported(self, backend): @@ -1717,28 +1729,34 @@ class TestEd448Serialization(object): key = ed448.Ed448PrivateKey.generate() with pytest.raises(ValueError): key.private_bytes( - Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.PEM, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) with pytest.raises(ValueError): key.private_bytes( - Encoding.DER, PrivateFormat.TraditionalOpenSSL, NoEncryption(), + Encoding.DER, + PrivateFormat.TraditionalOpenSSL, + NoEncryption(), ) def test_openssh_serialization_unsupported(self, backend): key = ed448.Ed448PrivateKey.generate() with pytest.raises(ValueError): key.public_key().public_bytes( - Encoding.OpenSSH, PublicFormat.OpenSSH, + Encoding.OpenSSH, + PublicFormat.OpenSSH, ) with pytest.raises(ValueError): key.private_bytes( - Encoding.PEM, PrivateFormat.OpenSSH, NoEncryption(), + Encoding.PEM, + PrivateFormat.OpenSSH, + NoEncryption(), ) class TestDHSerialization(object): - """Test all options with least-supported key type. - """ + """Test all options with least-supported key type.""" def test_dh_public_key(self, backend): data = load_vectors_from_file( @@ -1951,7 +1969,9 @@ class TestOpenSSHSerialization(object): if password: encryption = BestAvailableEncryption(password) priv_data2 = private_key.private_bytes( - Encoding.PEM, PrivateFormat.OpenSSH, encryption, + Encoding.PEM, + PrivateFormat.OpenSSH, + encryption, ) private_key2 = load_ssh_private_key(priv_data2, password, backend) assert ( @@ -2062,7 +2082,10 @@ class TestOpenSSHSerialization(object): kdfoptions=b"", nkeys=1, pub_type=b"ecdsa-sha2-nistp256", - pub_fields=(b"nistp256", b"\x04" * 65,), + pub_fields=( + b"nistp256", + b"\x04" * 65, + ), priv_type=None, priv_fields=(b"nistp256", b"\x04" * 65, b"\x7F" * 32), comment=b"comment", @@ -2073,8 +2096,7 @@ class TestOpenSSHSerialization(object): footer=b"-----END OPENSSH PRIVATE KEY-----\n", cut=8192, ): - """Create private key file - """ + """Create private key file""" if not priv_type: priv_type = pub_type @@ -2157,7 +2179,10 @@ class TestOpenSSHSerialization(object): def test_ssh_errors_pubpriv_mismatch(self, backend): # ecdsa public-private mismatch data = self.make_file( - pub_fields=(b"nistp256", b"\x04" + b"\x05" * 64,) + pub_fields=( + b"nistp256", + b"\x04" + b"\x05" * 64, + ) ) with pytest.raises(ValueError): load_ssh_private_key(data, None, backend) @@ -2187,14 +2212,20 @@ class TestOpenSSHSerialization(object): data = self.make_file( pub_type=b"ssh-ed25519", pub_fields=(pk1,), - priv_fields=(pk1, sk + pk2,), + priv_fields=( + pk1, + sk + pk2, + ), ) with pytest.raises(ValueError): load_ssh_private_key(data, None, backend) data = self.make_file( pub_type=b"ssh-ed25519", pub_fields=(pk1,), - priv_fields=(pk2, sk + pk1,), + priv_fields=( + pk2, + sk + pk1, + ), ) with pytest.raises(ValueError): load_ssh_private_key(data, None, backend) diff --git a/tests/test_fernet.py b/tests/test_fernet.py index 094e3e346..38409b03e 100644 --- a/tests/test_fernet.py +++ b/tests/test_fernet.py @@ -50,7 +50,8 @@ def test_default_backend(): ) class TestFernet(object): @json_parametrize( - ("secret", "now", "iv", "src", "token"), "generate.json", + ("secret", "now", "iv", "src", "token"), + "generate.json", ) def test_generate(self, secret, now, iv, src, token, backend): f = Fernet(secret.encode("ascii"), backend=backend) @@ -62,7 +63,8 @@ class TestFernet(object): assert actual_token == token.encode("ascii") @json_parametrize( - ("secret", "now", "src", "ttl_sec", "token"), "verify.json", + ("secret", "now", "src", "ttl_sec", "token"), + "verify.json", ) def test_verify( self, secret, now, src, ttl_sec, token, backend, monkeypatch @@ -70,7 +72,9 @@ class TestFernet(object): f = Fernet(secret.encode("ascii"), backend=backend) current_time = calendar.timegm(iso8601.parse_date(now).utctimetuple()) payload = f.decrypt_at_time( - token.encode("ascii"), ttl=ttl_sec, current_time=current_time, + token.encode("ascii"), + ttl=ttl_sec, + current_time=current_time, ) assert payload == src.encode("ascii") monkeypatch.setattr(time, "time", lambda: current_time) @@ -83,7 +87,9 @@ class TestFernet(object): current_time = calendar.timegm(iso8601.parse_date(now).utctimetuple()) with pytest.raises(InvalidToken): f.decrypt_at_time( - token.encode("ascii"), ttl=ttl_sec, current_time=current_time, + token.encode("ascii"), + ttl=ttl_sec, + current_time=current_time, ) monkeypatch.setattr(time, "time", lambda: current_time) with pytest.raises(InvalidToken): diff --git a/tests/test_utils.py b/tests/test_utils.py index e0b93c55d..d6afa3b34 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -362,7 +362,8 @@ def test_load_hash_vectors_bad_data(): def test_load_vectors_from_file(): vectors = load_vectors_from_file( - os.path.join("ciphers", "Blowfish", "bf-cfb.txt"), load_nist_vectors, + os.path.join("ciphers", "Blowfish", "bf-cfb.txt"), + load_nist_vectors, ) assert vectors == [ { diff --git a/tests/wycheproof/test_rsa.py b/tests/wycheproof/test_rsa.py index c71f05adf..1262b5885 100644 --- a/tests/wycheproof/test_rsa.py +++ b/tests/wycheproof/test_rsa.py @@ -136,7 +136,8 @@ def test_rsa_pss_signature(backend, wycheproof): if digest is None or mgf_digest is None: pytest.skip( "PSS with digest={} and MGF digest={} not supported".format( - wycheproof.testgroup["sha"], wycheproof.testgroup["mgfSha"], + wycheproof.testgroup["sha"], + wycheproof.testgroup["mgfSha"], ) ) @@ -212,7 +213,8 @@ def test_rsa_oaep_encryption(backend, wycheproof): if not backend.rsa_padding_supported(padding_algo): pytest.skip( "OAEP with digest={} and MGF digest={} not supported".format( - wycheproof.testgroup["sha"], wycheproof.testgroup["mgfSha"], + wycheproof.testgroup["sha"], + wycheproof.testgroup["mgfSha"], ) ) diff --git a/tests/x509/test_x509.py b/tests/x509/test_x509.py index 3e63dde74..11c80816c 100644 --- a/tests/x509/test_x509.py +++ b/tests/x509/test_x509.py @@ -380,7 +380,10 @@ class TestCertificateRevocationList(object): # Encode it to PEM and load it back. crl = x509.load_pem_x509_crl( - crl.public_bytes(encoding=serialization.Encoding.PEM,), backend + crl.public_bytes( + encoding=serialization.Encoding.PEM, + ), + backend, ) assert len(crl) == 0 @@ -396,7 +399,10 @@ class TestCertificateRevocationList(object): # Encode it to DER and load it back. crl = x509.load_der_x509_crl( - crl.public_bytes(encoding=serialization.Encoding.DER,), backend + crl.public_bytes( + encoding=serialization.Encoding.DER, + ), + backend, ) assert len(crl) == 12 @@ -1141,7 +1147,10 @@ class TestRSACertificate(object): # Encode it to PEM and load it back. cert = x509.load_pem_x509_certificate( - cert.public_bytes(encoding=serialization.Encoding.PEM,), backend + cert.public_bytes( + encoding=serialization.Encoding.PEM, + ), + backend, ) # We should recover what we had to start with. @@ -1164,7 +1173,10 @@ class TestRSACertificate(object): # Encode it to DER and load it back. cert = x509.load_der_x509_certificate( - cert.public_bytes(encoding=serialization.Encoding.DER,), backend + cert.public_bytes( + encoding=serialization.Encoding.DER, + ), + backend, ) # We should recover what we had to start with. @@ -1429,7 +1441,10 @@ class TestRSACertificateRequest(object): # Encode it to PEM and load it back. request = x509.load_pem_x509_csr( - request.public_bytes(encoding=serialization.Encoding.PEM,), backend + request.public_bytes( + encoding=serialization.Encoding.PEM, + ), + backend, ) # We should recover what we had to start with. @@ -1456,7 +1471,10 @@ class TestRSACertificateRequest(object): # Encode it to DER and load it back. request = x509.load_der_x509_csr( - request.public_bytes(encoding=serialization.Encoding.DER,), backend + request.public_bytes( + encoding=serialization.Encoding.DER, + ), + backend, ) # We should recover what we had to start with. @@ -1660,7 +1678,8 @@ class TestRSACertificateRequest(object): ) .public_key(subject_private_key.public_key()) .add_extension( - x509.BasicConstraints(ca=False, path_length=None), True, + x509.BasicConstraints(ca=False, path_length=None), + True, ) .add_extension( x509.SubjectAlternativeName( @@ -2336,12 +2355,14 @@ class TestCertificateBuilder(object): def test_add_extension_checks_for_duplicates(self): builder = x509.CertificateBuilder().add_extension( - x509.BasicConstraints(ca=False, path_length=None), True, + x509.BasicConstraints(ca=False, path_length=None), + True, ) with pytest.raises(ValueError): builder.add_extension( - x509.BasicConstraints(ca=False, path_length=None), True, + x509.BasicConstraints(ca=False, path_length=None), + True, ) def test_add_invalid_extension_type(self): @@ -2513,7 +2534,8 @@ class TestCertificateBuilder(object): ) .public_key(subject_private_key.public_key()) .add_extension( - x509.BasicConstraints(ca=False, path_length=None), True, + x509.BasicConstraints(ca=False, path_length=None), + True, ) .add_extension( x509.SubjectAlternativeName( @@ -2563,7 +2585,8 @@ class TestCertificateBuilder(object): ) .public_key(subject_private_key.public_key()) .add_extension( - x509.BasicConstraints(ca=False, path_length=None), True, + x509.BasicConstraints(ca=False, path_length=None), + True, ) .add_extension( x509.SubjectAlternativeName( @@ -2615,7 +2638,8 @@ class TestCertificateBuilder(object): ) .public_key(subject_private_key.public_key()) .add_extension( - x509.BasicConstraints(ca=False, path_length=None), True, + x509.BasicConstraints(ca=False, path_length=None), + True, ) .add_extension( x509.SubjectAlternativeName( @@ -2712,7 +2736,8 @@ class TestCertificateBuilder(object): ) .public_key(subject_private_key.public_key()) .add_extension( - x509.BasicConstraints(ca=False, path_length=None), True, + x509.BasicConstraints(ca=False, path_length=None), + True, ) .add_extension( x509.SubjectAlternativeName( @@ -3292,7 +3317,8 @@ class TestCertificateBuilder(object): "unrecognized", [ x509.UnrecognizedExtension( - x509.ObjectIdentifier("1.2.3.4.5"), b"abcdef", + x509.ObjectIdentifier("1.2.3.4.5"), + b"abcdef", ) ], ) @@ -3740,11 +3766,13 @@ class TestCertificateSigningRequestBuilder(object): def test_add_duplicate_extension(self): builder = x509.CertificateSigningRequestBuilder().add_extension( - x509.BasicConstraints(True, 2), critical=True, + x509.BasicConstraints(True, 2), + critical=True, ) with pytest.raises(ValueError): builder.add_extension( - x509.BasicConstraints(True, 2), critical=True, + x509.BasicConstraints(True, 2), + critical=True, ) def test_set_invalid_subject(self): @@ -4001,7 +4029,10 @@ class TestCertificateSigningRequestBuilder(object): .subject_name( x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u"SAN")]) ) - .add_extension(san, critical=False,) + .add_extension( + san, + critical=False, + ) .sign(private_key, hashes.SHA256(), backend) ) @@ -5207,8 +5238,7 @@ class TestEd448Certificate(object): @pytest.mark.requires_backend_interface(interface=X509Backend) class TestSignatureRejection(object): - """Test if signing rejects DH keys properly. - """ + """Test if signing rejects DH keys properly.""" def load_key(self, backend): data = load_vectors_from_file( diff --git a/tests/x509/test_x509_ext.py b/tests/x509/test_x509_ext.py index a89c01dad..2cd216fb6 100644 --- a/tests/x509/test_x509_ext.py +++ b/tests/x509/test_x509_ext.py @@ -2749,7 +2749,8 @@ class TestPolicyConstraintsExtension(object): assert ext.critical is True assert ext.value == x509.PolicyConstraints( - require_explicit_policy=None, inhibit_policy_mapping=0, + require_explicit_policy=None, + inhibit_policy_mapping=0, ) def test_require_explicit_policy(self, backend): @@ -2763,7 +2764,8 @@ class TestPolicyConstraintsExtension(object): ) assert ext.critical is True assert ext.value == x509.PolicyConstraints( - require_explicit_policy=1, inhibit_policy_mapping=None, + require_explicit_policy=1, + inhibit_policy_mapping=None, ) |
