Finalise the rest of the module

This commit is contained in:
Luke Murphy
2019-10-05 20:28:55 +02:00
parent c11909012a
commit a250b8391c
3 changed files with 118 additions and 19 deletions

View File

@ -1,14 +1,15 @@
"""Cryptography primitives test module."""
import pytest
from hypercore_crypto import key_pair, sign, verify
from merkle_tree_stream import MerkleTreeNode
from pysodium import crypto_sign_PUBLICKEYBYTES, crypto_sign_SECRETKEYBYTES
from hypercore_crypto import data, key_pair, parent, random_bytes, sign, verify
def test_key_pair_seed_length():
with pytest.raises(ValueError) as exception:
key_pair(b'wrong')
key_pair(b'world hello')
assert 'must be of length' in str(exception)
@ -19,13 +20,42 @@ def test_key_pair_length():
def test_sign():
message = b'mymessage'
message = b'hello world'
_, secret_key = key_pair()
assert message not in sign(message, secret_key)
signature = sign(message, secret_key)
assert message not in signature
assert len(signature) == 64
def test_verify():
message = b'mymessage'
message = b'hello world'
public_key, secret_key = key_pair()
signature = sign(message, secret_key)
assert verify(message, signature, public_key)
def test_data_digest():
assert (
data(b'hello world').hex()
== 'ccfa4259ee7c41e411e5770973a49c5ceffb5272d6a37f2c6f2dac2190f7e2b7'
)
def test_random_bytes():
assert len(random_bytes(32)) == 32
def test_parent_digest():
_data = b'hello world'
_parent = parent(
MerkleTreeNode(
index=0, size=11, hash=data(_data), parent=None, data=None
),
MerkleTreeNode(
index=2, size=11, hash=data(_data), parent=None, data=None
),
)
assert (
_parent.hex()
== '43563406adba8b34b133fdca32d0a458c5be769615e01df30e6535ccd3c075f0'
)