1
0
forked from QPQ-AG/enoise

Improve type specs

This commit is contained in:
Hans Svensson
2019-01-28 15:05:21 +01:00
parent c06bbae07d
commit 7c7ad54a6a
8 changed files with 32 additions and 13 deletions
+7 -2
View File
@@ -50,11 +50,16 @@ set_nonce(CState = #noise_cs{}, Nonce) ->
CState#noise_cs{ n = Nonce }.
-spec encrypt_with_ad(CState :: state(), AD :: binary(), PlainText :: binary()) ->
{ok, state(), binary()}.
{ok, state(), binary()} | {error, term()}.
encrypt_with_ad(CState = #noise_cs{ k = empty }, _AD, PlainText) ->
{ok, CState, PlainText};
encrypt_with_ad(CState = #noise_cs{ k = K, n = N, cipher = Cipher }, AD, PlainText) ->
{ok, CState#noise_cs{ n = N+1 }, enoise_crypto:encrypt(Cipher, K, N, AD, PlainText)}.
case enoise_crypto:encrypt(Cipher, K, N, AD, PlainText) of
Encrypted when is_binary(Encrypted) ->
{ok, CState#noise_cs{ n = N+1 }, Encrypted};
Err = {error, _} ->
Err
end.
-spec decrypt_with_ad(CState :: state(), AD :: binary(), CipherText :: binary()) ->
{ok, state(), binary()} | {error, term()}.