25b1426eafe70217543788f93cb90aee918028b9
[m6w6/ext-http] / php_http_etag.h
1 #ifndef PHP_HTTP_ETAG_H
2 #define PHP_HTTP_ETAG_H
3
4 PHP_HTTP_API void *php_http_etag_init(TSRMLS_D);
5 PHP_HTTP_API size_t php_http_etag_update(void *ctx, const char *data_ptr, size_t data_len TSRMLS_DC);
6 PHP_HTTP_API char *php_http_etag_finish(void *ctx TSRMLS_DC);
7
8 static inline char *php_http_etag_digest(const unsigned char *digest, int len)
9 {
10 static const char hexdigits[17] = "0123456789abcdef";
11 int i;
12 char *hex = emalloc(len * 2 + 1);
13 char *ptr = hex;
14
15 for (i = 0; i < len; ++i) {
16 *ptr++ = hexdigits[digest[i] >> 4];
17 *ptr++ = hexdigits[digest[i] & 0xF];
18 }
19 *ptr = '\0';
20
21 return hex;
22 }
23
24 #endif /* PHP_HTTP_ETAG_H */