Rework to use pysodium, document and test further
Still on key_pair, sign and verify
This commit is contained in:
@ -1,9 +1,31 @@
|
||||
"""Cryptography primitives test module."""
|
||||
|
||||
from hypercore_crypto import key_pair
|
||||
import pytest
|
||||
|
||||
from hypercore_crypto import key_pair, sign, verify
|
||||
from pysodium import crypto_sign_PUBLICKEYBYTES, crypto_sign_SECRETKEYBYTES
|
||||
|
||||
|
||||
def test_key_pair_seed_length():
|
||||
with pytest.raises(ValueError) as exception:
|
||||
key_pair(b'wrong')
|
||||
assert 'must be of length' in str(exception)
|
||||
|
||||
|
||||
def test_key_pair_length():
|
||||
public_key, secret_key = key_pair()
|
||||
assert len(public_key) == 32
|
||||
assert len(secret_key) == 64
|
||||
assert len(public_key) == crypto_sign_PUBLICKEYBYTES
|
||||
assert len(secret_key) == crypto_sign_SECRETKEYBYTES
|
||||
|
||||
|
||||
def test_sign():
|
||||
message = b'mymessage'
|
||||
_, secret_key = key_pair()
|
||||
assert message not in sign(message, secret_key)
|
||||
|
||||
|
||||
def test_verify():
|
||||
message = b'mymessage'
|
||||
public_key, secret_key = key_pair()
|
||||
signature = sign(message, secret_key)
|
||||
assert verify(message, signature, public_key)
|
||||
|
Reference in New Issue
Block a user