Streamline returns in the public key API

This commit is contained in:
Jesper Louis Andersen
2020-02-04 12:38:02 +01:00
parent 2041cec2e8
commit c791f602e9
4 changed files with 54 additions and 41 deletions
+6 -6
View File
@@ -183,10 +183,10 @@ prop_box_correct() ->
begin
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of
true ->
Key = enacl:box_beforenm(PK2, SK1),
Key = enacl:box_beforenm(PK1, SK2),
CipherText = enacl:box(Msg, Nonce, PK2, SK1),
CipherText = enacl:box_afternm(Msg, Nonce, Key),
{ok, Key} = enacl:box_beforenm(PK2, SK1),
{ok, Key} = enacl:box_beforenm(PK1, SK2),
{ok, CipherText} = enacl:box(Msg, Nonce, PK2, SK1),
{ok, CipherText} = enacl:box_afternm(Msg, Nonce, Key),
{ok, DecodedMsg} = enacl:box_open(CipherText, Nonce, PK1, SK2),
{ok, DecodedMsg} = enacl:box_open_afternm(CipherText, Nonce, Key),
equals(iolist_to_binary(Msg), DecodedMsg);
@@ -210,8 +210,8 @@ prop_box_failure_integrity() ->
andalso keypair_valid(PK1, SK1)
andalso keypair_valid(PK2, SK2) of
true ->
Key = enacl:box_beforenm(PK2, SK1),
CipherText = enacl:box(Msg, Nonce, PK2, SK1),
{ok, Key} = enacl:box_beforenm(PK2, SK1),
{ok, CipherText} = enacl:box(Msg, Nonce, PK2, SK1),
Err = enacl:box_open([<<"x">>, CipherText], Nonce, PK1, SK2),
Err = enacl:box_open_afternm([<<"x">>, CipherText], Nonce, Key),
equals(Err, {error, failed_verification});