diff options
author | iphydf <iphydf@users.noreply.github.com> | 2017-01-20 21:16:55 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2017-01-28 20:49:12 +0000 |
commit | 6ae33c16cf9e37fda85d70c78b3c2779eb8ca21a (patch) | |
tree | 99c3a8c26e02039b515bb6f57d2797d1cdf77c1d /auto_tests/encryptsave_test.c | |
parent | 895de7ef26e7617769f2271345e414545c2581f8 (diff) |
Add VLA compatibility macro for C89-ish compilers.
Diffstat (limited to 'auto_tests/encryptsave_test.c')
-rw-r--r-- | auto_tests/encryptsave_test.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 22c585ed..749767a0 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include "../toxcore/tox.h" | 14 | #include "../toxcore/tox.h" |
15 | 15 | ||
16 | #include "../toxcore/ccompat.h" | ||
16 | #include "../toxcore/crypto_core.h" | 17 | #include "../toxcore/crypto_core.h" |
17 | #include "../toxencryptsave/toxencryptsave.h" | 18 | #include "../toxencryptsave/toxencryptsave.h" |
18 | #ifdef VANILLA_NACL | 19 | #ifdef VANILLA_NACL |
@@ -68,10 +69,10 @@ START_TEST(test_save_friend) | |||
68 | ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); | 69 | ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); |
69 | 70 | ||
70 | size_t size = tox_get_savedata_size(tox1); | 71 | size_t size = tox_get_savedata_size(tox1); |
71 | uint8_t data[size]; | 72 | VLA(uint8_t, data, size); |
72 | tox_get_savedata(tox1, data); | 73 | tox_get_savedata(tox1, data); |
73 | size_t size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 74 | size_t size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
74 | uint8_t enc_data[size2]; | 75 | VLA(uint8_t, enc_data, size2); |
75 | TOX_ERR_ENCRYPTION error1; | 76 | TOX_ERR_ENCRYPTION error1; |
76 | bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1); | 77 | bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1); |
77 | ck_assert_msg(ret, "failed to encrypted save: %u", error1); | 78 | ck_assert_msg(ret, "failed to encrypted save: %u", error1); |
@@ -86,7 +87,7 @@ START_TEST(test_save_friend) | |||
86 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, | 87 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, |
87 | TOX_ERR_NEW_LOAD_ENCRYPTED); | 88 | TOX_ERR_NEW_LOAD_ENCRYPTED); |
88 | ck_assert_msg(tox3 == NULL, "tox_new with error should return NULL"); | 89 | ck_assert_msg(tox3 == NULL, "tox_new with error should return NULL"); |
89 | uint8_t dec_data[size]; | 90 | VLA(uint8_t, dec_data, size); |
90 | TOX_ERR_DECRYPTION err3; | 91 | TOX_ERR_DECRYPTION err3; |
91 | ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3); | 92 | ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3); |
92 | ck_assert_msg(ret, "failed to decrypt save: %u", err3); | 93 | ck_assert_msg(ret, "failed to decrypt save: %u", err3); |
@@ -99,19 +100,20 @@ START_TEST(test_save_friend) | |||
99 | ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match!"); | 100 | ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match!"); |
100 | 101 | ||
101 | size = tox_get_savedata_size(tox3); | 102 | size = tox_get_savedata_size(tox3); |
102 | uint8_t data2[size]; | 103 | VLA(uint8_t, data2, size); |
103 | tox_get_savedata(tox3, data2); | 104 | tox_get_savedata(tox3, data2); |
104 | Tox_Pass_Key *key = tox_pass_key_new(); | 105 | Tox_Pass_Key *key = tox_pass_key_new(); |
105 | ck_assert_msg(key != NULL, "pass key allocation failure"); | 106 | ck_assert_msg(key != NULL, "pass key allocation failure"); |
106 | memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH); | 107 | memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH); |
107 | memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key2, TOX_PASS_KEY_LENGTH); | 108 | memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key2, TOX_PASS_KEY_LENGTH); |
108 | size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 109 | size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
109 | uint8_t encdata2[size2]; | 110 | VLA(uint8_t, encdata2, size2); |
110 | ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1); | 111 | ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1); |
111 | ck_assert_msg(ret, "failed to key encrypt %u", error1); | 112 | ck_assert_msg(ret, "failed to key encrypt %u", error1); |
112 | ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing"); | 113 | ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing"); |
113 | 114 | ||
114 | uint8_t out1[size], out2[size]; | 115 | VLA(uint8_t, out1, size); |
116 | VLA(uint8_t, out2, size); | ||
115 | ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3); | 117 | ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3); |
116 | ck_assert_msg(ret, "failed to pw decrypt %u", err3); | 118 | ck_assert_msg(ret, "failed to pw decrypt %u", err3); |
117 | ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3); | 119 | ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3); |