Streamline sealed boxes
This commit is contained in:
parent
c791f602e9
commit
71832cce4c
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 ->
|
||||
|
@ -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
|
||||
%%
|
||||
|
Loading…
x
Reference in New Issue
Block a user