Rework to use pysodium, document and test further

Still on key_pair, sign and verify
This commit is contained in:
Luke Murphy
2019-10-05 14:11:14 +02:00
parent 1072d2662a
commit c11909012a
4 changed files with 49 additions and 27 deletions

View File

@ -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)