MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sha1hex

Function sha1hex

src/scripting.cpp:96–111  ·  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

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

Callers 3

luaRedisSha1hexCommandFunction · 0.85
luaCreateFunctionFunction · 0.85
evalGenericCommandFunction · 0.85

Calls 3

SHA1InitFunction · 0.85
SHA1UpdateFunction · 0.85
SHA1FinalFunction · 0.85

Tested by

no test coverage detected