|
2 | 2 | # SPDX-License-Identifier: Apache-2.0. |
3 | 3 |
|
4 | 4 |
|
5 | | -from awscrt.io import LogLevel, init_logging |
6 | 5 | from test import NativeResourceTest |
7 | 6 | from awscrt.crypto import Hash, RSA, RSAEncryptionAlgorithm, RSASignatureAlgorithm, ED25519, ED25519ExportFormat, EC, ECType, ECRawSignature |
8 | 7 | import base64 |
@@ -388,6 +387,25 @@ def test_ec_asn1_signing_roundtrip(self): |
388 | 387 |
|
389 | 388 | self.assertTrue(ec.verify(digest, signature)) |
390 | 389 |
|
| 390 | + def test_ec_signature_decode_pair(self): |
| 391 | + |
| 392 | + signature = bytes([0x30, 0x42, 0x02, 0x1f, 0x2d, 0x2a, 0xad, 0xce, 0xbc, 0x1b, 0x3f, 0x78, |
| 393 | + 0xec, 0xd1, 0x12, 0x53, 0x9e, 0xc0, 0xe3, 0x44, 0x7b, 0x37, 0x5f, 0x6a, |
| 394 | + 0x99, 0xca, 0x0b, 0x27, 0xb5, 0x4c, 0x31, 0xda, 0x0e, 0x6c, 0x5e, 0x02, |
| 395 | + 0x1f, 0x47, 0xfb, 0x3d, 0xbd, 0xff, 0xb8, 0x58, 0xf4, 0xba, 0x8a, 0x03, |
| 396 | + 0xe7, 0xb4, 0x83, 0xe6, 0xb8, 0xc9, 0x46, 0xa8, 0x0a, 0xd8, 0x46, 0xfa, |
| 397 | + 0x80, 0x0a, 0xd8, 0xca, 0xc5, 0x3f, 0x8e, 0xbd]) |
| 398 | + |
| 399 | + padded_sig = EC.decode_der_signature_to_padded_pair(signature=signature, pad_to=32) |
| 400 | + |
| 401 | + expected_sig = bytes([0x00, 0x2d, 0x2a, 0xad, 0xce, 0xbc, 0x1b, 0x3f, 0x78, 0xec, 0xd1, 0x12, 0x53, |
| 402 | + 0x9e, 0xc0, 0xe3, 0x44, 0x7b, 0x37, 0x5f, 0x6a, 0x99, 0xca, 0x0b, 0x27, 0xb5, |
| 403 | + 0x4c, 0x31, 0xda, 0x0e, 0x6c, 0x5e, 0x00, 0x47, 0xfb, 0x3d, 0xbd, 0xff, 0xb8, |
| 404 | + 0x58, 0xf4, 0xba, 0x8a, 0x03, 0xe7, 0xb4, 0x83, 0xe6, 0xb8, 0xc9, 0x46, 0xa8, |
| 405 | + 0x0a, 0xd8, 0x46, 0xfa, 0x80, 0x0a, 0xd8, 0xca, 0xc5, 0x3f, 0x8e, 0xbd]) |
| 406 | + |
| 407 | + self.assertEqual(padded_sig, expected_sig) |
| 408 | + |
391 | 409 |
|
392 | 410 | if __name__ == '__main__': |
393 | 411 | unittest.main() |
0 commit comments