You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by mi...@apache.org on 2013/03/18 01:27:38 UTC

svn commit: r1457610 - /httpd/httpd/trunk/server/util_expr_eval.c

Author: minfrin
Date: Mon Mar 18 00:27:38 2013
New Revision: 1457610

URL: http://svn.apache.org/r1457610
Log:
Expression parser: use hex encoding for the sha1 hash.

Modified:
    httpd/httpd/trunk/server/util_expr_eval.c

Modified: httpd/httpd/trunk/server/util_expr_eval.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_expr_eval.c?rev=1457610&r1=1457609&r2=1457610&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr_eval.c (original)
+++ httpd/httpd/trunk/server/util_expr_eval.c Mon Mar 18 00:27:38 2013
@@ -1036,18 +1036,23 @@ static const char *unbase64_func(ap_expr
 static const char *sha1_func(ap_expr_eval_ctx_t *ctx, const void *data,
                                const char *arg)
 {
-    int l;
     apr_sha1_ctx_t context;
-    apr_byte_t digest[APR_SHA1_DIGESTSIZE];
-    char *out = apr_palloc(ctx->p, 28);
+    apr_byte_t sha1[APR_SHA1_DIGESTSIZE];
+    char *hash, *out;
+    const char *hex = "0123456789abcdef";
+    int idx;
+
+    hash = out = apr_palloc(ctx->p, APR_SHA1_DIGESTSIZE*2+1);
 
     apr_sha1_init(&context);
     apr_sha1_update(&context, arg, strlen(arg));
-    apr_sha1_final(digest, &context);
+    apr_sha1_final(sha1, &context);
 
-    /* SHA1 hash is always 20 chars */
-    l = apr_base64_encode_binary(out, digest, sizeof(digest));
-    out[l] = '\0';
+    for (idx = 0; idx < APR_SHA1_DIGESTSIZE; idx++) {
+        *hash++ = hex[sha1[idx] >> 4];
+        *hash++ = hex[sha1[idx] & 0xF];
+    }
+    *hash++ = '\0';
 
     return out;
 }