diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d569a..a79fe7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - generichash - hash - kx - - public - pwhash - randombytes - secret diff --git a/c_src/public.c b/c_src/public.c index cc1925b..3c47bcf 100644 --- a/c_src/public.c +++ b/c_src/public.c @@ -255,7 +255,9 @@ ERL_NIF_TERM enacl_crypto_box_seal(ErlNifEnv *env, int argc, crypto_box_seal(ciphertext.data, msg.data, msg.size, key.data); - return enif_make_binary(env, &ciphertext); + ERL_NIF_TERM ret_ok = enif_make_atom(env, ATOM_OK); + ERL_NIF_TERM ret_bin = enif_make_binary(env, &ciphertext); + return enif_make_tuple2(env, ret_ok, ret_bin); } ERL_NIF_TERM enacl_crypto_box_seal_open(ErlNifEnv *env, int argc, @@ -283,5 +285,8 @@ ERL_NIF_TERM enacl_crypto_box_seal_open(ErlNifEnv *env, int argc, return enacl_error_tuple(env, "failed_verification"); } - return enif_make_binary(env, &msg); + ERL_NIF_TERM ret_ok = enif_make_atom(env, ATOM_OK); + ERL_NIF_TERM ret_bin = enif_make_binary(env, &msg); + + return enif_make_tuple2(env, ret_ok, ret_bin); } diff --git a/eqc_test/enacl_eqc.erl b/eqc_test/enacl_eqc.erl index 2a1a9f0..6a43dcf 100644 --- a/eqc_test/enacl_eqc.erl +++ b/eqc_test/enacl_eqc.erl @@ -431,7 +431,7 @@ prop_seal_box_failure_integrity() -> begin case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of true -> - CT = enacl:box_seal(Msg, PK1), + {ok, CT} = enacl:box_seal(Msg, PK1), Err = enacl:box_seal_open([<<"x">>, CT], PK1, SK1), equals(Err, {error, failed_verification}); false -> @@ -450,7 +450,7 @@ prop_seal_box_correct() -> begin case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of true -> - SealedCipherText = enacl:box_seal(Msg, PK1), + {ok, SealedCipherText} = enacl:box_seal(Msg, PK1), {ok, DecodedMsg} = enacl:box_seal_open(SealedCipherText, PK1, SK1), equals(iolist_to_binary(Msg), DecodedMsg); false -> diff --git a/src/enacl.erl b/src/enacl.erl index 5a2375a..037bafb 100644 --- a/src/enacl.erl +++ b/src/enacl.erl @@ -685,7 +685,7 @@ box_secret_key_bytes() -> %% keypair and then uses `box'. Ephemeral public key will sent to other party. Returns the %% enciphered message `SealedCipherText' which includes ephemeral public key at head. %% @end --spec box_seal(Msg, PK) -> SealedCipherText +-spec box_seal(Msg, PK) -> {ok, SealedCipherText} | {error, term()} when Msg :: iodata(), PK :: binary(), @@ -706,10 +706,7 @@ box_seal(Msg, PK) -> SK :: binary(), Msg :: binary(). box_seal_open(SealedCipherText, PK, SK) -> - case enacl_nif:crypto_box_seal_open(SealedCipherText, PK, SK) of - {error, Err} -> {error, Err}; - Bin when is_binary(Bin) -> {ok, Bin} - end. + enacl_nif:crypto_box_seal_open(SealedCipherText, PK, SK). %% @doc secretbox/3 encrypts a message with a key %%