コード例 #1
0
 def test_ecdh_direct_hkdf_apply_without_context(self, sender_key_es):
     sender = ECDH_DirectHKDF({1: -25}, {4: b"01"},
                              sender_key=sender_key_es)
     with pytest.raises(ValueError) as err:
         sender.apply(recipient_key=recipient_public_key)
         pytest.fail("apply() should fail.")
     assert "context should be set." in str(err.value)
コード例 #2
0
 def test_ecdh_direct_hkdf_apply_without_recipient_key(self, sender_key_es):
     sender = ECDH_DirectHKDF({1: -25}, {4: b"01"},
                              sender_key=sender_key_es)
     with pytest.raises(ValueError) as err:
         sender.apply(context={"alg": "A128GCM"})
         pytest.fail("apply() should fail.")
     assert "recipient_key should be set in advance." in str(err.value)
コード例 #3
0
    def test_ecdh_direct_hkdf_apply_and_extract_with_ecdh_es(
            self, sender_key_es, recipient_public_key, recipient_private_key):
        sender = ECDH_DirectHKDF({1: -25}, {4: b"01"},
                                 sender_key=sender_key_es)
        enc_key = sender.apply(recipient_key=recipient_public_key,
                               context={"alg": "A128GCM"})

        encoded = sender.to_list()
        recipient = Recipient.from_list(encoded)
        decoded_key = recipient.extract(recipient_private_key,
                                        context={"alg": "A128GCM"})
        assert enc_key.key == decoded_key.key
コード例 #4
0
 def test_ecdh_direct_hkdf_constructor_with_invalid_alg(self):
     with pytest.raises(ValueError) as err:
         ECDH_DirectHKDF({1: -1}, {4: b"01"})
         pytest.fail("ECDH_DirectHKDF() should fail.")
     assert "Unknown alg(1) for ECDH with HKDF: -1." in str(err.value)
コード例 #5
0
 def test_ecdh_direct_hkdf_constructor_with_ecdh_ss_512(self):
     ctx = ECDH_DirectHKDF({1: -28}, {4: b"01"})
     assert ctx.alg == -28
     assert ctx.kid == b"01"
コード例 #6
0
 def test_ecdh_direct_hkdf_constructor_with_ecdh_es_256(self):
     ctx = ECDH_DirectHKDF({1: -25}, {4: b"01"})
     assert isinstance(ctx, ECDH_DirectHKDF)
     assert ctx.alg == -25
     assert ctx.kid == b"01"