diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index de78a0c2..e2f41f43 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -55,7 +55,7 @@ END_TEST START_TEST(test_save_friend) { - TOX_ERR_NEW err = TOX_ERR_NEW_OK; + TOX_ERR_ENCRYPTED_NEW err = TOX_ERR_ENCRYPTED_NEW_OK; Tox *tox1 = tox_new(0, 0, 0, 0); Tox *tox2 = tox_new(0, 0, 0, 0); ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); @@ -73,7 +73,7 @@ START_TEST(test_save_friend) //ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing"); Tox *tox3 = tox_encrypted_new(0, data, size, "correcthorsebatterystaple", 25, &err); - ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new"); + ck_assert_msg(err == TOX_ERR_ENCRYPTED_NEW_OK, "failed to encrypted new"); uint8_t address2[TOX_PUBLIC_KEY_SIZE]; test = tox_friend_get_public_key(tox3, 0, address2, 0); ck_assert_msg(test == 1, "no friends!"); @@ -90,7 +90,7 @@ START_TEST(test_save_friend) // first test tox_encrypted_key_new Tox *tox4 = tox_encrypted_key_new(0, data2, size, key, &err); - ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new the second"); + ck_assert_msg(err == TOX_ERR_ENCRYPTED_NEW_OK, "failed to encrypted new the second"); uint8_t address4[TOX_PUBLIC_KEY_SIZE]; test = tox_friend_get_public_key(tox4, 0, address4, 0); ck_assert_msg(test == 1, "no friends! the second"); @@ -107,7 +107,7 @@ START_TEST(test_save_friend) // and now with the code in use (I only bothered with manually to debug this, and it seems a waste // to remove the manual check now that it's there) Tox *tox5 = tox_encrypted_new(0, data2, size, pw, pwlen, &err); - ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new the third"); + ck_assert_msg(err == TOX_ERR_ENCRYPTED_NEW_OK, "failed to encrypted new the third"); uint8_t address5[TOX_PUBLIC_KEY_SIZE]; test = tox_friend_get_public_key(tox4, 0, address5, 0); ck_assert_msg(test == 1, "no friends! the third"); diff --git a/toxcore/tox.h b/toxcore/tox.h index f645282e..e9d007db 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -487,14 +487,6 @@ typedef enum TOX_ERR_NEW { * The byte array to be loaded contained an encrypted save. */ TOX_ERR_NEW_LOAD_ENCRYPTED, - /** - * The encrypted byte array could not be decrypted. Either the data was - * corrupt or the password/key was incorrect. - * - * NOTE: This error code is only set by tox_encrypted_new() and - * tox_encrypted_key_new(), in the toxencryptsave module. - */ - TOX_ERR_NEW_LOAD_DECRYPTION_FAILED, /** * The data format was invalid. This can happen when loading data that was * saved by an older version of Tox, or when the data has been corrupted. diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 587c7048..874f0fd0 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -300,14 +300,14 @@ int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, * returns NULL on failure; see the documentation in toxcore/tox.h. */ Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, - size_t pplength, TOX_ERR_NEW *error) + size_t pplength, TOX_ERR_ENCRYPTED_NEW *error) { uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; uint8_t temp_data[decrypt_length]; if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) != decrypt_length) { - SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); + SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED); return NULL; } @@ -320,14 +320,14 @@ Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, s * returns NULL on failure; see the documentation in toxcore/tox.h. */ Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, - TOX_ERR_NEW *error) + TOX_ERR_ENCRYPTED_NEW *error) { uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; uint8_t temp_data[decrypt_length]; if (tox_pass_key_decrypt(data, length, key, temp_data) != decrypt_length) { - SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); + SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED); return NULL; } diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index 9b613cac..db272592 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h @@ -35,7 +35,6 @@ extern "C" { #define TOX_DEFINED typedef struct Tox Tox; struct Tox_Options; -typedef enum TOX_ERR_NEW TOX_ERR_NEW; #endif // these functions provide access to these defines in toxencryptsave.c, which @@ -110,13 +109,66 @@ int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint3 */ int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); +typedef enum TOX_ERR_ENCRYPTED_NEW { + TOX_ERR_ENCRYPTED_NEW_OK, + TOX_ERR_ENCRYPTED_NEW_NULL, + /** + * The function was unable to allocate enough memory to store the internal + * structures for the Tox object. + */ + TOX_ERR_ENCRYPTED_NEW_MALLOC, + /** + * The function was unable to bind to a port. This may mean that all ports + * have already been bound, e.g. by other Tox instances, or it may mean + * a permission error. You may be able to gather more information from errno. + */ + TOX_ERR_ENCRYPTED_NEW_PORT_ALLOC, + /** + * proxy_type was invalid. + */ + TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_TYPE, + /** + * proxy_type was valid but the proxy_host passed had an invalid format + * or was NULL. + */ + TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_HOST, + /** + * proxy_type was valid, but the proxy_port was invalid. + */ + TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_PORT, + /** + * The proxy host passed could not be resolved. + */ + TOX_ERR_ENCRYPTED_NEW_PROXY_NOT_FOUND, + /** + * The byte array to be loaded contained an encrypted save. + */ + TOX_ERR_ENCRYPTED_NEW_LOAD_ENCRYPTED, + /** + * The data format was invalid. This can happen when loading data that was + * saved by an older version of Tox, or when the data has been corrupted. + * When loading from badly formatted data, some data may have been loaded, + * and the rest is discarded. Passing an invalid length parameter also + * causes this error. + */ + TOX_ERR_ENCRYPTED_NEW_LOAD_BAD_FORMAT, + /** + * The encrypted byte array could not be decrypted. Either the data was + * corrupt or the password/key was incorrect. + * + * NOTE: This error code is only set by tox_encrypted_new() and + * tox_encrypted_key_new(), in the toxencryptsave module. + */ + TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED +} TOX_ERR_ENCRYPTED_NEW; + /* Load the new messenger from encrypted data of size length. * All other arguments are like toxcore/tox_new(). * * returns NULL on failure; see the documentation in toxcore/tox.h. */ Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, - size_t pplength, TOX_ERR_NEW *error); + size_t pplength, TOX_ERR_ENCRYPTED_NEW *error); /******************************* BEGIN PART 1 ******************************* @@ -190,7 +242,7 @@ int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *ke * returns NULL on failure; see the documentation in toxcore/tox.h. */ Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, - TOX_ERR_NEW *error); + TOX_ERR_ENCRYPTED_NEW *error); /* Determines whether or not the given data is encrypted (by checking the magic number)