3131-----END EC PRIVATE KEY-----
3232"""
3333
34+ # ES256 signatures generated to test conversion logic
35+ DER_SIGNATURE = (
36+ b"0F\x02 !\x00 \x89 yG\x81 W\x01 \x11 \x9b 0\x08 \xa4 \xd0 \xe3 g([\x07 \xb5 \x01 \xb3 "
37+ b"\x9d \xdf \xd1 \xbc \xed K\x01 \x87 :}\xf2 \x02 !\x00 \xb2 shTA\x00 \x1a \x13 ~\xba "
38+ b"J\xdb \xee m\x12 \x1e \xfe MO\x04 \xb2 [\x86 A\xbd \xc6 hu\x95 3X\x1e "
39+ )
40+ ASN1_SIGNATURE = (
41+ b"\x89 yG\x81 W\x01 \x11 \x9b 0\x08 \xa4 \xd0 \xe3 g([\x07 \xb5 \x01 \xb3 \x9d \xdf "
42+ b"\xd1 \xbc \xed K\x01 \x87 :}\xf2 \xb2 shTA\x00 \x1a \x13 ~\xba J\xdb \xee m\x12 \x1e "
43+ b"\xfe MO\x04 \xb2 [\x86 A\xbd \xc6 hu\x95 3X\x1e "
44+ )
45+
3446
3547def _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+
5480class TestECAlgorithm :
5581
5682 def test_key_from_pem (self ):
0 commit comments