Skip to content

Commit aaae0ae

Browse files
committed
Add external_aad and aad_context to Recipient.apply.
1 parent e51f001 commit aaae0ae

7 files changed

Lines changed: 32 additions & 2 deletions

File tree

cwt/recipient_algs/aes_key_wrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def apply(
4141
recipient_key: Optional[COSEKeyInterface] = None,
4242
salt: Optional[bytes] = None,
4343
context: Optional[Union[List[Any], Dict[str, Any]]] = None,
44+
external_aad: bytes = b"",
45+
aad_context: str = "Enc_Recipient",
4446
) -> COSEKeyInterface:
4547
if not key:
4648
raise ValueError("key should be set.")

cwt/recipient_algs/direct_hkdf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def apply(
8888
recipient_key: Optional[COSEKeyInterface] = None,
8989
salt: Optional[bytes] = None,
9090
context: Optional[Union[List[Any], Dict[str, Any]]] = None,
91+
external_aad: bytes = b"",
92+
aad_context: str = "Enc_Recipient",
9193
) -> COSEKeyInterface:
9294

9395
if not key:

cwt/recipient_algs/direct_key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def apply(
2323
recipient_key: Optional[COSEKeyInterface] = None,
2424
salt: Optional[bytes] = None,
2525
context: Optional[Union[List[Any], Dict[str, Any]]] = None,
26+
external_aad: bytes = b"",
27+
aad_context: str = "Enc_Recipient",
2628
) -> COSEKeyInterface:
2729
if not key:
2830
raise ValueError("key should be set.")

cwt/recipient_algs/ecdh_aes_key_wrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def apply(
5555
recipient_key: Optional[COSEKeyInterface] = None,
5656
salt: Optional[bytes] = None,
5757
context: Optional[Union[List[Any], Dict[str, Any]]] = None,
58+
external_aad: bytes = b"",
59+
aad_context: str = "Enc_Recipient",
5860
) -> COSEKeyInterface:
5961

6062
if not key:

cwt/recipient_algs/ecdh_direct_hkdf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def apply(
6464
recipient_key: Optional[COSEKeyInterface] = None,
6565
salt: Optional[bytes] = None,
6666
context: Optional[Union[List[Any], Dict[str, Any]]] = None,
67+
external_aad: bytes = b"",
68+
aad_context: str = "Enc_Recipient",
6769
) -> COSEKeyInterface:
6870

6971
if not self._sender_key:

cwt/recipient_algs/hpke.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,25 @@ def apply(
3636
recipient_key: Optional[COSEKeyInterface] = None,
3737
salt: Optional[bytes] = None,
3838
context: Optional[Union[List[Any], Dict[str, Any]]] = None,
39+
external_aad: bytes = b"",
40+
aad_context: str = "Enc_Recipient",
3941
) -> COSEKeyInterface:
42+
# if not key:
43+
# raise ValueError("key should be set.")
4044
if not recipient_key:
4145
raise ValueError("recipient_key should be set.")
42-
46+
# if recipient_key.kid:
47+
# self._protected[4] = key.kid
4348
self._recipient_key = recipient_key
4449
self._kem_key = self._to_kem_key(recipient_key)
50+
# enc_structure = ["Enc_Recipient", self._dumps(self._protected), external_aad]
51+
# aad = self._dumps(enc_structure)
52+
# enc, sender = self._suite.create_sender_context(self._kem_key)
53+
# self._unprotected[-4][4] = enc
54+
# try:
55+
# self._ciphertext = sender.seal(key.key, aad=aad)
56+
# except Exception as err:
57+
# raise EncodeError("Failed to seal.") from err
4558
return self._recipient_key
4659

4760
def to_list(self, payload: bytes = b"", external_aad: bytes = b"", aad_context: str = "Enc_Recipient") -> List[Any]:

cwt/recipient_interface.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def apply(
160160
recipient_key: Optional[COSEKeyInterface] = None,
161161
salt: Optional[bytes] = None,
162162
context: Optional[Union[List[Any], Dict[str, Any]]] = None,
163+
external_aad: bytes = b"",
164+
aad_context: str = "Enc_Recipient",
163165
) -> COSEKeyInterface:
164166
"""
165167
Applies a COSEKey as a material to prepare a MAC/encryption key with
@@ -179,6 +181,9 @@ def apply(
179181
salt (Optional[bytes]): A salt used for deriving a key.
180182
context (Optional[Union[List[Any], Dict[str, Any]]]): Context
181183
information structure.
184+
external_aad (bytes): External additional authenticated data for AEAD.
185+
aad_context (bytes): An additional authenticated data context to build
186+
an Enc_structure internally.
182187
Returns:
183188
COSEKeyInterface: A generated key or passed-throug key which is used
184189
as ``key`` parameter of COSE.encode_* functions.
@@ -233,7 +238,9 @@ def decrypt(
233238
key (COSEKeyInterface): The external key to be used for extracting the key.
234239
alg (Optional[int]): The algorithm of the key extracted.
235240
context (Optional[Union[List[Any], Dict[str, Any]]]): Context information structure.
236-
external_aad (bytes): External additional authenticated data.
241+
external_aad (bytes): External additional authenticated data for AEAD.
242+
aad_context (bytes): An additional authenticated data context to build
243+
an Enc_structure internally.
237244
Returns:
238245
bytes: The decrypted plain text.
239246
Raises:

0 commit comments

Comments
 (0)