@@ -186,8 +186,8 @@ def test_cose_hpke_encrypt0_psk_id_wrong_type_header_validation(self):
186186 sender .encode_and_encrypt (
187187 b"This is the content." ,
188188 rpk ,
189- protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0 },
190- unprotected = {COSEHeaders .KID : b"01" , COSEHeaders . PSK_ID : 123 },
189+ protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0 , COSEHeaders . PSK_ID : 123 },
190+ unprotected = {COSEHeaders .KID : b"01" },
191191 )
192192 assert "psk_id (-5) must be bstr." in str (err .value )
193193
@@ -205,8 +205,8 @@ def test_cose_hpke_encrypt0_with_psk_id_roundtrip(self):
205205 encoded = sender .encode_and_encrypt (
206206 b"This is the content." ,
207207 rpk ,
208- protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0 },
209- unprotected = {COSEHeaders .KID : b"01" , COSEHeaders . PSK_ID : b"psk-01" },
208+ protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0 , COSEHeaders . PSK_ID : b"psk-01" },
209+ unprotected = {COSEHeaders .KID : b"01" },
210210 hpke_psk = b"secret-psk" ,
211211 )
212212
@@ -279,8 +279,8 @@ def test_cose_hpke_encrypt0_psk_id_without_psk_should_error_on_encode(self):
279279 sender .encode_and_encrypt (
280280 b"This is the content." ,
281281 rpk ,
282- protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0 },
283- unprotected = {COSEHeaders .KID : b"01" , COSEHeaders . PSK_ID : b"psk-01" },
282+ protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0 , COSEHeaders . PSK_ID : b"psk-01" },
283+ unprotected = {COSEHeaders .KID : b"01" },
284284 )
285285 assert "hpke_psk is required when psk_id (-5) is provided." in str (err .value )
286286
@@ -295,7 +295,8 @@ def test_cose_hpke_encrypt0_psk_id_without_psk_should_error_on_decode(self):
295295 }
296296 )
297297 sender = COSE .new ()
298- # First, produce a base-mode (no psk_id) and then inject psk_id to simulate peer mismatch
298+ # First, produce a base-mode (no psk_id) and then inject psk_id into the
299+ # protected header to simulate peer mismatch
299300 encoded = sender .encode_and_encrypt (
300301 b"This is the content." ,
301302 rpk ,
@@ -304,8 +305,10 @@ def test_cose_hpke_encrypt0_psk_id_without_psk_should_error_on_decode(self):
304305 )
305306 tag = cbor2 .loads (encoded )
306307 p , u , c = tag .value
307- u [- 5 ] = b"psk-01"
308- tampered = cbor2 .dumps (cbor2 .CBORTag (16 , [p , u , c ]))
308+ p_map = cbor2 .loads (p )
309+ p_map [- 5 ] = b"psk-01"
310+ tampered_p = cbor2 .dumps (p_map )
311+ tampered = cbor2 .dumps (cbor2 .CBORTag (16 , [tampered_p , u , c ]))
309312
310313 rsk = COSEKey .from_jwk (
311314 {
@@ -676,8 +679,8 @@ def test_cose_hpke_ke_with_psk_roundtrip(self):
676679 )
677680
678681 r = Recipient .new (
679- protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0_KE },
680- unprotected = {COSEHeaders .KID : b"01" , COSEHeaders . PSK_ID : b"psk-01" },
682+ protected = {COSEHeaders .ALG : COSEAlgs .HPKE_0_KE , COSEHeaders . PSK_ID : b"psk-01" },
683+ unprotected = {COSEHeaders .KID : b"01" },
681684 recipient_key = rpk ,
682685 hpke_psk = b"secret-psk" ,
683686 )
0 commit comments