Skip to content
Prev Previous commit
Next Next commit
add tests to verify der/asn1 conversions
  • Loading branch information
mattsb42-aws committed Dec 25, 2018
commit cea6ae82f31c0fea863f2bc28a17ba31ef3e61cb
26 changes: 26 additions & 0 deletions tests/algorithms/test_EC.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
-----END EC PRIVATE KEY-----
"""

# ES256 signatures generated to test conversion logic
DER_SIGNATURE = (
b"0F\x02!\x00\x89yG\x81W\x01\x11\x9b0\x08\xa4\xd0\xe3g([\x07\xb5\x01\xb3"
b"\x9d\xdf \xd1\xbc\xedK\x01\x87:}\xf2\x02!\x00\xb2shTA\x00\x1a\x13~\xba"
b"J\xdb\xeem\x12\x1e\xfeMO\x04\xb2[\x86A\xbd\xc6hu\x953X\x1e"
)
ASN1_SIGNATURE = (
b"\x89yG\x81W\x01\x11\x9b0\x08\xa4\xd0\xe3g([\x07\xb5\x01\xb3\x9d\xdf "
b"\xd1\xbc\xedK\x01\x87:}\xf2\xb2shTA\x00\x1a\x13~\xbaJ\xdb\xeem\x12\x1e"
b"\xfeMO\x04\xb2[\x86A\xbd\xc6hu\x953X\x1e"
)


def _backend_exception_types():
"""Build the backend exception types based on available backends."""
Expand All @@ -51,6 +63,20 @@ def test_key_from_ecdsa():
assert not ECKey(key, ALGORITHMS.ES256).is_public()


@pytest.mark.cryptography
@pytest.mark.skipif(CryptographyECKey is None, reason="pyca/cryptography backend not available")
def test_cryptograhy_der_to_asn1():
key = CryptographyECKey(private_key, ALGORITHMS.ES256)
assert key._der_to_asn1(DER_SIGNATURE) == ASN1_SIGNATURE


@pytest.mark.cryptography
@pytest.mark.skipif(CryptographyECKey is None, reason="pyca/cryptography backend not available")
def test_cryptograhy_asn1_to_der():
key = CryptographyECKey(private_key, ALGORITHMS.ES256)
assert key._asn1_to_der(ASN1_SIGNATURE) == DER_SIGNATURE


class TestECAlgorithm:

def test_key_from_pem(self):
Expand Down