From 414e4eb55750090ccae9001797a89351bf2722fd Mon Sep 17 00:00:00 2001 From: pukkamustard Date: Mon, 30 Nov 2020 09:37:01 +0100 Subject: monocypher: add more useful type specifications --- src/monocypher.erl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/monocypher.erl') diff --git a/src/monocypher.erl b/src/monocypher.erl index acdf488..41c5c24 100644 --- a/src/monocypher.erl +++ b/src/monocypher.erl @@ -16,11 +16,14 @@ %% Authenticated Encryption --spec crypto_lock(binary(), binary(), binary(), binary()) -> binary(). +-type crypto_lock_mac() :: <<_:128>>. +-type crypto_lock_key() :: <<_:256>>. +-type crypto_lock_nonce() :: <<_:192>>. +-spec crypto_lock(crypto_lock_mac(), crypto_lock_key(), crypto_lock_nonce(), binary()) -> binary(). crypto_lock(_,_,_,_) -> not_loaded(?LINE). --spec crypto_unlock(binary(), binary(), binary(), binary()) -> {'ok', binary()} | {'error', integer()}. +-spec crypto_unlock(crypto_lock_key(), crypto_lock_nonce(), crypto_lock_mac(), binary()) -> {'ok', binary()} | {'error', integer()}. crypto_unlock(_,_,_,_) -> not_loaded(?LINE). @@ -30,17 +33,22 @@ crypto_unlock(_,_,_,_) -> crypto_blake2b(_) -> not_loaded(?LINE). --spec crypto_blake2b_general(integer(), binary(), binary()) -> binary(). + +-type crypto_blake2b_hash_size() :: 1..64. +-type crypto_blake2b_key() :: <<_:_*8>>. +-spec crypto_blake2b_general(crypto_blake2b_hash_size(), crypto_blake2b_key(), binary()) -> binary(). crypto_blake2b_general(_,_,_) -> not_loaded(?LINE). %% IETF ChaCha20 --spec crypto_ietf_chacha20(binary(), binary(), binary()) -> binary(). +-type crypto_ietf_chacha20_key() :: <<_:256>>. +-type crypto_ietf_chacha20_nonce() :: <<_:96>>. +-spec crypto_ietf_chacha20(binary(), crypto_ietf_chacha20_key(), crypto_ietf_chacha20_nonce()) -> binary(). crypto_ietf_chacha20(_,_,_) -> not_loaded(?LINE). --spec crypto_ietf_chacha20_ctr(binary(), binary(), binary(), pos_integer()) -> binary(). +-spec crypto_ietf_chacha20_ctr(binary(), crypto_ietf_chacha20_key(), crypto_ietf_chacha20_nonce(), pos_integer()) -> binary(). crypto_ietf_chacha20_ctr(_,_,_,_) -> not_loaded(?LINE). -- cgit v1.2.3