Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp committed Feb 10, 2016
1 parent 97b2c47 commit 4375691
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
17 changes: 13 additions & 4 deletions tests/toxencryptsave/test_encryptsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ TEST_F(tox_is_data_encrypted, really_encrypted) {
EXPECT_TRUE( ::tox_is_data_encrypted(encrypted_out) );
}

TEST_F(tox_is_data_encrypted, DISABLED_arg_is_null) {
// FIXME enable this test
TEST_F(tox_is_data_encrypted, arg_is_null) {
EXPECT_FALSE( ::tox_is_data_encrypted(NULL) );
}

Expand Down Expand Up @@ -266,8 +265,7 @@ TEST_F(tox_get_salt, all_args_are_good) {
EXPECT_EQ(0, memcmp(salt, key.salt, TOX_PASS_SALT_LENGTH) );
}

TEST_F(tox_get_salt, DISABLED_args_are_null_ptrs) {
// FIXME enable this test
TEST_F(tox_get_salt, args_are_null_ptrs) {
uint8_t salt[TOX_PASS_SALT_LENGTH] = {0};

EXPECT_FALSE( ::tox_get_salt(NULL, salt) );
Expand Down Expand Up @@ -349,6 +347,12 @@ TEST_F(tox_derive_key_with_salt, different_salt_produces_different_keys) {
delete[] passphrase_copy;
}

TEST_F(tox_derive_key_with_salt, key_is_null) {
EXPECT_FALSE( ::tox_derive_key_with_salt(passphrase, pplength, salt, NULL, &key_derivation_error) );
EXPECT_EQ(TOX_ERR_KEY_DERIVATION_NULL, key_derivation_error);
}


class tox_pass_encrypt : public tox_pass_key_encrypt
{
public:
Expand Down Expand Up @@ -446,6 +450,11 @@ TEST_F(tox_pass_decrypt, small_encrypted_len) {
EXPECT_EQ(TOX_ERR_DECRYPTION_INVALID_LENGTH, decryption_error);
}

TEST_F(tox_pass_decrypt, too_big_encrypted_len) {
EXPECT_FALSE( ::tox_pass_decrypt(encrypted_out, encrypted_len + 1, passphrase, pplength, decrypted_out, &decryption_error) );
EXPECT_EQ(TOX_ERR_DECRYPTION_FAILED, decryption_error);
}

TEST_F(tox_pass_decrypt, data_is_not_encrypted) {
uint8_t* mem = new uint8_t[encrypted_len];
memset(mem, 0, encrypted_len);
Expand Down
24 changes: 11 additions & 13 deletions toxencryptsave/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,19 @@ bool Reader::decrypt_by_key(size_t data_length, const TOX_PASS_KEY* key, uint8_t

bool Reader::decrypt_by_passphrase(size_t data_length, uint8_t* passphrase, size_t pplength, uint8_t* out, TOX_ERR_DECRYPTION* error) const
{
if (!ro_data.base) {
SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_NULL);
return false;
}

if ( !this->magic_is_valid() ) {
SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT);
return false;
}

/* extract the key */
TOX_PASS_KEY key;
if ( !this->extract_key_into(passphrase, pplength, &key, NULL)) {
/* out of memory most likely */
SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_KEY_DERIVATION_FAILED);
TOX_ERR_KEY_DERIVATION _error;

if ( !this->extract_key_into(passphrase, pplength, &key, &_error)) {
if (_error == TOX_ERR_KEY_DERIVATION_NULL) {
SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_NULL);
} else if ( !this->magic_is_valid() ) {
SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT);
} else {
/* out of memory most likely */
SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_KEY_DERIVATION_FAILED);
}
return false;
}

Expand Down

0 comments on commit 4375691

Please sign in to comment.