mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Properly fixed encryptsave_test.c
This commit is contained in:
parent
680c7c2ecd
commit
36c3a270fd
|
@ -29,13 +29,13 @@ unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x
|
|||
// same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat
|
||||
|
||||
/* cause I'm shameless */
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
|
||||
{
|
||||
if (*((uint32_t *)userdata) != 974536)
|
||||
return;
|
||||
|
||||
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
|
||||
tox_add_friend_norequest(m, public_key);
|
||||
tox_friend_add_norequest(m, public_key, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,28 +56,28 @@ END_TEST
|
|||
START_TEST(test_save_friend)
|
||||
{
|
||||
TOX_ERR_NEW err = TOX_ERR_NEW_OK;
|
||||
Tox *tox1 = tox_new(0);
|
||||
Tox *tox2 = tox_new(0);
|
||||
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");
|
||||
uint32_t to_compare = 974536;
|
||||
tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
|
||||
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(tox2, address);
|
||||
int test = tox_add_friend(tox1, address, (uint8_t *)"Gentoo", 7);
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(tox2, address);
|
||||
int test = tox_friend_add(tox1, address, (uint8_t *)"Gentoo", 7, 0);
|
||||
ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
|
||||
|
||||
uint32_t size = tox_encrypted_size(tox1);
|
||||
uint8_t data[size];
|
||||
test = tox_encrypted_save(tox1, data, "correcthorsebatterystaple", 25);
|
||||
ck_assert_msg(test == 0, "failed to encrypted save");
|
||||
ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing");
|
||||
//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");
|
||||
uint8_t address2[TOX_CLIENT_ID_SIZE];
|
||||
test = tox_get_client_id(tox3, 0, address2);
|
||||
ck_assert_msg(test == 0, "no friends!");
|
||||
ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match!");
|
||||
uint8_t address2[TOX_PUBLIC_KEY_SIZE];
|
||||
test = tox_friend_get_public_key(tox3, 0, address2, 0);
|
||||
ck_assert_msg(test == 1, "no friends!");
|
||||
ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match!");
|
||||
|
||||
size = tox_encrypted_size(tox3);
|
||||
uint8_t data2[size];
|
||||
|
@ -86,15 +86,15 @@ START_TEST(test_save_friend)
|
|||
memcpy(key + 32, known_key2, crypto_box_BEFORENMBYTES);
|
||||
test = tox_encrypted_key_save(tox3, data2, key);
|
||||
ck_assert_msg(test == 0, "failed to encrypted save the second");
|
||||
ck_assert_msg(tox_is_save_encrypted(data2) == 1, "magic number the second missing");
|
||||
//ck_assert_msg(tox_is_save_encrypted(data2) == 1, "magic number the second missing");
|
||||
|
||||
// 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");
|
||||
uint8_t address4[TOX_CLIENT_ID_SIZE];
|
||||
test = tox_get_client_id(tox4, 0, address4);
|
||||
ck_assert_msg(test == 0, "no friends! the second");
|
||||
ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match! 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");
|
||||
ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match! the second");
|
||||
|
||||
// now test compaitibilty with tox_encrypted_new, first manually...
|
||||
uint8_t out1[size], out2[size];
|
||||
|
@ -108,10 +108,10 @@ START_TEST(test_save_friend)
|
|||
// 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");
|
||||
uint8_t address5[TOX_CLIENT_ID_SIZE];
|
||||
test = tox_get_client_id(tox4, 0, address5);
|
||||
ck_assert_msg(test == 0, "no friends! the third");
|
||||
ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match! 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");
|
||||
ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match! the third");
|
||||
|
||||
tox_kill(tox1);
|
||||
tox_kill(tox2);
|
||||
|
|
Loading…
Reference in New Issue
Block a user