Mercurial > vim
comparison src/crypt.c @ 15531:959cf4c63b18 v8.1.0773
patch 8.1.0773: not all crypt code is tested
commit https://github.com/vim/vim/commit/987411db9e4b76b524d0579db21074be0bffd61b
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 18 22:48:34 2019 +0100
patch 8.1.0773: not all crypt code is tested
Problem: Not all crypt code is tested.
Solution: Disable unused crypt code. Add more test coverage.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 18 Jan 2019 23:00:08 +0100 |
parents | 55ccc2d353bd |
children | dd725a8ab112 |
comparison
equal
deleted
inserted
replaced
15530:05bc9f3070b8 | 15531:959cf4c63b18 |
---|---|
32 typedef struct { | 32 typedef struct { |
33 char *name; /* encryption name as used in 'cryptmethod' */ | 33 char *name; /* encryption name as used in 'cryptmethod' */ |
34 char *magic; /* magic bytes stored in file header */ | 34 char *magic; /* magic bytes stored in file header */ |
35 int salt_len; /* length of salt, or 0 when not using salt */ | 35 int salt_len; /* length of salt, or 0 when not using salt */ |
36 int seed_len; /* length of seed, or 0 when not using salt */ | 36 int seed_len; /* length of seed, or 0 when not using salt */ |
37 #ifdef CRYPT_NOT_INPLACE | |
37 int works_inplace; /* encryption/decryption can be done in-place */ | 38 int works_inplace; /* encryption/decryption can be done in-place */ |
39 #endif | |
38 int whole_undofile; /* whole undo file is encrypted */ | 40 int whole_undofile; /* whole undo file is encrypted */ |
39 | 41 |
40 /* Optional function pointer for a self-test. */ | 42 /* Optional function pointer for a self-test. */ |
41 int (* self_test_fn)(); | 43 int (* self_test_fn)(); |
42 | 44 |
78 { | 80 { |
79 "zip", | 81 "zip", |
80 "VimCrypt~01!", | 82 "VimCrypt~01!", |
81 0, | 83 0, |
82 0, | 84 0, |
85 #ifdef CRYPT_NOT_INPLACE | |
83 TRUE, | 86 TRUE, |
87 #endif | |
84 FALSE, | 88 FALSE, |
85 NULL, | 89 NULL, |
86 crypt_zip_init, | 90 crypt_zip_init, |
87 crypt_zip_encode, crypt_zip_decode, | 91 crypt_zip_encode, crypt_zip_decode, |
88 NULL, NULL, | 92 NULL, NULL, |
93 { | 97 { |
94 "blowfish", | 98 "blowfish", |
95 "VimCrypt~02!", | 99 "VimCrypt~02!", |
96 8, | 100 8, |
97 8, | 101 8, |
102 #ifdef CRYPT_NOT_INPLACE | |
98 TRUE, | 103 TRUE, |
104 #endif | |
99 FALSE, | 105 FALSE, |
100 blowfish_self_test, | 106 blowfish_self_test, |
101 crypt_blowfish_init, | 107 crypt_blowfish_init, |
102 crypt_blowfish_encode, crypt_blowfish_decode, | 108 crypt_blowfish_encode, crypt_blowfish_decode, |
103 NULL, NULL, | 109 NULL, NULL, |
108 { | 114 { |
109 "blowfish2", | 115 "blowfish2", |
110 "VimCrypt~03!", | 116 "VimCrypt~03!", |
111 8, | 117 8, |
112 8, | 118 8, |
119 #ifdef CRYPT_NOT_INPLACE | |
113 TRUE, | 120 TRUE, |
121 #endif | |
114 TRUE, | 122 TRUE, |
115 blowfish_self_test, | 123 blowfish_self_test, |
116 crypt_blowfish_init, | 124 crypt_blowfish_init, |
117 crypt_blowfish_encode, crypt_blowfish_decode, | 125 crypt_blowfish_encode, crypt_blowfish_decode, |
118 NULL, NULL, | 126 NULL, NULL, |
165 emsg(_("E821: File is encrypted with unknown method")); | 173 emsg(_("E821: File is encrypted with unknown method")); |
166 | 174 |
167 return -1; | 175 return -1; |
168 } | 176 } |
169 | 177 |
178 #ifdef CRYPT_NOT_INPLACE | |
170 /* | 179 /* |
171 * Return TRUE if the crypt method for "method_nr" can be done in-place. | 180 * Return TRUE if the crypt method for "method_nr" can be done in-place. |
172 */ | 181 */ |
173 int | 182 int |
174 crypt_works_inplace(cryptstate_T *state) | 183 crypt_works_inplace(cryptstate_T *state) |
175 { | 184 { |
176 return cryptmethods[state->method_nr].works_inplace; | 185 return cryptmethods[state->method_nr].works_inplace; |
177 } | 186 } |
187 #endif | |
178 | 188 |
179 /* | 189 /* |
180 * Get the crypt method for buffer "buf" as a number. | 190 * Get the crypt method for buffer "buf" as a number. |
181 */ | 191 */ |
182 int | 192 int |
364 { | 374 { |
365 vim_free(state->method_state); | 375 vim_free(state->method_state); |
366 vim_free(state); | 376 vim_free(state); |
367 } | 377 } |
368 | 378 |
379 #ifdef CRYPT_NOT_INPLACE | |
369 /* | 380 /* |
370 * Encode "from[len]" and store the result in a newly allocated buffer, which | 381 * Encode "from[len]" and store the result in a newly allocated buffer, which |
371 * is stored in "newptr". | 382 * is stored in "newptr". |
372 * Return number of bytes in "newptr", 0 for need more or -1 on error. | 383 * Return number of bytes in "newptr", 0 for need more or -1 on error. |
373 */ | 384 */ |
420 if (*newptr == NULL) | 431 if (*newptr == NULL) |
421 return -1; | 432 return -1; |
422 method->decode_fn(state, ptr, len, *newptr); | 433 method->decode_fn(state, ptr, len, *newptr); |
423 return len; | 434 return len; |
424 } | 435 } |
436 #endif | |
425 | 437 |
426 /* | 438 /* |
427 * Encrypting "from[len]" into "to[len]". | 439 * Encrypting "from[len]" into "to[len]". |
428 */ | 440 */ |
429 void | 441 void |
434 char_u *to) | 446 char_u *to) |
435 { | 447 { |
436 cryptmethods[state->method_nr].encode_fn(state, from, len, to); | 448 cryptmethods[state->method_nr].encode_fn(state, from, len, to); |
437 } | 449 } |
438 | 450 |
451 #if 0 // unused | |
439 /* | 452 /* |
440 * decrypting "from[len]" into "to[len]". | 453 * decrypting "from[len]" into "to[len]". |
441 */ | 454 */ |
442 void | 455 void |
443 crypt_decode( | 456 crypt_decode( |
446 size_t len, | 459 size_t len, |
447 char_u *to) | 460 char_u *to) |
448 { | 461 { |
449 cryptmethods[state->method_nr].decode_fn(state, from, len, to); | 462 cryptmethods[state->method_nr].decode_fn(state, from, len, to); |
450 } | 463 } |
464 #endif | |
451 | 465 |
452 /* | 466 /* |
453 * Simple inplace encryption, modifies "buf[len]" in place. | 467 * Simple inplace encryption, modifies "buf[len]" in place. |
454 */ | 468 */ |
455 void | 469 void |