mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-06-07 22:52:50 -04:00
* API Breaking Change: CryptoSystem.verify() should return bool, and reserve errors for error cases, not validation failures.
* API Breaking Change: VeilidAPI.verify_signatures() returns Option<TypedKeySet> now Fixes #313
This commit is contained in:
parent
8e8ee06fe9
commit
05180252e4
36 changed files with 445 additions and 174 deletions
|
@ -45,6 +45,39 @@ async def test_hash_and_verify_password(api_connection: veilid.VeilidAPI):
|
|||
phash2 = await cs.hash_password(b"abc1234", salt)
|
||||
assert not await cs.verify_password(b"abc12345", phash)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sign_and_verify_signature(api_connection: veilid.VeilidAPI):
|
||||
cs = await api_connection.best_crypto_system()
|
||||
async with cs:
|
||||
kp1 = await cs.generate_key_pair()
|
||||
kp2 = await cs.generate_key_pair()
|
||||
|
||||
# Signature match
|
||||
sig = await cs.sign(kp1.key(), kp1.secret(), b"abc123")
|
||||
assert await cs.verify(kp1.key(), b"abc123", sig)
|
||||
|
||||
# Signature mismatch
|
||||
sig2 = await cs.sign(kp1.key(), kp1.secret(), b"abc1234")
|
||||
assert await cs.verify(kp1.key(), b"abc1234", sig2)
|
||||
assert not await cs.verify(kp1.key(), b"abc12345", sig2)
|
||||
assert not await cs.verify(kp2.key(), b"abc1234", sig2)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sign_and_verify_signatures(api_connection: veilid.VeilidAPI):
|
||||
cs = await api_connection.best_crypto_system()
|
||||
async with cs:
|
||||
kind = await cs.kind()
|
||||
kp1 = await cs.generate_key_pair()
|
||||
|
||||
# Signature match
|
||||
sigs = await api_connection.generate_signatures(b"abc123", [veilid.TypedKeyPair.from_value(kind, kp1)])
|
||||
keys = [veilid.TypedKey.from_value(kind,kp1.key())]
|
||||
assert (await api_connection.verify_signatures(keys, b"abc123", sigs)) == keys
|
||||
|
||||
# Signature mismatch
|
||||
assert (await api_connection.verify_signatures([veilid.TypedKey.from_value(kind,kp1.key())], b"abc1234", sigs)) is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_shared_secret(api_connection: veilid.VeilidAPI):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue