summaryrefslogtreecommitdiff
path: root/auto_tests/encryptsave_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-08-04 19:18:31 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-08-13 11:02:32 +0000
commita509d253240abd96665675fed7513f6cdeec04de (patch)
tree0f82af1686f6a2f9fd66759d97ac581fd875d29b /auto_tests/encryptsave_test.c
parent97a4b8e6a74584a692aa8e92bd080c2e60ef04de (diff)
Fix some printf format specifiers.
Diffstat (limited to 'auto_tests/encryptsave_test.c')
-rw-r--r--auto_tests/encryptsave_test.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c
index 41a4ed5c..bf7988e2 100644
--- a/auto_tests/encryptsave_test.c
+++ b/auto_tests/encryptsave_test.c
@@ -72,7 +72,7 @@ static void test_save_friend(void)
72 VLA(uint8_t, enc_data, size2); 72 VLA(uint8_t, enc_data, size2);
73 TOX_ERR_ENCRYPTION error1; 73 TOX_ERR_ENCRYPTION error1;
74 bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1); 74 bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1);
75 ck_assert_msg(ret, "failed to encrypted save: %u", error1); 75 ck_assert_msg(ret, "failed to encrypted save: %d", error1);
76 ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); 76 ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing");
77 77
78 struct Tox_Options *options = tox_options_new(nullptr); 78 struct Tox_Options *options = tox_options_new(nullptr);
@@ -81,16 +81,16 @@ static void test_save_friend(void)
81 81
82 TOX_ERR_NEW err2; 82 TOX_ERR_NEW err2;
83 Tox *tox3 = tox_new_log(options, &err2, nullptr); 83 Tox *tox3 = tox_new_log(options, &err2, nullptr);
84 ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, 84 ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %d. should fail with %d", err2,
85 TOX_ERR_NEW_LOAD_ENCRYPTED); 85 TOX_ERR_NEW_LOAD_ENCRYPTED);
86 ck_assert_msg(tox3 == nullptr, "tox_new with error should return NULL"); 86 ck_assert_msg(tox3 == nullptr, "tox_new with error should return NULL");
87 VLA(uint8_t, dec_data, size); 87 VLA(uint8_t, dec_data, size);
88 TOX_ERR_DECRYPTION err3; 88 TOX_ERR_DECRYPTION err3;
89 ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3); 89 ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3);
90 ck_assert_msg(ret, "failed to decrypt save: %u", err3); 90 ck_assert_msg(ret, "failed to decrypt save: %d", err3);
91 tox_options_set_savedata_data(options, dec_data, size); 91 tox_options_set_savedata_data(options, dec_data, size);
92 tox3 = tox_new_log(options, &err2, nullptr); 92 tox3 = tox_new_log(options, &err2, nullptr);
93 ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); 93 ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %d", err2);
94 uint8_t address2[TOX_PUBLIC_KEY_SIZE]; 94 uint8_t address2[TOX_PUBLIC_KEY_SIZE];
95 ret = tox_friend_get_public_key(tox3, 0, address2, nullptr); 95 ret = tox_friend_get_public_key(tox3, 0, address2, nullptr);
96 ck_assert_msg(ret, "no friends!"); 96 ck_assert_msg(ret, "no friends!");
@@ -107,15 +107,15 @@ static void test_save_friend(void)
107 size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 107 size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
108 VLA(uint8_t, encdata2, size2); 108 VLA(uint8_t, encdata2, size2);
109 ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1); 109 ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1);
110 ck_assert_msg(ret, "failed to key encrypt %u", error1); 110 ck_assert_msg(ret, "failed to key encrypt %d", error1);
111 ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing"); 111 ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing");
112 112
113 VLA(uint8_t, out1, size); 113 VLA(uint8_t, out1, size);
114 VLA(uint8_t, out2, size); 114 VLA(uint8_t, out2, size);
115 ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3); 115 ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3);
116 ck_assert_msg(ret, "failed to pw decrypt %u", err3); 116 ck_assert_msg(ret, "failed to pw decrypt %d", err3);
117 ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3); 117 ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3);
118 ck_assert_msg(ret, "failed to key decrypt %u", err3); 118 ck_assert_msg(ret, "failed to key decrypt %d", err3);
119 ck_assert_msg(memcmp(out1, out2, size) == 0, "differing output data"); 119 ck_assert_msg(memcmp(out1, out2, size) == 0, "differing output data");
120 120
121 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste 121 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste
@@ -143,37 +143,37 @@ static void test_keys(void)
143 TOX_ERR_DECRYPTION decerr; 143 TOX_ERR_DECRYPTION decerr;
144 TOX_ERR_KEY_DERIVATION keyerr; 144 TOX_ERR_KEY_DERIVATION keyerr;
145 Tox_Pass_Key *key = tox_pass_key_derive((const uint8_t *)"123qweasdzxc", 12, &keyerr); 145 Tox_Pass_Key *key = tox_pass_key_derive((const uint8_t *)"123qweasdzxc", 12, &keyerr);
146 ck_assert_msg(key != nullptr, "generic failure 1: %u", keyerr); 146 ck_assert_msg(key != nullptr, "generic failure 1: %d", keyerr);
147 const uint8_t *string = (const uint8_t *)"No Patrick, mayonnaise is not an instrument."; // 44 147 const uint8_t *string = (const uint8_t *)"No Patrick, mayonnaise is not an instrument."; // 44
148 148
149 uint8_t encrypted[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; 149 uint8_t encrypted[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
150 bool ret = tox_pass_key_encrypt(key, string, 44, encrypted, &encerr); 150 bool ret = tox_pass_key_encrypt(key, string, 44, encrypted, &encerr);
151 ck_assert_msg(ret, "generic failure 2: %u", encerr); 151 ck_assert_msg(ret, "generic failure 2: %d", encerr);
152 152
153 uint8_t encrypted2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; 153 uint8_t encrypted2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
154 ret = tox_pass_encrypt(string, 44, (const uint8_t *)"123qweasdzxc", 12, encrypted2, &encerr); 154 ret = tox_pass_encrypt(string, 44, (const uint8_t *)"123qweasdzxc", 12, encrypted2, &encerr);
155 ck_assert_msg(ret, "generic failure 3: %u", encerr); 155 ck_assert_msg(ret, "generic failure 3: %d", encerr);
156 156
157 uint8_t out1[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; 157 uint8_t out1[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
158 uint8_t out2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; 158 uint8_t out2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
159 159
160 ret = tox_pass_key_decrypt(key, encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, out1, &decerr); 160 ret = tox_pass_key_decrypt(key, encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, out1, &decerr);
161 ck_assert_msg(ret, "generic failure 4: %u", decerr); 161 ck_assert_msg(ret, "generic failure 4: %d", decerr);
162 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed"); 162 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed");
163 163
164 ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out2, 164 ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out2,
165 &decerr); 165 &decerr);
166 ck_assert_msg(ret, "generic failure 5: %u", decerr); 166 ck_assert_msg(ret, "generic failure 5: %d", decerr);
167 ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); 167 ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed");
168 168
169 ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, nullptr, 0, out2, &decerr); 169 ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, nullptr, 0, out2, &decerr);
170 ck_assert_msg(!ret, "Decrypt succeeded with wrong pass"); 170 ck_assert_msg(!ret, "Decrypt succeeded with wrong pass");
171 ck_assert_msg(decerr != TOX_ERR_DECRYPTION_FAILED, "Bad error code %u", decerr); 171 ck_assert_msg(decerr != TOX_ERR_DECRYPTION_FAILED, "Bad error code %d", decerr);
172 172
173 // test that pass_decrypt can decrypt things from pass_key_encrypt 173 // test that pass_decrypt can decrypt things from pass_key_encrypt
174 ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out1, 174 ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out1,
175 &decerr); 175 &decerr);
176 ck_assert_msg(ret, "generic failure 6: %u", decerr); 176 ck_assert_msg(ret, "generic failure 6: %d", decerr);
177 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed"); 177 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed");
178 178
179 uint8_t salt[TOX_PASS_SALT_LENGTH]; 179 uint8_t salt[TOX_PASS_SALT_LENGTH];
@@ -181,7 +181,7 @@ static void test_keys(void)
181 ck_assert_msg(tox_get_salt(encrypted, salt, &salt_err), "couldn't get salt"); 181 ck_assert_msg(tox_get_salt(encrypted, salt, &salt_err), "couldn't get salt");
182 ck_assert_msg(salt_err == TOX_ERR_GET_SALT_OK, "get_salt returned an error"); 182 ck_assert_msg(salt_err == TOX_ERR_GET_SALT_OK, "get_salt returned an error");
183 Tox_Pass_Key *key2 = tox_pass_key_derive_with_salt((const uint8_t *)"123qweasdzxc", 12, salt, &keyerr); 183 Tox_Pass_Key *key2 = tox_pass_key_derive_with_salt((const uint8_t *)"123qweasdzxc", 12, salt, &keyerr);
184 ck_assert_msg(key2 != nullptr, "generic failure 7: %u", keyerr); 184 ck_assert_msg(key2 != nullptr, "generic failure 7: %d", keyerr);
185 ck_assert_msg(0 == memcmp(key, key2, TOX_PASS_KEY_LENGTH + TOX_PASS_SALT_LENGTH), "salt comparison failed"); 185 ck_assert_msg(0 == memcmp(key, key2, TOX_PASS_KEY_LENGTH + TOX_PASS_SALT_LENGTH), "salt comparison failed");
186 tox_pass_key_free(key2); 186 tox_pass_key_free(key2);
187 tox_pass_key_free(key); 187 tox_pass_key_free(key);