Skip to content

Commit cd6bc63

Browse files
authored
Merge pull request #439 from kentakayama/allow-key-wrap-in-context
Allow AES-KW algorithm in context
2 parents 6f699f2 + f2a8706 commit cd6bc63

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

cwt/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .const import (
88
COSE_ALGORITHMS_CEK,
9+
COSE_ALGORITHMS_KEY_WRAP,
910
COSE_ALGORITHMS_MAC,
1011
COSE_ALGORITHMS_SYMMETRIC,
1112
COSE_HEADER_PARAMETERS,
@@ -121,7 +122,11 @@ def to_cis(context: Dict[str, Any], recipient_alg: Optional[int] = None) -> List
121122
if "alg" not in context:
122123
raise ValueError("alg not found.")
123124
# if context["alg"] not in COSE_NAMED_ALGORITHMS_SUPPORTED:
124-
if context["alg"] not in COSE_ALGORITHMS_CEK and context["alg"] not in COSE_ALGORITHMS_MAC:
125+
if (
126+
context["alg"] not in COSE_ALGORITHMS_CEK
127+
and context["alg"] not in COSE_ALGORITHMS_MAC
128+
and context["alg"] not in COSE_ALGORITHMS_KEY_WRAP
129+
):
125130
raise ValueError(f'Unsupported or unknown alg for context information: {context["alg"]}.')
126131
alg = COSE_NAMED_ALGORITHMS_SUPPORTED[context["alg"]]
127132
res.append(alg)

tests/test_utils.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ def test_to_cis_without_supp_pub_other(self):
7272
)
7373
assert isinstance(res, list)
7474

75+
def test_to_cis_without_apu_apv_supp_pub_other(self):
76+
res = to_cis(
77+
{
78+
"alg": "A128KW",
79+
"supp_pub": {
80+
"key_data_length": 128,
81+
"protected": {"alg": "ECDH-ES+A128KW"},
82+
"other": "SUIT Payload Encryption",
83+
},
84+
}
85+
)
86+
assert isinstance(res, list)
87+
7588
@pytest.mark.parametrize(
7689
"invalid, msg",
7790
[
@@ -131,14 +144,6 @@ def test_to_cis_without_supp_pub_other(self):
131144
{"alg": "AES-CCM-16-64-128", "supp_pub": {"other": 123}},
132145
"supp_pub.other should be str.",
133146
),
134-
(
135-
{"alg": "A128KW"},
136-
"Unsupported or unknown alg for context information: A128KW.",
137-
),
138-
(
139-
{"alg": "A128KW", "supp_pub": {}},
140-
"Unsupported or unknown alg for context information: A128KW.",
141-
),
142147
],
143148
)
144149
def test_to_cis_with_invalid_args(self, invalid, msg):

0 commit comments

Comments
 (0)