(backend, wycheproof)
| 275 | "rsa_pkcs1_4096_test.json", |
| 276 | ) |
| 277 | def test_rsa_pkcs1_encryption(backend, wycheproof): |
| 278 | key = wycheproof.cache_value_to_group( |
| 279 | "cached_key", |
| 280 | lambda: serialization.load_der_private_key( |
| 281 | binascii.unhexlify(wycheproof.testgroup["privateKeyPkcs8"]), |
| 282 | password=None, |
| 283 | unsafe_skip_rsa_key_validation=True, |
| 284 | ), |
| 285 | ) |
| 286 | assert isinstance(key, rsa.RSAPrivateKey) |
| 287 | |
| 288 | if wycheproof.valid: |
| 289 | pt = key.decrypt( |
| 290 | binascii.unhexlify(wycheproof.testcase["ct"]), padding.PKCS1v15() |
| 291 | ) |
| 292 | assert pt == binascii.unhexlify(wycheproof.testcase["msg"]) |
| 293 | elif backend._lib.Cryptography_HAS_IMPLICIT_RSA_REJECTION: |
| 294 | try: |
| 295 | assert key.decrypt( |
| 296 | binascii.unhexlify(wycheproof.testcase["ct"]), |
| 297 | padding.PKCS1v15(), |
| 298 | ) != binascii.unhexlify(wycheproof.testcase["ct"]) |
| 299 | except ValueError: |
| 300 | # Some raise ValueError due to length mismatch. |
| 301 | pass |
| 302 | else: |
| 303 | with pytest.raises(ValueError): |
| 304 | key.decrypt( |
| 305 | binascii.unhexlify(wycheproof.testcase["ct"]), |
| 306 | padding.PKCS1v15(), |
| 307 | ) |
nothing calls this directly
no test coverage detected