From 91916908a029ac7440979ee5c7771b0fe9d2f33e Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Sat, 29 Mar 2025 20:57:45 +0100 Subject: [PATCH] Revert "Update enacl dep and fix some minor details (#1)" This reverts commit 479ec7087031b3b69ca2dd9b5c8e471d0a1125cd. --- rebar.config | 2 +- rebar.lock | 10 ++++++---- src/enoise_cipher_state.erl | 8 ++++++-- src/enoise_crypto.erl | 3 ++- test/enoise_utils.erl | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/rebar.config b/rebar.config index cbb8b16..4407b81 100644 --- a/rebar.config +++ b/rebar.config @@ -1,6 +1,6 @@ {erl_opts, [debug_info]}. {plugins, [rebar3_hex]}. -{deps, [{enacl, {git, "https://git.qpq.swiss/QPQ-AG/enacl.git", {ref, "4eb7ec70"}}}]}. +{deps, [{enacl, "1.1.1"}]}. {profiles, [{test, [{deps, [{jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}}]}]} ]}. diff --git a/rebar.lock b/rebar.lock index a218ebb..22d6918 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,4 +1,6 @@ -[{<<"enacl">>, - {git,"https://git.qpq.swiss/QPQ-AG/enacl.git", - {ref,"4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}, - 0}]. +{"1.2.0", +[{<<"enacl">>,{pkg,<<"enacl">>,<<"1.1.1">>},0}]}. +[ +{pkg_hash,[ + {<<"enacl">>, <<"F65DC64D9BFF2D8A534CB77AEF14DA5E7A2FA148987D87856F79A4745C9C2627">>}]} +]. diff --git a/src/enoise_cipher_state.erl b/src/enoise_cipher_state.erl index e1bea0d..7a5d784 100644 --- a/src/enoise_cipher_state.erl +++ b/src/enoise_cipher_state.erl @@ -54,8 +54,12 @@ set_nonce(CState = #noise_cs{}, Nonce) -> 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) -> - Encrypted = enoise_crypto:encrypt(Cipher, K, N, AD, PlainText), - {ok, CState#noise_cs{ n = N+1 }, Encrypted}. + 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()}. diff --git a/src/enoise_crypto.erl b/src/enoise_crypto.erl index 3f312c6..bdb81c9 100644 --- a/src/enoise_crypto.erl +++ b/src/enoise_crypto.erl @@ -65,7 +65,8 @@ rekey(Cipher, K) -> -spec encrypt(Cipher :: enoise_cipher_state:noise_cipher(), Key :: binary(), Nonce :: non_neg_integer(), - Ad :: binary(), PlainText :: binary()) -> binary(). + Ad :: binary(), PlainText :: binary()) -> + binary() | {error, term()}. encrypt('ChaChaPoly', K, N, Ad, PlainText) -> Nonce = <<0:32, N:64/little-unsigned-integer>>, enacl:aead_chacha20poly1305_ietf_encrypt(PlainText, Ad, Nonce, K); diff --git a/test/enoise_utils.erl b/test/enoise_utils.erl index 0d3b75c..fe5377b 100644 --- a/test/enoise_utils.erl +++ b/test/enoise_utils.erl @@ -26,7 +26,7 @@ echo_srv(Port, Protocol, SKP, SrvOpts) -> AcceptRes = try enoise:accept(TcpSock, Opts) - catch _:R:T -> gen_tcp:close(TcpSock), {error, {R, T}} end, + catch _:R -> gen_tcp:close(TcpSock), {error, {R, erlang:get_stacktrace()}} end, gen_tcp:close(LSock),