MCPcopy Create free account
hub / github.com/mpdavis/python-jose / TestEncrypt

Class TestEncrypt

tests/test_jwe.py:361–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359
360
361class TestEncrypt:
362 @pytest.mark.skipif(AESKey is None, reason="No AES backend")
363 def test_rfc7516_appendix_b_direct(self, monkeypatch):
364 algorithm = ALGORITHMS.DIR
365 encryption = ALGORITHMS.A128CBC_HS256
366 key = bytes(
367 bytearray(
368 [
369 4,
370 211,
371 31,
372 197,
373 84,
374 157,
375 252,
376 254,
377 11,
378 100,
379 157,
380 250,
381 63,
382 170,
383 106,
384 206,
385 107,
386 124,
387 212,
388 45,
389 111,
390 107,
391 9,
392 219,
393 200,
394 177,
395 0,
396 240,
397 143,
398 156,
399 44,
400 207,
401 ]
402 )
403 )
404 plain_text = b"Live long and prosper."
405 expected_iv = bytes(bytearray([3, 22, 60, 12, 43, 67, 104, 105, 108, 108, 105, 99, 111, 116, 104, 101]))
406
407 for backend in backends:
408 monkeypatch.setattr(backend, "get_random_bytes", lambda x: expected_iv if x == 16 else key)
409
410 expected = b"eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..AxY8DCtDaGlsbGljb3RoZQ.KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY.BIiCkt8mWOVyJOqDMwNqaQ"
411 actual = jwe.encrypt(plain_text, key, encryption, algorithm)
412
413 assert actual == expected
414
415 @pytest.mark.skipif(AESKey is None, reason="No AES backend")
416 @pytest.mark.parametrize("alg", filter(lambda x: x in ALGORITHMS.SUPPORTED, ALGORITHMS.RSA_KW))
417 @pytest.mark.parametrize("enc", filter(lambda x: x in ALGORITHMS.SUPPORTED, ALGORITHMS.AES_ENC))
418 @pytest.mark.parametrize("zip", ZIPS.SUPPORTED)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…