MCPcopy Create free account
hub / github.com/mpdavis/python-jose / TestBackendAesCompatibility

Class TestBackendAesCompatibility

tests/algorithms/test_AES_compat.py:18–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16 CryptographyAESKey is None, reason="Multiple crypto backends not available for backend compatibility tests"
17)
18class TestBackendAesCompatibility:
19 @pytest.mark.parametrize("backend_decrypt", CRYPTO_BACKENDS)
20 @pytest.mark.parametrize("backend_encrypt", CRYPTO_BACKENDS)
21 @pytest.mark.parametrize("algorithm", ALGORITHMS.AES_PSEUDO)
22 def test_encryption_parity(self, backend_encrypt, backend_decrypt, algorithm):
23 if "128" in algorithm:
24 key = b"8slRzzty6dKMaFCP"
25 elif "192" in algorithm:
26 key = b"8slRzzty6dKMaFCP8slRzzty"
27 else:
28 key = b"8slRzzty6dKMaFCP8slRzzty6dKMaFCP"
29
30 key_encrypt = backend_encrypt(key, algorithm)
31 key_decrypt = backend_decrypt(key, algorithm)
32 plain_text = b"test"
33 aad = b"extra data" if "GCM" in algorithm else None
34
35 iv, cipher_text, tag = key_encrypt.encrypt(plain_text, aad)
36
37 # verify decrypt to original plain text
38 actual = key_decrypt.decrypt(cipher_text, iv, aad, tag)
39 assert actual == plain_text
40
41 with pytest.raises(JWEError):
42 key_decrypt.decrypt(b"n" * 64)
43
44 @pytest.mark.parametrize("backend_key_wrap", CRYPTO_BACKENDS)
45 @pytest.mark.parametrize("backend_key_unwrap", CRYPTO_BACKENDS)
46 @pytest.mark.parametrize("algorithm", ALGORITHMS.AES_KW)
47 def test_wrap_parity(self, backend_key_wrap, backend_key_unwrap, algorithm):
48 if "128" in algorithm:
49 key = b"8slRzzty6dKMaFCP"
50 elif "192" in algorithm:
51 key = b"8slRzzty6dKMaFCP8slRzzty"
52 else:
53 key = b"8slRzzty6dKMaFCP8slRzzty6dKMaFCP"
54
55 key_wrap = backend_key_wrap(key, algorithm)
56 key_unwrap = backend_key_unwrap(key, algorithm)
57 plain_text = b"sixteen byte key"
58
59 wrapped_key = key_wrap.wrap_key(plain_text)
60
61 # verify unwrap_key to original plain text
62 actual = key_unwrap.unwrap_key(wrapped_key)
63 assert actual == plain_text
64
65 with pytest.raises(JWEError):
66 key_unwrap.decrypt(b"n" * 64)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…