| 16 | reason="Multiple crypto backends not available for backend compatibility tests", |
| 17 | ) |
| 18 | class TestBackendEcdsaCompatibility: |
| 19 | @pytest.mark.parametrize("BackendSign", [ECDSAECKey, CryptographyECKey]) |
| 20 | @pytest.mark.parametrize("BackendVerify", [ECDSAECKey, CryptographyECKey]) |
| 21 | def test_signing_parity(self, BackendSign, BackendVerify): |
| 22 | key_sign = BackendSign(private_key, ALGORITHMS.ES256) |
| 23 | key_verify = BackendVerify(private_key, ALGORITHMS.ES256).public_key() |
| 24 | |
| 25 | msg = b"test" |
| 26 | sig = key_sign.sign(msg) |
| 27 | |
| 28 | # valid signature |
| 29 | assert key_verify.verify(msg, sig) |
| 30 | |
| 31 | # invalid signature |
| 32 | assert not key_verify.verify(msg, b"n" * 64) |
| 33 | |
| 34 | @pytest.mark.parametrize("BackendFrom", [ECDSAECKey, CryptographyECKey]) |
| 35 | @pytest.mark.parametrize("BackendTo", [ECDSAECKey, CryptographyECKey]) |
| 36 | def test_public_key_to_pem(self, BackendFrom, BackendTo): |
| 37 | key = BackendFrom(private_key, ALGORITHMS.ES256) |
| 38 | key2 = BackendTo(private_key, ALGORITHMS.ES256) |
| 39 | |
| 40 | assert normalize_pem(get_pem_for_key(key.public_key())) == normalize_pem(get_pem_for_key(key2.public_key())) |
| 41 | |
| 42 | @pytest.mark.parametrize("BackendFrom", [ECDSAECKey, CryptographyECKey]) |
| 43 | @pytest.mark.parametrize("BackendTo", [ECDSAECKey, CryptographyECKey]) |
| 44 | def test_private_key_to_pem(self, BackendFrom, BackendTo): |
| 45 | key = BackendFrom(private_key, ALGORITHMS.ES256) |
| 46 | key2 = BackendTo(private_key, ALGORITHMS.ES256) |
| 47 | |
| 48 | assert normalize_pem(get_pem_for_key(key)) == normalize_pem(get_pem_for_key(key2)) |
| 49 | |
| 50 | @pytest.mark.parametrize("BackendFrom", [ECDSAECKey, CryptographyECKey]) |
| 51 | @pytest.mark.parametrize("BackendTo", [ECDSAECKey, CryptographyECKey]) |
| 52 | def test_public_key_load_cycle(self, BackendFrom, BackendTo): |
| 53 | key = BackendFrom(private_key, ALGORITHMS.ES256) |
| 54 | pubkey = key.public_key() |
| 55 | |
| 56 | pub_pem_source = normalize_pem(get_pem_for_key(pubkey)) |
| 57 | |
| 58 | pub_target = BackendTo(pub_pem_source, ALGORITHMS.ES256) |
| 59 | |
| 60 | assert pub_pem_source == normalize_pem(get_pem_for_key(pub_target)) |
| 61 | |
| 62 | @pytest.mark.parametrize("BackendFrom", [ECDSAECKey, CryptographyECKey]) |
| 63 | @pytest.mark.parametrize("BackendTo", [ECDSAECKey, CryptographyECKey]) |
| 64 | def test_private_key_load_cycle(self, BackendFrom, BackendTo): |
| 65 | key = BackendFrom(private_key, ALGORITHMS.ES256) |
| 66 | |
| 67 | pem_source = normalize_pem(get_pem_for_key(key)) |
| 68 | |
| 69 | target = BackendTo(pem_source, ALGORITHMS.ES256) |
| 70 | |
| 71 | assert pem_source == normalize_pem(get_pem_for_key(target)) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…