mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
ba476e82bb
|
@ -14,6 +14,19 @@
|
|||
|
||||
#include "helpers.h"
|
||||
|
||||
static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t *status_message)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < TOX_MAX_NAME_LENGTH; ++i) {
|
||||
name[i] = rand();
|
||||
}
|
||||
|
||||
for (i = 0; i < TOX_MAX_STATUS_MESSAGE_LENGTH; ++i) {
|
||||
status_message[i] = rand();
|
||||
}
|
||||
}
|
||||
|
||||
START_TEST(test_one)
|
||||
{
|
||||
{
|
||||
|
@ -26,9 +39,17 @@ START_TEST(test_one)
|
|||
tox_options_free(o1);
|
||||
}
|
||||
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||
uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||
|
||||
uint8_t name2[TOX_MAX_NAME_LENGTH];
|
||||
uint8_t status_message2[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||
|
||||
uint32_t index[] = { 1, 2 };
|
||||
Tox *tox1 = tox_new_log(0, 0, &index[0]);
|
||||
set_random_name_and_status_message(tox1, name, status_message);
|
||||
Tox *tox2 = tox_new_log(0, 0, &index[1]);
|
||||
set_random_name_and_status_message(tox2, name2, status_message2);
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(tox1, address);
|
||||
|
@ -57,16 +78,13 @@ START_TEST(test_one)
|
|||
ret = tox_friend_add(tox1, address, message, TOX_MAX_FRIEND_REQUEST_LENGTH, &error);
|
||||
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_ALREADY_SENT, "Adding friend twice worked.");
|
||||
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < TOX_MAX_NAME_LENGTH; ++i) {
|
||||
name[i] = rand();
|
||||
}
|
||||
|
||||
tox_self_set_name(tox1, name, sizeof(name), 0);
|
||||
ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
|
||||
|
||||
tox_self_set_status_message(tox1, status_message, sizeof(status_message), 0);
|
||||
ck_assert_msg(tox_self_get_status_message_size(tox1) == sizeof(status_message),
|
||||
"Can't set status message of TOX_MAX_STATUS_MESSAGE_LENGTH");
|
||||
|
||||
tox_self_get_address(tox1, address);
|
||||
size_t save_size = tox_get_savedata_size(tox1);
|
||||
uint8_t data[save_size];
|
||||
|
@ -84,8 +102,17 @@ START_TEST(test_one)
|
|||
ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed");
|
||||
|
||||
ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size.");
|
||||
ck_assert_msg(tox_self_get_status_message_size(tox2) == sizeof status_message, "Wrong status message size");
|
||||
|
||||
uint8_t address2[TOX_ADDRESS_SIZE];
|
||||
uint8_t name_loaded[TOX_MAX_NAME_LENGTH] = { 0 };
|
||||
tox_self_get_name(tox2, name_loaded);
|
||||
ck_assert_msg(!memcmp(name, name_loaded, sizeof name), "Wrong name.");
|
||||
|
||||
uint8_t status_message_loaded[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 };
|
||||
tox_self_get_status_message(tox2, status_message_loaded);
|
||||
ck_assert_msg(!memcmp(status_message, status_message_loaded, sizeof status_message_loaded), "Wrong status message.");
|
||||
|
||||
uint8_t address2[TOX_ADDRESS_SIZE] = { 0 };
|
||||
tox_self_get_address(tox2, address2);
|
||||
ck_assert_msg(memcmp(address2, address, TOX_ADDRESS_SIZE) == 0, "Wrong address.");
|
||||
uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 };
|
||||
|
|
|
@ -2988,7 +2988,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
|
|||
break;
|
||||
|
||||
case MESSENGER_STATE_TYPE_STATUSMESSAGE:
|
||||
if ((length > 0) && (length < MAX_STATUSMESSAGE_LENGTH)) {
|
||||
if ((length > 0) && (length <= MAX_STATUSMESSAGE_LENGTH)) {
|
||||
m_set_statusmessage(m, data, length);
|
||||
}
|
||||
|
||||
|
|
|
@ -1321,7 +1321,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
|
|||
* return -1 on failure.
|
||||
* return 0 on success.
|
||||
*/
|
||||
static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
|
||||
static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
|
||||
bool udp, void *userdata)
|
||||
{
|
||||
if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) {
|
||||
|
@ -1542,7 +1542,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
|
|||
|
||||
case NET_PACKET_CRYPTO_DATA: {
|
||||
if (conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED) {
|
||||
return handle_data_packet_helper(c, crypt_connection_id, packet, length, udp, userdata);
|
||||
return handle_data_packet_core(c, crypt_connection_id, packet, length, udp, userdata);
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
|
|
@ -203,6 +203,9 @@ bool tox_derive_key_with_salt(const uint8_t *passphrase, size_t pplength, const
|
|||
* derive_key_with_salt to produce the same key as was previously used. Any encrpyted
|
||||
* data with this module can be used as input.
|
||||
*
|
||||
* The data must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in length.
|
||||
* The salt must be TOX_PASS_SALT_LENGTH bytes in length.
|
||||
*
|
||||
* returns true if magic number matches
|
||||
* success does not say anything about the validity of the data, only that data of
|
||||
* the appropriate size was copied
|
||||
|
@ -232,7 +235,11 @@ bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const TOX_PASS_K
|
|||
bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const TOX_PASS_KEY *key, uint8_t *out,
|
||||
TOX_ERR_DECRYPTION *error);
|
||||
|
||||
/* Determines whether or not the given data is encrypted (by checking the magic number)
|
||||
/* Determines whether or not the given data is encrypted (by checking the magic number).
|
||||
*
|
||||
* The data must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in length.
|
||||
*
|
||||
* returns true on success
|
||||
*/
|
||||
bool tox_is_data_encrypted(const uint8_t *data);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user