Problem: Not all crypt code is tested.
Solution: Disable unused crypt code. Add more test coverage.
char *magic; /* magic bytes stored in file header */
int salt_len; /* length of salt, or 0 when not using salt */
int seed_len; /* length of seed, or 0 when not using salt */
+#ifdef CRYPT_NOT_INPLACE
int works_inplace; /* encryption/decryption can be done in-place */
+#endif
int whole_undofile; /* whole undo file is encrypted */
/* Optional function pointer for a self-test. */
"VimCrypt~01!",
0,
0,
+#ifdef CRYPT_NOT_INPLACE
TRUE,
+#endif
FALSE,
NULL,
crypt_zip_init,
"VimCrypt~02!",
8,
8,
+#ifdef CRYPT_NOT_INPLACE
TRUE,
+#endif
FALSE,
blowfish_self_test,
crypt_blowfish_init,
"VimCrypt~03!",
8,
8,
+#ifdef CRYPT_NOT_INPLACE
TRUE,
+#endif
TRUE,
blowfish_self_test,
crypt_blowfish_init,
return -1;
}
+#ifdef CRYPT_NOT_INPLACE
/*
* Return TRUE if the crypt method for "method_nr" can be done in-place.
*/
{
return cryptmethods[state->method_nr].works_inplace;
}
+#endif
/*
* Get the crypt method for buffer "buf" as a number.
vim_free(state);
}
+#ifdef CRYPT_NOT_INPLACE
/*
* Encode "from[len]" and store the result in a newly allocated buffer, which
* is stored in "newptr".
method->decode_fn(state, ptr, len, *newptr);
return len;
}
+#endif
/*
* Encrypting "from[len]" into "to[len]".
cryptmethods[state->method_nr].encode_fn(state, from, len, to);
}
+#if 0 // unused
/*
* decrypting "from[len]" into "to[len]".
*/
{
cryptmethods[state->method_nr].decode_fn(state, from, len, to);
}
+#endif
/*
* Simple inplace encryption, modifies "buf[len]" in place.
if (cryptkey != NULL && curbuf->b_cryptstate != NULL
&& size > 0)
{
+# ifdef CRYPT_NOT_INPLACE
if (crypt_works_inplace(curbuf->b_cryptstate))
{
+# endif
crypt_decode_inplace(curbuf->b_cryptstate, ptr, size);
+# ifdef CRYPT_NOT_INPLACE
}
else
{
}
size = decrypted_size;
}
+# endif
}
#endif
{
/* Encrypt the data. Do it in-place if possible, otherwise use an
* allocated buffer. */
+# ifdef CRYPT_NOT_INPLACE
if (crypt_works_inplace(ip->bw_buffer->b_cryptstate))
{
+# endif
crypt_encode_inplace(ip->bw_buffer->b_cryptstate, buf, len);
+# ifdef CRYPT_NOT_INPLACE
}
else
{
vim_free(outbuf);
return (wlen < len) ? FAIL : OK;
}
+# endif
}
#endif
/* crypt.c */
int crypt_method_nr_from_name(char_u *name);
int crypt_method_nr_from_magic(char *ptr, int len);
-int crypt_works_inplace(cryptstate_T *state);
int crypt_get_method_nr(buf_T *buf);
int crypt_whole_undofile(int method_nr);
int crypt_get_header_len(int method_nr);
cryptstate_T *crypt_create_from_file(FILE *fp, char_u *key);
cryptstate_T *crypt_create_for_writing(int method_nr, char_u *key, char_u **header, int *header_len);
void crypt_free_state(cryptstate_T *state);
-long crypt_encode_alloc(cryptstate_T *state, char_u *from, size_t len, char_u **newptr);
-long crypt_decode_alloc(cryptstate_T *state, char_u *ptr, long len, char_u **newptr);
void crypt_encode(cryptstate_T *state, char_u *from, size_t len, char_u *to);
-void crypt_decode(cryptstate_T *state, char_u *from, size_t len, char_u *to);
void crypt_encode_inplace(cryptstate_T *state, char_u *buf, size_t len);
void crypt_decode_inplace(cryptstate_T *state, char_u *buf, size_t len);
void crypt_free_key(char_u *key);
# define CRYPT_M_BF 1
# define CRYPT_M_BF2 2
# define CRYPT_M_COUNT 3 /* number of crypt methods */
+
+// Currently all crypt methods work inplace. If one is added that isn't then
+// define this.
+// # define CRYPT_NOT_INPLACE 1
#endif
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx']
call setline(1, text)
call feedkeys(":X\<CR>foobar\<CR>foobar\<CR>", 'xt')
+ call assert_equal('*****', &key)
w!
bwipe!
call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", 'xt')
func Test_uncrypt_blowfish2()
call Uncrypt_stable('blowfish', "VimCrypt~03!\u001e\u00d1N\u00e3;\u00d3\u00c0\u00a0^C)\u0004\u00f7\u007f.\u00b6\u00abF\u000eS\u0019\u00e0\u008b6\u00d2[T\u00cb\u00a7\u0085\u00d8\u00be9\u000b\u00812\u000bQ\u00b3\u00cc@\u0097\u000f\u00df\u009a\u00adIv\u00aa.\u00d8\u00c9\u00ee\u009e`\u00bd$\u00af%\u00d0", "barburp", ["abcdefghijklmnopqrstuvwxyz", "!@#$%^&*()_+=-`~"])
endfunc
+
+func Test_uncrypt_unknown_method()
+ split Xuncrypt_unknown.txt
+ set bin noeol key= fenc=latin1
+ call setline(1, "VimCrypt~93!\u001e\u00d1")
+ w!
+ bwipe!
+ set nobin
+ call assert_fails(":split Xuncrypt_unknown.txt", 'E821:')
+
+ bwipe!
+ call delete('Xuncrypt_unknown.txt')
+ set key=
+endfunc
+
+func Test_crypt_key_mismatch()
+ set cryptmethod=blowfish
+
+ split Xtest.txt
+ call setline(1, 'nothing')
+ call feedkeys(":X\<CR>foobar\<CR>nothing\<CR>", 'xt')
+ call assert_match("Keys don't match!", execute(':2messages'))
+ call assert_equal('', &key)
+ call feedkeys("\<CR>\<CR>", 'xt')
+
+ set cryptmethod&
+ bwipe!
+endfunc
+
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 773,
/**/
772,
/**/