summaryrefslogtreecommitdiff
path: root/auto_tests/file_saving_test.c
diff options
context:
space:
mode:
authorpranomostro <pranomestro@gmail.com>2017-05-11 13:55:43 +0200
committerpranomostro <pranomestro@gmail.com>2017-05-13 22:59:50 +0200
commit7ef27a9105cde3e8b72d1a85ef245c31a8108fa6 (patch)
tree7ca52f3a77ea41c10789c35bf7e0eede7f677e59 /auto_tests/file_saving_test.c
parent2474f43087f67cd9ac993a7ef78bfd81e2b083d7 (diff)
Make variable names in file saving test less cryptic.
Diffstat (limited to 'auto_tests/file_saving_test.c')
-rw-r--r--auto_tests/file_saving_test.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c
index 643b8fe1..8cff56e8 100644
--- a/auto_tests/file_saving_test.c
+++ b/auto_tests/file_saving_test.c
@@ -29,9 +29,9 @@
29#include "../toxcore/tox.h" 29#include "../toxcore/tox.h"
30#include "../toxencryptsave/toxencryptsave.h" 30#include "../toxencryptsave/toxencryptsave.h"
31 31
32static const char *pphrase = "bar", *name = "foo"; 32static const char *pphrase = "bar", *name = "foo", *savefile = "./save";
33 33
34static void tse(void) 34static void save_data_encrypted(void)
35{ 35{
36 struct Tox_Options options; 36 struct Tox_Options options;
37 tox_options_default(&options); 37 tox_options_default(&options);
@@ -39,27 +39,27 @@ static void tse(void)
39 39
40 tox_self_set_name(t, (const uint8_t *)name, strlen(name), NULL); 40 tox_self_set_name(t, (const uint8_t *)name, strlen(name), NULL);
41 41
42 FILE *f = fopen("save", "w"); 42 FILE *f = fopen(savefile, "w");
43 43
44 off_t sz = tox_get_savedata_size(t); 44 off_t size = tox_get_savedata_size(t);
45 uint8_t *clear = (uint8_t *)malloc(sz); 45 uint8_t *clear = (uint8_t *)malloc(size);
46 46
47 /*this function does not write any data at all*/ 47 /*this function does not write any data at all*/
48 tox_get_savedata(t, clear); 48 tox_get_savedata(t, clear);
49 49
50 sz += TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 50 size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
51 uint8_t *cipher = (uint8_t *)malloc(sz); 51 uint8_t *cipher = (uint8_t *)malloc(size);
52 52
53 TOX_ERR_ENCRYPTION eerr; 53 TOX_ERR_ENCRYPTION eerr;
54 54
55 if (!tox_pass_encrypt(clear, sz - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)pphrase, strlen(pphrase), cipher, 55 if (!tox_pass_encrypt(clear, size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)pphrase, strlen(pphrase), cipher,
56 &eerr)) { 56 &eerr)) {
57 fprintf(stderr, "error: could not encrypt, error code %d\n", eerr); 57 fprintf(stderr, "error: could not encrypt, error code %d\n", eerr);
58 exit(4); 58 exit(4);
59 } 59 }
60 60
61 size_t wv = fwrite(cipher, sizeof(*cipher), sz, f); 61 size_t written_value = fwrite(cipher, sizeof(*cipher), size, f);
62 printf("written wv = %li of %li\n", wv, sz); 62 printf("written written_value = %li of %li\n", written_value, size);
63 63
64 free(cipher); 64 free(cipher);
65 free(clear); 65 free(clear);
@@ -67,21 +67,21 @@ static void tse(void)
67 tox_kill(t); 67 tox_kill(t);
68} 68}
69 69
70static void tsd(void) 70static void load_data_decrypted(void)
71{ 71{
72 FILE *f = fopen("save", "r"); 72 FILE *f = fopen(savefile, "r");
73 fseek(f, 0, SEEK_END); 73 fseek(f, 0, SEEK_END);
74 long sz = ftell(f); 74 long size = ftell(f);
75 fseek(f, 0, SEEK_SET); 75 fseek(f, 0, SEEK_SET);
76 76
77 uint8_t *cipher = (uint8_t *)malloc(sz); 77 uint8_t *cipher = (uint8_t *)malloc(size);
78 uint8_t *clear = (uint8_t *)malloc(sz - TOX_PASS_ENCRYPTION_EXTRA_LENGTH); 78 uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
79 size_t rv = fread(cipher, sizeof(*cipher), sz, f); 79 size_t read_value = fread(cipher, sizeof(*cipher), size, f);
80 printf("read rv = %li of %li\n", rv, sz); 80 printf("read read_vavue = %li of %li\n", read_value, size);
81 81
82 TOX_ERR_DECRYPTION derr; 82 TOX_ERR_DECRYPTION derr;
83 83
84 if (!tox_pass_decrypt(cipher, sz, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr)) { 84 if (!tox_pass_decrypt(cipher, size, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr)) {
85 fprintf(stderr, "error: could not decrypt, error code %d\n", derr); 85 fprintf(stderr, "error: could not decrypt, error code %d\n", derr);
86 exit(3); 86 exit(3);
87 } 87 }
@@ -92,7 +92,7 @@ static void tsd(void)
92 92
93 tox_options_set_savedata_type(&options, TOX_SAVEDATA_TYPE_TOX_SAVE); 93 tox_options_set_savedata_type(&options, TOX_SAVEDATA_TYPE_TOX_SAVE);
94 94
95 tox_options_set_savedata_data(&options, clear, sz); 95 tox_options_set_savedata_data(&options, clear, size);
96 96
97 TOX_ERR_NEW err; 97 TOX_ERR_NEW err;
98 98
@@ -120,10 +120,10 @@ static void tsd(void)
120 120
121int main(void) 121int main(void)
122{ 122{
123 tse(); 123 save_data_encrypted();
124 tsd(); 124 load_data_decrypted();
125 125
126 int ret = remove("./save"); 126 int ret = remove(savefile);
127 127
128 if (ret != 0) { 128 if (ret != 0) {
129 fprintf(stderr, "error: could not remove savefile\n"); 129 fprintf(stderr, "error: could not remove savefile\n");