mirror of
https://github.com/zoriya/vim.git
synced 2025-12-20 06:05:18 +00:00
Change 'cryptmethod' from a number to a string option. Make it global-local.
This commit is contained in:
@@ -1371,10 +1371,17 @@ the file is encrypted.
|
|||||||
To disable the encryption, reset the 'key' option to an empty value: >
|
To disable the encryption, reset the 'key' option to an empty value: >
|
||||||
:set key=
|
:set key=
|
||||||
|
|
||||||
You can use the 'cryptmethod' option to select the type of encryption. Do
|
You can use the 'cryptmethod' option to select the type of encryption, use one
|
||||||
this before writing the file. When reading an encrypted file it will be set
|
of these two: >
|
||||||
automatically to the method used when that file was written. You can change
|
:setlocal cm=zip " weak method, backwards compatible
|
||||||
'cryptmethod' before writing that file to change the method.
|
:setlocal cm=blowfish " strong method
|
||||||
|
Do this before writing the file. When reading an encrypted file it will be
|
||||||
|
set automatically to the method used when that file was written. You can
|
||||||
|
change 'cryptmethod' before writing that file to change the method.
|
||||||
|
To set the default method, used for new files, use one of these in your
|
||||||
|
|vimrc| file: >
|
||||||
|
set cm=zip
|
||||||
|
set cm=blowfish
|
||||||
|
|
||||||
When writing an undo file, the same key and method will be used for the text
|
When writing an undo file, the same key and method will be used for the text
|
||||||
in the undo file. |persistent-undo|.
|
in the undo file. |persistent-undo|.
|
||||||
|
|||||||
@@ -2074,15 +2074,15 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
|
|
||||||
|
|
||||||
*'cryptmethod'* *'cm'*
|
*'cryptmethod'* *'cm'*
|
||||||
'cryptmethod' number (default 0)
|
'cryptmethod' string (default "zip")
|
||||||
local to buffer
|
global or local to buffer |global-local|
|
||||||
{not in Vi}
|
{not in Vi}
|
||||||
Method used for encryption when the buffer is written to a file:
|
Method used for encryption when the buffer is written to a file:
|
||||||
*pkzip*
|
*pkzip*
|
||||||
0 PkZip compatible method. A weak kind of encryption.
|
zip PkZip compatible method. A weak kind of encryption.
|
||||||
Backwards compatible with Vim 7.2 and older.
|
Backwards compatible with Vim 7.2 and older.
|
||||||
*blowfish*
|
*blowfish*
|
||||||
1 Blowfish method. Strong encryption. Requires Vim 7.3
|
blowfish Blowfish method. Strong encryption. Requires Vim 7.3
|
||||||
or later, files can NOT be read by Vim 7.2 and older.
|
or later, files can NOT be read by Vim 7.2 and older.
|
||||||
This adds a "seed" to the file, every time you write
|
This adds a "seed" to the file, every time you write
|
||||||
the file the encrypted bytes will be different.
|
the file the encrypted bytes will be different.
|
||||||
@@ -2091,10 +2091,16 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
to the detected method of the file being read. Thus if you write it
|
to the detected method of the file being read. Thus if you write it
|
||||||
without changing 'cryptmethod' the same method will be used.
|
without changing 'cryptmethod' the same method will be used.
|
||||||
Changing 'cryptmethod' does not mark the file as modified, you have to
|
Changing 'cryptmethod' does not mark the file as modified, you have to
|
||||||
explicitly write it when not making modifications.
|
explicitly write it, you don't get a warning unless there are other
|
||||||
Also see |:X|.
|
modifications. Also see |:X|.
|
||||||
|
|
||||||
|
When setting the global value to an empty string, it will end up with
|
||||||
|
the value "zip". When setting the local value to an empty string the
|
||||||
|
buffer will use the global value.
|
||||||
|
|
||||||
When a new encryption method is added in a later version of Vim, and
|
When a new encryption method is added in a later version of Vim, and
|
||||||
the current version does not recognize it, you will get *E821* .
|
the current version does not recognize it, you will get *E821* .
|
||||||
|
You need to edit this file with the later version of Vim.
|
||||||
|
|
||||||
|
|
||||||
*'cscopepathcomp'* *'cspc'*
|
*'cscopepathcomp'* *'cspc'*
|
||||||
|
|||||||
@@ -30,19 +30,10 @@ be worked on, but only if you sponsor Vim development. See |sponsor|.
|
|||||||
*known-bugs*
|
*known-bugs*
|
||||||
-------------------- Known bugs and current work -----------------------
|
-------------------- Known bugs and current work -----------------------
|
||||||
|
|
||||||
GTK: torn-off menu doesn't work. Because of patch for file selector?
|
GTK: torn-off menu doesn't work.
|
||||||
|
|
||||||
Win64: diff.exe crashes on Win64. (Julianne Bailey, 2006 Dec 12)
|
|
||||||
Build another diff.exe somehow?
|
|
||||||
|
|
||||||
:find completion has duplicates. (Bjorn Winckler, 2010 Jul 18)
|
:find completion has duplicates. (Bjorn Winckler, 2010 Jul 18)
|
||||||
|
|
||||||
Conceal: don't show for 'hlmatch' when 'modifiable' is off?
|
|
||||||
And don't care about 'cursorline'.
|
|
||||||
|
|
||||||
Make 'cryptmethod' global-local, so that a default specified in a .vimrc file
|
|
||||||
is used for new files. (Christian J. Robinson)
|
|
||||||
|
|
||||||
Cursor positioning wrong with 0x200e character. (John Becket, 2010 May 6)
|
Cursor positioning wrong with 0x200e character. (John Becket, 2010 May 6)
|
||||||
|
|
||||||
Test 69 breaks on MS-Windows, both 32 and 64 builds. (George Reilly, 2010 Feb
|
Test 69 breaks on MS-Windows, both 32 and 64 builds. (George Reilly, 2010 Feb
|
||||||
|
|||||||
@@ -7265,7 +7265,7 @@ Added the |strchars()|, |strwidth()| and |strdisplaywidth()| functions.
|
|||||||
|
|
||||||
Support GDK_SUPER_MASK for GTK on Mac. (Stephan Schulz)
|
Support GDK_SUPER_MASK for GTK on Mac. (Stephan Schulz)
|
||||||
|
|
||||||
Made CTRL modifier work for mouse wheel. (Benjamin Haskell)
|
Made CTRL and ALT modifier work for mouse wheel. (Benjamin Haskell)
|
||||||
|
|
||||||
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
|
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
|
||||||
side-by-side. (Christian Brabandt)
|
side-by-side. (Christian Brabandt)
|
||||||
@@ -10031,5 +10031,10 @@ Window title not updated after file dropped.
|
|||||||
|
|
||||||
"g8" doesn't work properly on a NUL.
|
"g8" doesn't work properly on a NUL.
|
||||||
|
|
||||||
|
Fixed crash for ":find" completion, might also happen in other path expansion
|
||||||
|
usage.
|
||||||
|
|
||||||
|
When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
|
||||||
|
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:
|
vim:tw=78:ts=8:ft=help:norl:
|
||||||
|
|||||||
@@ -1756,6 +1756,9 @@ free_buf_options(buf, free_p_ff)
|
|||||||
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
||||||
clear_string_option(&buf->b_p_bexpr);
|
clear_string_option(&buf->b_p_bexpr);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(FEAT_CRYPT)
|
||||||
|
clear_string_option(&buf->b_p_cm);
|
||||||
|
#endif
|
||||||
#if defined(FEAT_EVAL)
|
#if defined(FEAT_EVAL)
|
||||||
clear_string_option(&buf->b_p_fex);
|
clear_string_option(&buf->b_p_fex);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -11189,7 +11189,7 @@ ex_match(eap)
|
|||||||
ex_X(eap)
|
ex_X(eap)
|
||||||
exarg_T *eap UNUSED;
|
exarg_T *eap UNUSED;
|
||||||
{
|
{
|
||||||
if (curbuf->b_p_cm == 0 || blowfish_self_test() == OK)
|
if (get_crypt_method(curbuf) == 0 || blowfish_self_test() == OK)
|
||||||
(void)get_crypt_key(TRUE, TRUE);
|
(void)get_crypt_key(TRUE, TRUE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
20
src/fileio.c
20
src/fileio.c
@@ -63,7 +63,7 @@ static char_u *readfile_charconvert __ARGS((char_u *fname, char_u *fenc, int *fd
|
|||||||
static void check_marks_read __ARGS((void));
|
static void check_marks_read __ARGS((void));
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_CRYPT
|
#ifdef FEAT_CRYPT
|
||||||
static int get_crypt_method __ARGS((char *ptr, int len));
|
static int crypt_method_from_magic __ARGS((char *ptr, int len));
|
||||||
static char_u *check_for_cryptkey __ARGS((char_u *cryptkey, char_u *ptr, long *sizep, off_t *filesizep, int newfile, char_u *fname, int *did_ask));
|
static char_u *check_for_cryptkey __ARGS((char_u *cryptkey, char_u *ptr, long *sizep, off_t *filesizep, int newfile, char_u *fname, int *did_ask));
|
||||||
#endif
|
#endif
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
@@ -2855,7 +2855,7 @@ check_marks_read()
|
|||||||
* Returns -1 when no encryption used.
|
* Returns -1 when no encryption used.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
get_crypt_method(ptr, len)
|
crypt_method_from_magic(ptr, len)
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int len;
|
int len;
|
||||||
{
|
{
|
||||||
@@ -2892,11 +2892,11 @@ check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask)
|
|||||||
char_u *fname; /* file name to display */
|
char_u *fname; /* file name to display */
|
||||||
int *did_ask; /* flag: whether already asked for key */
|
int *did_ask; /* flag: whether already asked for key */
|
||||||
{
|
{
|
||||||
int method = get_crypt_method((char *)ptr, *sizep);
|
int method = crypt_method_from_magic((char *)ptr, *sizep);
|
||||||
|
|
||||||
if (method >= 0)
|
if (method >= 0)
|
||||||
{
|
{
|
||||||
curbuf->b_p_cm = method;
|
set_crypt_method(curbuf, method);
|
||||||
if (method > 0)
|
if (method > 0)
|
||||||
(void)blowfish_self_test();
|
(void)blowfish_self_test();
|
||||||
if (cryptkey == NULL && !*did_ask)
|
if (cryptkey == NULL && !*did_ask)
|
||||||
@@ -2968,11 +2968,11 @@ prepare_crypt_read(fp)
|
|||||||
|
|
||||||
if (fread(buffer, CRYPT_MAGIC_LEN, 1, fp) != 1)
|
if (fread(buffer, CRYPT_MAGIC_LEN, 1, fp) != 1)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
method = get_crypt_method((char *)buffer,
|
method = crypt_method_from_magic((char *)buffer,
|
||||||
CRYPT_MAGIC_LEN +
|
CRYPT_MAGIC_LEN +
|
||||||
CRYPT_SEED_LEN_MAX +
|
CRYPT_SEED_LEN_MAX +
|
||||||
CRYPT_SALT_LEN_MAX);
|
CRYPT_SALT_LEN_MAX);
|
||||||
if (method < 0 || method != curbuf->b_p_cm)
|
if (method < 0 || method != get_crypt_method(curbuf))
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
crypt_push_state();
|
crypt_push_state();
|
||||||
@@ -3003,8 +3003,8 @@ prepare_crypt_write(buf, lenp)
|
|||||||
int *lenp;
|
int *lenp;
|
||||||
{
|
{
|
||||||
char_u *header;
|
char_u *header;
|
||||||
int seed_len = crypt_seed_len[buf->b_p_cm];
|
int seed_len = crypt_seed_len[get_crypt_method(buf)];
|
||||||
int salt_len = crypt_salt_len[buf->b_p_cm];
|
int salt_len = crypt_salt_len[get_crypt_method(buf)];
|
||||||
char_u *salt;
|
char_u *salt;
|
||||||
char_u *seed;
|
char_u *seed;
|
||||||
|
|
||||||
@@ -3013,10 +3013,10 @@ prepare_crypt_write(buf, lenp)
|
|||||||
if (header != NULL)
|
if (header != NULL)
|
||||||
{
|
{
|
||||||
crypt_push_state();
|
crypt_push_state();
|
||||||
use_crypt_method = buf->b_p_cm; /* select pkzip or blowfish */
|
use_crypt_method = get_crypt_method(buf); /* select zip or blowfish */
|
||||||
vim_strncpy(header, (char_u *)crypt_magic[use_crypt_method],
|
vim_strncpy(header, (char_u *)crypt_magic[use_crypt_method],
|
||||||
CRYPT_MAGIC_LEN);
|
CRYPT_MAGIC_LEN);
|
||||||
if (buf->b_p_cm == 0)
|
if (use_crypt_method == 0)
|
||||||
crypt_init_keys(buf->b_p_key);
|
crypt_init_keys(buf->b_p_key);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ ml_set_b0_crypt(buf, b0p)
|
|||||||
b0p->b0_id[1] = BLOCK0_ID1;
|
b0p->b0_id[1] = BLOCK0_ID1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (buf->b_p_cm == 0)
|
if (get_crypt_method(buf) == 0)
|
||||||
b0p->b0_id[1] = BLOCK0_ID1_C0;
|
b0p->b0_id[1] = BLOCK0_ID1_C0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -458,8 +458,8 @@ ml_set_b0_crypt(buf, b0p)
|
|||||||
* Will apply this to the swapfile.
|
* Will apply this to the swapfile.
|
||||||
* "old_key" is the previous key. It is equal to buf->b_p_key when
|
* "old_key" is the previous key. It is equal to buf->b_p_key when
|
||||||
* 'cryptmethod' is changed.
|
* 'cryptmethod' is changed.
|
||||||
* "old_cm" is the previous 'cryptmethod'. It is equal to buf->b_p_cm when
|
* "old_cm" is the previous 'cryptmethod'. It is equal to the current
|
||||||
* 'key' is changed.
|
* 'cryptmethod' when 'key' is changed.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ml_set_crypt_key(buf, old_key, old_cm)
|
ml_set_crypt_key(buf, old_key, old_cm)
|
||||||
@@ -1250,12 +1250,13 @@ ml_recover()
|
|||||||
|
|
||||||
#ifdef FEAT_CRYPT
|
#ifdef FEAT_CRYPT
|
||||||
if (b0p->b0_id[1] == BLOCK0_ID1_C0)
|
if (b0p->b0_id[1] == BLOCK0_ID1_C0)
|
||||||
buf->b_p_cm = b0_cm = 0;
|
b0_cm = 0;
|
||||||
else if (b0p->b0_id[1] == BLOCK0_ID1_C1)
|
else if (b0p->b0_id[1] == BLOCK0_ID1_C1)
|
||||||
{
|
{
|
||||||
buf->b_p_cm = b0_cm = 1;
|
b0_cm = 1;
|
||||||
mch_memmove(mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN);
|
mch_memmove(mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN);
|
||||||
}
|
}
|
||||||
|
set_crypt_method(buf, b0_cm);
|
||||||
#else
|
#else
|
||||||
if (b0p->b0_id[1] != BLOCK0_ID1)
|
if (b0p->b0_id[1] != BLOCK0_ID1)
|
||||||
{
|
{
|
||||||
@@ -4908,7 +4909,7 @@ ml_crypt_prepare(mfp, offset, reading)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
method = buf->b_p_cm;
|
method = get_crypt_method(buf);
|
||||||
key = buf->b_p_key;
|
key = buf->b_p_key;
|
||||||
seed = mfp->mf_seed;
|
seed = mfp->mf_seed;
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/misc2.c
35
src/misc2.c
@@ -3750,6 +3750,41 @@ static int crypt_busy = 0;
|
|||||||
static ulg saved_keys[3];
|
static ulg saved_keys[3];
|
||||||
static int saved_crypt_method;
|
static int saved_crypt_method;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return int value for crypt method string:
|
||||||
|
* 0 for "zip", the old method. Also for any non-valid value.
|
||||||
|
* 1 for "blowfish".
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
crypt_method_from_string(s)
|
||||||
|
char_u *s;
|
||||||
|
{
|
||||||
|
return *s == 'b' ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the crypt method for buffer "buf" as a number.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
get_crypt_method(buf)
|
||||||
|
buf_T *buf;
|
||||||
|
{
|
||||||
|
return crypt_method_from_string(*buf->b_p_cm == NUL ? p_cm : buf->b_p_cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the crypt method for buffer "buf" to "method" using the int value as
|
||||||
|
* returned by crypt_method_from_string().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
set_crypt_method(buf, method)
|
||||||
|
buf_T *buf;
|
||||||
|
int method;
|
||||||
|
{
|
||||||
|
free_string_option(buf->b_p_cm);
|
||||||
|
buf->b_p_cm = vim_strsave((char_u *)(method == 0 ? "zip" : "blowfish"));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare for initializing encryption. If already doing encryption then save
|
* Prepare for initializing encryption. If already doing encryption then save
|
||||||
* the state.
|
* the state.
|
||||||
|
|||||||
104
src/option.c
104
src/option.c
@@ -77,7 +77,7 @@
|
|||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
# define PV_CINW OPT_BUF(BV_CINW)
|
# define PV_CINW OPT_BUF(BV_CINW)
|
||||||
#endif
|
#endif
|
||||||
#define PV_CM OPT_BUF(BV_CM)
|
#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
# define PV_CMS OPT_BUF(BV_CMS)
|
# define PV_CMS OPT_BUF(BV_CMS)
|
||||||
#endif
|
#endif
|
||||||
@@ -287,9 +287,6 @@ static char_u *p_cino;
|
|||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
static char_u *p_cinw;
|
static char_u *p_cinw;
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_CRYPT
|
|
||||||
static long p_cm;
|
|
||||||
#endif
|
|
||||||
#ifdef FEAT_COMMENTS
|
#ifdef FEAT_COMMENTS
|
||||||
static char_u *p_com;
|
static char_u *p_com;
|
||||||
#endif
|
#endif
|
||||||
@@ -866,13 +863,15 @@ static struct vimoption
|
|||||||
(char_u *)&p_cpo, PV_NONE,
|
(char_u *)&p_cpo, PV_NONE,
|
||||||
{(char_u *)CPO_VI, (char_u *)CPO_VIM}
|
{(char_u *)CPO_VI, (char_u *)CPO_VIM}
|
||||||
SCRIPTID_INIT},
|
SCRIPTID_INIT},
|
||||||
{"cryptmethod", "cm", P_NUM|P_VI_DEF|P_VIM,
|
{"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
|
||||||
#ifdef FEAT_CRYPT
|
#ifdef FEAT_CRYPT
|
||||||
(char_u *)&p_cm, PV_CM,
|
(char_u *)&p_cm, PV_CM,
|
||||||
|
{(char_u *)"zip", (char_u *)0L}
|
||||||
#else
|
#else
|
||||||
(char_u *)NULL, PV_NONE,
|
(char_u *)NULL, PV_NONE,
|
||||||
|
{(char_u *)0L, (char_u *)0L}
|
||||||
#endif
|
#endif
|
||||||
{(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
|
SCRIPTID_INIT},
|
||||||
{"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
|
{"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
|
||||||
#ifdef FEAT_CSCOPE
|
#ifdef FEAT_CSCOPE
|
||||||
(char_u *)&p_cspc, PV_NONE,
|
(char_u *)&p_cspc, PV_NONE,
|
||||||
@@ -2915,6 +2914,9 @@ static char *(p_ambw_values[]) = {"single", "double", NULL};
|
|||||||
static char *(p_bg_values[]) = {"light", "dark", NULL};
|
static char *(p_bg_values[]) = {"light", "dark", NULL};
|
||||||
static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
|
static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
|
||||||
static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
|
static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
|
||||||
|
#ifdef FEAT_CRYPT
|
||||||
|
static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
|
||||||
|
#endif
|
||||||
#ifdef FEAT_CMDL_COMPL
|
#ifdef FEAT_CMDL_COMPL
|
||||||
static char *(p_wop_values[]) = {"tagfile", NULL};
|
static char *(p_wop_values[]) = {"tagfile", NULL};
|
||||||
#endif
|
#endif
|
||||||
@@ -5215,6 +5217,9 @@ check_buf_options(buf)
|
|||||||
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
||||||
check_string_option(&buf->b_p_bexpr);
|
check_string_option(&buf->b_p_bexpr);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(FEAT_CRYPT)
|
||||||
|
check_string_option(&buf->b_p_cm);
|
||||||
|
#endif
|
||||||
#if defined(FEAT_EVAL)
|
#if defined(FEAT_EVAL)
|
||||||
check_string_option(&buf->b_p_fex);
|
check_string_option(&buf->b_p_fex);
|
||||||
#endif
|
#endif
|
||||||
@@ -5998,7 +6003,57 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
|
|||||||
# endif
|
# endif
|
||||||
if (STRCMP(curbuf->b_p_key, oldval) != 0)
|
if (STRCMP(curbuf->b_p_key, oldval) != 0)
|
||||||
/* Need to update the swapfile. */
|
/* Need to update the swapfile. */
|
||||||
ml_set_crypt_key(curbuf, oldval, curbuf->b_p_cm);
|
ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (gvarp == &p_cm)
|
||||||
|
{
|
||||||
|
if (opt_flags & OPT_LOCAL)
|
||||||
|
p = curbuf->b_p_cm;
|
||||||
|
else
|
||||||
|
p = p_cm;
|
||||||
|
if (check_opt_strings(p, p_cm_values, TRUE) != OK)
|
||||||
|
errmsg = e_invarg;
|
||||||
|
else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
|
||||||
|
errmsg = e_invarg;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* When setting the global value to empty, make it "zip". */
|
||||||
|
if (*p_cm == NUL)
|
||||||
|
{
|
||||||
|
if (new_value_alloced)
|
||||||
|
free_string_option(p_cm);
|
||||||
|
p_cm = vim_strsave((char_u *)"zip");
|
||||||
|
new_value_alloced = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Need to update the swapfile when the effective method changed.
|
||||||
|
* Set "s" to the effective old value, "p" to the effective new
|
||||||
|
* method and compare. */
|
||||||
|
if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
|
||||||
|
s = p_cm; /* was previously using the global value */
|
||||||
|
else
|
||||||
|
s = oldval;
|
||||||
|
if (*curbuf->b_p_cm == NUL)
|
||||||
|
p = p_cm; /* is now using the global value */
|
||||||
|
else
|
||||||
|
p = curbuf->b_p_cm;
|
||||||
|
if (STRCMP(s, p) != 0)
|
||||||
|
ml_set_crypt_key(curbuf, curbuf->b_p_key,
|
||||||
|
crypt_method_from_string(s));
|
||||||
|
|
||||||
|
/* If the global value changes need to update the swapfile for all
|
||||||
|
* buffers using that value. */
|
||||||
|
if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
|
||||||
|
{
|
||||||
|
buf_T *buf;
|
||||||
|
|
||||||
|
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
||||||
|
if (buf != curbuf && *buf->b_p_cm == NUL)
|
||||||
|
ml_set_crypt_key(buf, buf->b_p_key,
|
||||||
|
crypt_method_from_string(oldval));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -8048,28 +8103,6 @@ set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_CRYPT
|
|
||||||
else if (pp == &curbuf->b_p_cm)
|
|
||||||
{
|
|
||||||
if (curbuf->b_p_cm < 0)
|
|
||||||
{
|
|
||||||
errmsg = e_positive;
|
|
||||||
curbuf->b_p_cm = old_value;
|
|
||||||
}
|
|
||||||
if (curbuf->b_p_cm > 1)
|
|
||||||
{
|
|
||||||
errmsg = e_invarg;
|
|
||||||
curbuf->b_p_cm = old_value;
|
|
||||||
}
|
|
||||||
if (curbuf->b_p_cm > 0 && blowfish_self_test() == FAIL)
|
|
||||||
curbuf->b_p_cm = old_value;
|
|
||||||
|
|
||||||
if (curbuf->b_p_cm != old_value && *curbuf->b_p_key != NUL)
|
|
||||||
/* Need to update the swapfile. */
|
|
||||||
ml_set_crypt_key(curbuf, curbuf->b_p_key, old_value);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FEAT_WINDOWS
|
#ifdef FEAT_WINDOWS
|
||||||
/* (re)set last window status line */
|
/* (re)set last window status line */
|
||||||
else if (pp == &p_ls)
|
else if (pp == &p_ls)
|
||||||
@@ -9383,6 +9416,9 @@ get_varp_scope(p, opt_flags)
|
|||||||
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
||||||
case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
|
case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(FEAT_CRYPT)
|
||||||
|
case PV_CM: return (char_u *)&(curbuf->b_p_cm);
|
||||||
|
#endif
|
||||||
#ifdef FEAT_STL_OPT
|
#ifdef FEAT_STL_OPT
|
||||||
case PV_STL: return (char_u *)&(curwin->w_p_stl);
|
case PV_STL: return (char_u *)&(curwin->w_p_stl);
|
||||||
#endif
|
#endif
|
||||||
@@ -9442,6 +9478,10 @@ get_varp(p)
|
|||||||
case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
|
case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
|
||||||
? (char_u *)&(curbuf->b_p_bexpr) : p->var;
|
? (char_u *)&(curbuf->b_p_bexpr) : p->var;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(FEAT_CRYPT)
|
||||||
|
case PV_CM: return *curbuf->b_p_cm != NUL
|
||||||
|
? (char_u *)&(curbuf->b_p_cm) : p->var;
|
||||||
|
#endif
|
||||||
#ifdef FEAT_STL_OPT
|
#ifdef FEAT_STL_OPT
|
||||||
case PV_STL: return *curwin->w_p_stl != NUL
|
case PV_STL: return *curwin->w_p_stl != NUL
|
||||||
? (char_u *)&(curwin->w_p_stl) : p->var;
|
? (char_u *)&(curwin->w_p_stl) : p->var;
|
||||||
@@ -9525,9 +9565,6 @@ get_varp(p)
|
|||||||
case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
|
case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
|
||||||
case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
|
case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_CRYPT
|
|
||||||
case PV_CM: return (char_u *)&(curbuf->b_p_cm);
|
|
||||||
#endif
|
|
||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
|
case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
|
||||||
#endif
|
#endif
|
||||||
@@ -9994,6 +10031,9 @@ buf_copy_options(buf, flags)
|
|||||||
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
||||||
buf->b_p_bexpr = empty_option;
|
buf->b_p_bexpr = empty_option;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(FEAT_CRYPT)
|
||||||
|
buf->b_p_cm = empty_option;
|
||||||
|
#endif
|
||||||
#ifdef FEAT_PERSISTENT_UNDO
|
#ifdef FEAT_PERSISTENT_UNDO
|
||||||
buf->b_p_udf = p_udf;
|
buf->b_p_udf = p_udf;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -333,6 +333,9 @@ EXTERN char_u *p_bex; /* 'backupext' */
|
|||||||
#ifdef FEAT_WILDIGN
|
#ifdef FEAT_WILDIGN
|
||||||
EXTERN char_u *p_bsk; /* 'backupskip' */
|
EXTERN char_u *p_bsk; /* 'backupskip' */
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef FEAT_CRYPT
|
||||||
|
EXTERN char_u *p_cm; /* 'cryptmethod' */
|
||||||
|
#endif
|
||||||
#ifdef FEAT_BEVAL
|
#ifdef FEAT_BEVAL
|
||||||
EXTERN long p_bdlay; /* 'balloondelay' */
|
EXTERN long p_bdlay; /* 'balloondelay' */
|
||||||
EXTERN int p_beval; /* 'ballooneval' */
|
EXTERN int p_beval; /* 'ballooneval' */
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ int illegal_slash __ARGS((char *name));
|
|||||||
char_u *parse_shape_opt __ARGS((int what));
|
char_u *parse_shape_opt __ARGS((int what));
|
||||||
int get_shape_idx __ARGS((int mouse));
|
int get_shape_idx __ARGS((int mouse));
|
||||||
void update_mouseshape __ARGS((int shape_idx));
|
void update_mouseshape __ARGS((int shape_idx));
|
||||||
|
int crypt_method_from_string __ARGS((char_u *s));
|
||||||
|
int get_crypt_method __ARGS((buf_T *buf));
|
||||||
|
void set_crypt_method __ARGS((buf_T *buf, int method));
|
||||||
void crypt_push_state __ARGS((void));
|
void crypt_push_state __ARGS((void));
|
||||||
void crypt_pop_state __ARGS((void));
|
void crypt_pop_state __ARGS((void));
|
||||||
void crypt_encode __ARGS((char_u *from, size_t len, char_u *to));
|
void crypt_encode __ARGS((char_u *from, size_t len, char_u *to));
|
||||||
|
|||||||
@@ -1450,9 +1450,6 @@ struct file_buffer
|
|||||||
#ifdef FEAT_INS_EXPAND
|
#ifdef FEAT_INS_EXPAND
|
||||||
char_u *b_p_cpt; /* 'complete' */
|
char_u *b_p_cpt; /* 'complete' */
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_CRYPT
|
|
||||||
long b_p_cm; /* 'cryptmethod' */
|
|
||||||
#endif
|
|
||||||
#ifdef FEAT_COMPL_FUNC
|
#ifdef FEAT_COMPL_FUNC
|
||||||
char_u *b_p_cfu; /* 'completefunc' */
|
char_u *b_p_cfu; /* 'completefunc' */
|
||||||
char_u *b_p_ofu; /* 'omnifunc' */
|
char_u *b_p_ofu; /* 'omnifunc' */
|
||||||
@@ -1574,6 +1571,9 @@ struct file_buffer
|
|||||||
char_u *b_p_bexpr; /* 'balloonexpr' local value */
|
char_u *b_p_bexpr; /* 'balloonexpr' local value */
|
||||||
long_u b_p_bexpr_flags;/* flags for 'balloonexpr' */
|
long_u b_p_bexpr_flags;/* flags for 'balloonexpr' */
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef FEAT_CRYPT
|
||||||
|
char_u *b_p_cm; /* 'cryptmethod' */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* When a buffer is created, it starts without a swap file. b_may_swap is
|
/* When a buffer is created, it starts without a swap file. b_may_swap is
|
||||||
* then set to indicate that a swap file may be opened later. It is reset
|
* then set to indicate that a swap file may be opened later. It is reset
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ STARTTEST
|
|||||||
:so small.vim
|
:so small.vim
|
||||||
:/^start of text/+1
|
:/^start of text/+1
|
||||||
:let text_lines = getline('.', line('.') + 2)
|
:let text_lines = getline('.', line('.') + 2)
|
||||||
:/^start of cm=0 bytes/+1
|
:/^start of cm=zip bytes/+1
|
||||||
:let cm0_bytes = getline('.', '.')
|
:let cm0_bytes = getline('.', '.')
|
||||||
:/^start of cm=1 bytes/+1
|
:/^start of cm=blowfish bytes/+1
|
||||||
:let cm1_bytes = getline('.', '.')
|
:let cm1_bytes = getline('.', '.')
|
||||||
:bwipe
|
:bwipe
|
||||||
:call append(0, text_lines)
|
:call append(0, text_lines)
|
||||||
@@ -20,9 +20,9 @@ foobar
|
|||||||
foobar
|
foobar
|
||||||
:let cm0_read_back = getline('.', '$')
|
:let cm0_read_back = getline('.', '$')
|
||||||
:set key=
|
:set key=
|
||||||
:set cryptmethod=1
|
:set cryptmethod=blowfish
|
||||||
:" If the blowfish test fails 'cryptmethod' will be 0 now.
|
:" If the blowfish test fails 'cryptmethod' will be 'zip' now.
|
||||||
:%s/^/\=&cryptmethod == 1 ? "OK " : "blowfish test failed "/
|
:%s/^/\=&cryptmethod == 'blowfish' ? "OK " : "blowfish test failed "/
|
||||||
:X
|
:X
|
||||||
barfoo
|
barfoo
|
||||||
barfoo
|
barfoo
|
||||||
@@ -66,10 +66,10 @@ line 2 foo bar blah
|
|||||||
line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
end of text
|
end of text
|
||||||
|
|
||||||
start of cm=0 bytes
|
start of cm=zip bytes
|
||||||
VimCrypt~01!lV'<27>}Mg<4D><67><EFBFBD>V<EFBFBD><56>E#3<>2U<32><55>
|
VimCrypt~01!lV'<27>}Mg<4D><67><EFBFBD>V<EFBFBD><56>E#3<>2U<32><55>
|
||||||
end of cm=0 bytes
|
end of cm=zip bytes
|
||||||
|
|
||||||
start of cm=1 bytes
|
start of cm=blowfish bytes
|
||||||
VimCrypt~02!k)<29><17>#<16>S<EFBFBD><53>=<3D><><EFBFBD>#<23>M<EFBFBD><4D>J<EFBFBD>AͥM<CDA5><4D>!<21><15><><0F><><19><16><>
|
VimCrypt~02!k)<29><17>#<16>S<EFBFBD><53>=<3D><><EFBFBD>#<23>M<EFBFBD><4D>J<EFBFBD>AͥM<CDA5><4D>!<21><15><><0F><><19><16><>
|
||||||
<EFBFBD>
|
<EFBFBD>
|
||||||
|
|||||||
Reference in New Issue
Block a user