Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cwt/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import copy
import json
from typing import Any, Dict, List, Optional, Union

Expand Down Expand Up @@ -150,7 +151,7 @@ def to_cis(context: Dict[str, Any], recipient_alg: Optional[int] = None) -> List
if "protected" in context["supp_pub"]:
if not isinstance(context["supp_pub"]["protected"], dict):
raise ValueError("supp_pub.protected should be dict.")
protected = to_cose_header(context["supp_pub"]["protected"])
protected = to_cose_header(copy.deepcopy(context["supp_pub"]["protected"]))
supp_pub[1] = cbor2.dumps(protected)
if "other" in context["supp_pub"]:
if not isinstance(context["supp_pub"]["other"], str):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_recipient.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ def test_recipient_new_with_invalid_arg(self, protected, unprotected, msg):
pytest.fail("Recipient() should fail.")
assert msg in str(err.value)

def test_recipient_new_does_not_modify_protected(self, rpk1, rsk1):
protected = {}
unprotected = {"alg": "ECDH-ES+A128KW"}
kdf_context = {
"alg": "A128KW",
"supp_pub": {
"key_data_length": 128,
"protected": protected,
"other": "test",
},
}
_ = Recipient.new(
protected=protected, unprotected=unprotected, sender_key=rsk1, recipient_key=rpk1, context=kdf_context
)
assert protected == {}

def test_recipient_from_jwk_with_str(self):
recipient = Recipient.new(unprotected={"alg": "direct"})
assert isinstance(recipient, RecipientInterface)
Expand Down
Loading