MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sha1hex

Function sha1hex

app/redis-6.2.6/src/scripting.c:93–108  ·  view source on GitHub ↗

Perform the SHA1 of the input string. We use this both for hashing script * bodies in order to obtain the Lua function name, and in the implementation * of redis.sha1(). * * 'digest' should point to a 41 bytes buffer: 40 for SHA1 converted into an * hexadecimal number, plus 1 byte for null term. */

Source from the content-addressed store, hash-verified

91 * 'digest' should point to a 41 bytes buffer: 40 for SHA1 converted into an
92 * hexadecimal number, plus 1 byte for null term. */
93void sha1hex(char *digest, char *script, size_t len) {
94 SHA1_CTX ctx;
95 unsigned char hash[20];
96 char *cset = "0123456789abcdef";
97 int j;
98
99 SHA1Init(&ctx);
100 SHA1Update(&ctx,(unsigned char*)script,len);
101 SHA1Final(hash,&ctx);
102
103 for (j = 0; j < 20; j++) {
104 digest[j*2] = cset[((hash[j]&0xF0)>>4)];
105 digest[j*2+1] = cset[(hash[j]&0xF)];
106 }
107 digest[40] = '\0';
108}
109
110/* ---------------------------------------------------------------------------
111 * Redis reply to Lua type conversion functions.

Callers 3

luaRedisSha1hexCommandFunction · 0.85
luaCreateFunctionFunction · 0.85
evalGenericCommandFunction · 0.85

Calls 3

SHA1InitFunction · 0.70
SHA1UpdateFunction · 0.70
SHA1FinalFunction · 0.70

Tested by

no test coverage detected