|
1 | 1 | from unittest import TestCase |
2 | 2 | from joserfc import jwe |
3 | | -from joserfc.jwe import GeneralJSONEncryption |
| 3 | +from joserfc.jwe import GeneralJSONEncryption, FlattenedJSONEncryption |
4 | 4 | from joserfc.jwk import KeySet, RSAKey, ECKey, OctKey |
5 | 5 | from joserfc.errors import ( |
6 | 6 | DecodeError, |
@@ -72,3 +72,19 @@ def test_decode_multiple_recipients(self): |
72 | 72 | key3, |
73 | 73 | registry=registry, |
74 | 74 | ) |
| 75 | + |
| 76 | + def test_flattened_encryption(self): |
| 77 | + key = OctKey.generate_key(128) |
| 78 | + protected = {"enc": "A128CBC-HS256"} |
| 79 | + plaintext = b"hello world" |
| 80 | + obj0 = FlattenedJSONEncryption(protected, plaintext) |
| 81 | + obj0.add_recipient({"alg": "A128KW"}) |
| 82 | + value = jwe.encrypt_json(obj0, key) |
| 83 | + obj1 = jwe.decrypt_json(value, key) |
| 84 | + self.assertEqual(obj1.plaintext, plaintext) |
| 85 | + |
| 86 | + obj2 = FlattenedJSONEncryption(protected, plaintext) |
| 87 | + obj2.add_recipient({"alg": "A128KW"}, key) |
| 88 | + value = jwe.encrypt_json(obj0, None) |
| 89 | + obj3 = jwe.decrypt_json(value, key) |
| 90 | + self.assertEqual(obj3.plaintext, plaintext) |
0 commit comments