* lua_apr_sha1; r:sha1(string) - Calculates the SHA1 digest of a string */
| 967 | * lua_apr_sha1; r:sha1(string) - Calculates the SHA1 digest of a string |
| 968 | */ |
| 969 | static int lua_apr_sha1(lua_State *L) |
| 970 | { |
| 971 | unsigned char digest[APR_SHA1_DIGESTSIZE]; |
| 972 | apr_sha1_ctx_t sha1; |
| 973 | const char *buffer; |
| 974 | char *result; |
| 975 | size_t len; |
| 976 | request_rec *r; |
| 977 | |
| 978 | r = ap_lua_check_request_rec(L, 1); |
| 979 | luaL_checktype(L, 2, LUA_TSTRING); |
| 980 | result = apr_pcalloc(r->pool, sizeof(digest) * 2 + 1); |
| 981 | buffer = lua_tolstring(L, 2, &len); |
| 982 | apr_sha1_init(&sha1); |
| 983 | apr_sha1_update(&sha1, buffer, len); |
| 984 | apr_sha1_final(digest, &sha1); |
| 985 | |
| 986 | ap_bin2hex(digest, sizeof(digest), result); |
| 987 | lua_pushstring(L, result); |
| 988 | return 1; |
| 989 | } |
| 990 | |
| 991 | /* |
| 992 | * lua_apr_htpassword; r:htpassword(string [, algorithm [, cost]]) - Creates |
nothing calls this directly
no test coverage detected