def test_ecdh_aes_key_wrap_extract_without_context(self): enc_key = COSEKey.from_symmetric_key(alg="ChaCha20/Poly1305") ctx = ECDH_AESKeyWrap({1: -29}, {4: b"01"}) with pytest.raises(ValueError) as err: ctx.extract(enc_key, alg="ChaCha20/Poly1305") pytest.fail("extract() should fail.") assert "context should be set." in str(err.value)
def test_ecdh_aes_key_wrap_apply_without_context(self, sender_key_es): enc_key = COSEKey.from_symmetric_key(alg="ChaCha20/Poly1305") sender = ECDH_AESKeyWrap({1: -29}, {4: b"01"}, sender_key=sender_key_es) with pytest.raises(ValueError) as err: sender.apply(enc_key, recipient_key=recipient_public_key) pytest.fail("apply() should fail.") assert "context should be set." in str(err.value)
def test_ecdh_aes_key_wrap_apply_without_key(self, sender_key_es): sender = ECDH_AESKeyWrap({1: -29}, {4: b"01"}, sender_key=sender_key_es) with pytest.raises(ValueError) as err: sender.apply(recipient_key=recipient_public_key, context={"alg": "A128GCM"}) pytest.fail("apply() should fail.") assert "key should be set." in str(err.value)
def test_ecdh_aes_key_wrap_apply_without_recipient_key( self, sender_key_es): enc_key = COSEKey.from_symmetric_key(alg="ChaCha20/Poly1305") sender = ECDH_AESKeyWrap({1: -29}, {4: b"01"}, sender_key=sender_key_es) with pytest.raises(ValueError) as err: sender.apply(enc_key, context={"alg": "A128GCM"}) pytest.fail("apply() should fail.") assert "recipient_key should be set in advance." in str(err.value)
def test_ecdh_aes_key_wrap_encode_and_extract_with_ecdh_es( self, sender_key_es, recipient_public_key, recipient_private_key): enc_key = COSEKey.from_symmetric_key(alg="ChaCha20/Poly1305") sender = ECDH_AESKeyWrap({1: -29}, {4: b"01"}, sender_key=sender_key_es) sender.apply(enc_key, recipient_key=recipient_public_key, context={"alg": "A128GCM"}) assert sender.ciphertext is not None encoded = sender.to_list() recipient = Recipient.from_list(encoded) decoded_key = recipient.extract(recipient_private_key, alg="ChaCha20/Poly1305", context={"alg": "A128GCM"}) assert enc_key.key == decoded_key.key
def test_ecdh_aes_key_wrap_constructor_with_invalid_alg(self): with pytest.raises(ValueError) as err: ECDH_AESKeyWrap({1: -1}, {4: b"01"}) pytest.fail("ECDH_AESKeyWrap() should fail.") assert "Unknown alg(1) for ECDH with key wrap: -1." in str(err.value)
def test_ecdh_aes_key_wrap_constructor_with_ecdh_ss_a256kw(self): ctx = ECDH_AESKeyWrap({1: -34}, {4: b"01"}) assert ctx.alg == -34 assert ctx.kid == b"01"
def test_ecdh_aes_key_wrap_constructor_with_ecdh_es_a128kw(self): ctx = ECDH_AESKeyWrap({1: -29}, {4: b"01"}) assert isinstance(ctx, ECDH_AESKeyWrap) assert ctx.alg == -29 assert ctx.kid == b"01"