1. ZyX_I
  2. vim

Commits

Bram Moolenaar  committed 2b340e5

updated for version 7.3.816
Problem: Can't compute a hash.
Solution: Add the sha256() function. (Tyru, Hirohito Higashi)

  • Participants
  • Parent commits 8443bfa
  • Branches default
  • Tags v7.3.816

Comments (0)

Files changed (11)

File runtime/doc/eval.txt

View file
 settabwinvar( {tabnr}, {winnr}, {varname}, {val})    set {varname} in window
 					{winnr} in tab page {tabnr} to {val}
 setwinvar( {nr}, {varname}, {val})	set {varname} in window {nr} to {val}
+sha256( {string})		String	SHA256 checksum of {string}
 shellescape( {string} [, {special}])
 				String	escape {string} for use as shell
 					command argument
 			:call setwinvar(1, "&list", 0)
 			:call setwinvar(2, "myvar", "foobar")
 
+sha256({string})						*sha256()*
+		Returns a String with 64 hex charactes, which is the SHA256
+		checksum of {string}.
+		{only available when compiled with the |+cryptv| feature}
+
 shellescape({string} [, {special}])			*shellescape()*
 		Escape {string} for use as a shell command argument.
 		On MS-Windows and MS-DOS, when 'shellslash' is not set, it

File src/eval.c

View file
 static void f_settabvar __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
+#ifdef FEAT_CRYPT
+static void f_sha256 __ARGS((typval_T *argvars, typval_T *rettv));
+#endif /* FEAT_CRYPT */
 static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_shiftwidth __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
     {"settabvar",	3, 3, f_settabvar},
     {"settabwinvar",	4, 4, f_settabwinvar},
     {"setwinvar",	3, 3, f_setwinvar},
+#ifdef FEAT_CRYPT
+    {"sha256",		1, 1, f_sha256},
+#endif
     {"shellescape",	1, 2, f_shellescape},
     {"shiftwidth",	0, 0, f_shiftwidth},
     {"simplify",	1, 1, f_simplify},
     }
 }
 
+#ifdef FEAT_CRYPT
+/*
+ * "sha256({string})" function
+ */
+    static void
+f_sha256(argvars, rettv)
+    typval_T	*argvars;
+    typval_T	*rettv;
+{
+    char_u	*p;
+
+    p = get_tv_string(&argvars[0]);
+    rettv->vval.v_string = vim_strsave(
+				    sha256_bytes(p, (int)STRLEN(p), NULL, 0));
+    rettv->v_type = VAR_STRING;
+}
+#endif /* FEAT_CRYPT */
+
 /*
  * "shellescape({string})" function
  */

File src/proto/sha256.pro

View file
 void sha256_start __ARGS((context_sha256_T *ctx));
 void sha256_update __ARGS((context_sha256_T *ctx, char_u *input, UINT32_T length));
 void sha256_finish __ARGS((context_sha256_T *ctx, char_u digest[32]));
+char_u *sha256_bytes __ARGS((char_u *buf, int buf_len, char_u *salt, int salt_len));
 char_u *sha256_key __ARGS((char_u *buf, char_u *salt, int salt_len));
 int sha256_self_test __ARGS((void));
 void sha2_seed __ARGS((char_u *header, int header_len, char_u *salt, int salt_len));

File src/sha256.c

View file
 #endif /* FEAT_CRYPT || FEAT_PERSISTENT_UNDO */
 
 #if defined(FEAT_CRYPT) || defined(PROTO)
-static char_u *sha256_bytes __ARGS((char_u *buf, int buf_len, char_u *salt, int salt_len));
 static unsigned int get_some_time __ARGS((void));
 
 /*
  * Returns hex digest of "buf[buf_len]" in a static array.
  * if "salt" is not NULL also do "salt[salt_len]".
  */
-    static char_u *
+    char_u *
 sha256_bytes(buf, buf_len, salt, salt_len)
     char_u *buf;
     int    buf_len;

File src/testdir/Make_amiga.mak

View file
 		test71.out test72.out test73.out test74.out test75.out \
 		test76.out test77.out test78.out test79.out test80.out \
 		test81.out test82.out test83.out test84.out test88.out \
-		test89.out
+		test89.out test90.out
 
 .SUFFIXES: .in .out
 
 test84.out: test84.in
 test88.out: test88.in
 test89.out: test89.in
+test90.out: test90.in

File src/testdir/Make_dos.mak

View file
 		test74.out test75.out test76.out test77.out test78.out \
 		test79.out test80.out test81.out test82.out test83.out \
 		test84.out test85.out test86.out test87.out test88.out \
-		test89.out
+		test89.out test90.out
 
 SCRIPTS32 =	test50.out test70.out
 

File src/testdir/Make_ming.mak

View file
 		test74.out test75.out test76.out test77.out test78.out \
 		test79.out test80.out test81.out test82.out test83.out \
 		test84.out test85.out test86.out test87.out test88.out \
-		test89.out
+		test89.out test90.out
 
 SCRIPTS32 =	test50.out test70.out
 

File src/testdir/Make_os2.mak

View file
 		test71.out test72.out test73.out test74.out test75.out \
 		test76.out test77.out test78.out test79.out test80.out \
 		test81.out test82.out test83.out test84.out test88.out \
-		test89.out
+		test89.out test90.out
 
 .SUFFIXES: .in .out
 

File src/testdir/Make_vms.mms

View file
 # Authors:	Zoltan Arpadffy, <arpadffy@polarhome.com>
 #		Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
 #
-# Last change:  2012 Dec 05
+# Last change:  2013 Feb 13
 #
 # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
 # Edit the lines in the Configuration section below to select.
 	 test66.out test67.out test68.out test69.out \
 	 test71.out test72.out test74.out test75.out test76.out \
 	 test77.out test78.out test79.out test80.out test81.out \
-	 test82.out test83.out test84.out test88.out test89.out
+	 test82.out test83.out test84.out test88.out test89.out \
+	 test90.out
 
 # Known problems:
 # Test 30: a problem around mac format - unknown reason

File src/testdir/Makefile

View file
 		test74.out test75.out test76.out test77.out test78.out \
 		test79.out test80.out test81.out test82.out test83.out \
 		test84.out test85.out test86.out test87.out test88.out \
-		test89.out
+		test89.out test90.out
 
 SCRIPTS_GUI = test16.out
 

File src/version.c

View file
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    816,
+/**/
     815,
 /**/
     814,