예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
    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