MCPcopy
hub / github.com/pyca/cryptography / test_rsa_pkcs1_encryption

Function test_rsa_pkcs1_encryption

tests/wycheproof/test_rsa.py:277–307  ·  view source on GitHub ↗
(backend, wycheproof)

Source from the content-addressed store, hash-verified

275 "rsa_pkcs1_4096_test.json",
276)
277def 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 )

Callers

nothing calls this directly

Calls 3

cache_value_to_groupMethod · 0.80
unhexlifyMethod · 0.80
decryptMethod · 0.45

Tested by

no test coverage detected