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. */
| 94 | * 'digest' should point to a 41 bytes buffer: 40 for SHA1 converted into an |
| 95 | * hexadecimal number, plus 1 byte for null term. */ |
| 96 | void 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. |
no test coverage detected