Skip to content

Commit 36a614b

Browse files
committed
updated for version 7.3.816
Problem: Can't compute a hash. Solution: Add the sha256() function. (Tyru, Hirohito Higashi)
1 parent d7c5fc2 commit 36a614b

File tree

11 files changed

+43
-9
lines changed

11 files changed

+43
-9
lines changed

runtime/doc/eval.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,7 @@ settabvar( {nr}, {varname}, {val}) set {varname} in tab page {nr} to {val}
19311931
settabwinvar( {tabnr}, {winnr}, {varname}, {val}) set {varname} in window
19321932
{winnr} in tab page {tabnr} to {val}
19331933
setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val}
1934+
sha256( {string}) String SHA256 checksum of {string}
19341935
shellescape( {string} [, {special}])
19351936
String escape {string} for use as shell
19361937
command argument
@@ -5336,6 +5337,11 @@ setwinvar({nr}, {varname}, {val}) *setwinvar()*
53365337
:call setwinvar(1, "&list", 0)
53375338
:call setwinvar(2, "myvar", "foobar")
53385339
5340+
sha256({string}) *sha256()*
5341+
Returns a String with 64 hex charactes, which is the SHA256
5342+
checksum of {string}.
5343+
{only available when compiled with the |+cryptv| feature}
5344+
53395345
shellescape({string} [, {special}]) *shellescape()*
53405346
Escape {string} for use as a shell command argument.
53415347
On MS-Windows and MS-DOS, when 'shellslash' is not set, it

src/eval.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv));
688688
static void f_settabvar __ARGS((typval_T *argvars, typval_T *rettv));
689689
static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
690690
static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
691+
#ifdef FEAT_CRYPT
692+
static void f_sha256 __ARGS((typval_T *argvars, typval_T *rettv));
693+
#endif /* FEAT_CRYPT */
691694
static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
692695
static void f_shiftwidth __ARGS((typval_T *argvars, typval_T *rettv));
693696
static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
@@ -8055,6 +8058,9 @@ static struct fst
80558058
{"settabvar", 3, 3, f_settabvar},
80568059
{"settabwinvar", 4, 4, f_settabwinvar},
80578060
{"setwinvar", 3, 3, f_setwinvar},
8061+
#ifdef FEAT_CRYPT
8062+
{"sha256", 1, 1, f_sha256},
8063+
#endif
80588064
{"shellescape", 1, 2, f_shellescape},
80598065
{"shiftwidth", 0, 0, f_shiftwidth},
80608066
{"simplify", 1, 1, f_simplify},
@@ -16710,6 +16716,24 @@ setwinvar(argvars, rettv, off)
1671016716
}
1671116717
}
1671216718

16719+
#ifdef FEAT_CRYPT
16720+
/*
16721+
* "sha256({string})" function
16722+
*/
16723+
static void
16724+
f_sha256(argvars, rettv)
16725+
typval_T *argvars;
16726+
typval_T *rettv;
16727+
{
16728+
char_u *p;
16729+
16730+
p = get_tv_string(&argvars[0]);
16731+
rettv->vval.v_string = vim_strsave(
16732+
sha256_bytes(p, (int)STRLEN(p), NULL, 0));
16733+
rettv->v_type = VAR_STRING;
16734+
}
16735+
#endif /* FEAT_CRYPT */
16736+
1671316737
/*
1671416738
* "shellescape({string})" function
1671516739
*/

src/proto/sha256.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
void sha256_start __ARGS((context_sha256_T *ctx));
33
void sha256_update __ARGS((context_sha256_T *ctx, char_u *input, UINT32_T length));
44
void sha256_finish __ARGS((context_sha256_T *ctx, char_u digest[32]));
5+
char_u *sha256_bytes __ARGS((char_u *buf, int buf_len, char_u *salt, int salt_len));
56
char_u *sha256_key __ARGS((char_u *buf, char_u *salt, int salt_len));
67
int sha256_self_test __ARGS((void));
78
void sha2_seed __ARGS((char_u *header, int header_len, char_u *salt, int salt_len));

src/sha256.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,13 @@ sha256_finish(ctx, digest)
273273
#endif /* FEAT_CRYPT || FEAT_PERSISTENT_UNDO */
274274

275275
#if defined(FEAT_CRYPT) || defined(PROTO)
276-
static char_u *sha256_bytes __ARGS((char_u *buf, int buf_len, char_u *salt, int salt_len));
277276
static unsigned int get_some_time __ARGS((void));
278277

279278
/*
280279
* Returns hex digest of "buf[buf_len]" in a static array.
281280
* if "salt" is not NULL also do "salt[salt_len]".
282281
*/
283-
static char_u *
282+
char_u *
284283
sha256_bytes(buf, buf_len, salt, salt_len)
285284
char_u *buf;
286285
int buf_len;

src/testdir/Make_amiga.mak

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
3232
test71.out test72.out test73.out test74.out test75.out \
3333
test76.out test77.out test78.out test79.out test80.out \
3434
test81.out test82.out test83.out test84.out test88.out \
35-
test89.out
35+
test89.out test90.out
3636

3737
.SUFFIXES: .in .out
3838

@@ -138,3 +138,4 @@ test83.out: test83.in
138138
test84.out: test84.in
139139
test88.out: test88.in
140140
test89.out: test89.in
141+
test90.out: test90.in

src/testdir/Make_dos.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
3131
test74.out test75.out test76.out test77.out test78.out \
3232
test79.out test80.out test81.out test82.out test83.out \
3333
test84.out test85.out test86.out test87.out test88.out \
34-
test89.out
34+
test89.out test90.out
3535

3636
SCRIPTS32 = test50.out test70.out
3737

src/testdir/Make_ming.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
5151
test74.out test75.out test76.out test77.out test78.out \
5252
test79.out test80.out test81.out test82.out test83.out \
5353
test84.out test85.out test86.out test87.out test88.out \
54-
test89.out
54+
test89.out test90.out
5555

5656
SCRIPTS32 = test50.out test70.out
5757

src/testdir/Make_os2.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
3232
test71.out test72.out test73.out test74.out test75.out \
3333
test76.out test77.out test78.out test79.out test80.out \
3434
test81.out test82.out test83.out test84.out test88.out \
35-
test89.out
35+
test89.out test90.out
3636

3737
.SUFFIXES: .in .out
3838

src/testdir/Make_vms.mms

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Authors: Zoltan Arpadffy, <[email protected]>
55
# Sandor Kopanyi, <[email protected]>
66
#
7-
# Last change: 2012 Dec 05
7+
# Last change: 2013 Feb 13
88
#
99
# This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
1010
# Edit the lines in the Configuration section below to select.
@@ -76,7 +76,8 @@ SCRIPT = test1.out test2.out test3.out test4.out test5.out \
7676
test66.out test67.out test68.out test69.out \
7777
test71.out test72.out test74.out test75.out test76.out \
7878
test77.out test78.out test79.out test80.out test81.out \
79-
test82.out test83.out test84.out test88.out test89.out
79+
test82.out test83.out test84.out test88.out test89.out \
80+
test90.out
8081

8182
# Known problems:
8283
# Test 30: a problem around mac format - unknown reason

src/testdir/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
2828
test74.out test75.out test76.out test77.out test78.out \
2929
test79.out test80.out test81.out test82.out test83.out \
3030
test84.out test85.out test86.out test87.out test88.out \
31-
test89.out
31+
test89.out test90.out
3232

3333
SCRIPTS_GUI = test16.out
3434

0 commit comments

Comments
 (0)