Skip to content

Commit cea6ae8

Browse files
committed
add tests to verify der/asn1 conversions
1 parent 04ef8b5 commit cea6ae8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/algorithms/test_EC.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
-----END EC PRIVATE KEY-----
3232
"""
3333

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

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

5365

66+
@pytest.mark.cryptography
67+
@pytest.mark.skipif(CryptographyECKey is None, reason="pyca/cryptography backend not available")
68+
def test_cryptograhy_der_to_asn1():
69+
key = CryptographyECKey(private_key, ALGORITHMS.ES256)
70+
assert key._der_to_asn1(DER_SIGNATURE) == ASN1_SIGNATURE
71+
72+
73+
@pytest.mark.cryptography
74+
@pytest.mark.skipif(CryptographyECKey is None, reason="pyca/cryptography backend not available")
75+
def test_cryptograhy_asn1_to_der():
76+
key = CryptographyECKey(private_key, ALGORITHMS.ES256)
77+
assert key._asn1_to_der(ASN1_SIGNATURE) == DER_SIGNATURE
78+
79+
5480
class TestECAlgorithm:
5581

5682
def test_key_from_pem(self):

0 commit comments

Comments
 (0)