You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by sf...@apache.org on 2013/03/18 22:13:32 UTC
svn commit: r1458003 - /httpd/httpd/trunk/server/util_expr_eval.c
Author: sf
Date: Mon Mar 18 21:13:31 2013
New Revision: 1458003
URL: http://svn.apache.org/r1458003
Log:
simplify code by using ap_bin2hex()
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=1458003&r1=1458002&r2=1458003&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr_eval.c (original)
+++ httpd/httpd/trunk/server/util_expr_eval.c Mon Mar 18 21:13:31 2013
@@ -1038,21 +1038,15 @@ static const char *sha1_func(ap_expr_eva
{
apr_sha1_ctx_t context;
apr_byte_t sha1[APR_SHA1_DIGESTSIZE];
- char *hash, *out;
- const char *hex = "0123456789abcdef";
- int idx;
+ char *out;
- hash = out = apr_palloc(ctx->p, APR_SHA1_DIGESTSIZE*2+1);
+ out = apr_palloc(ctx->p, APR_SHA1_DIGESTSIZE*2+1);
apr_sha1_init(&context);
apr_sha1_update(&context, arg, strlen(arg));
apr_sha1_final(sha1, &context);
- for (idx = 0; idx < APR_SHA1_DIGESTSIZE; idx++) {
- *hash++ = hex[sha1[idx] >> 4];
- *hash++ = hex[sha1[idx] & 0xF];
- }
- *hash++ = '\0';
+ ap_bin2hex(sha1, APR_SHA1_DIGESTSIZE, out);
return out;
}
Re: svn commit: r1458003 - /httpd/httpd/trunk/server/util_expr_eval.c
Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Monday 18 March 2013, Graham Leggett wrote:
> This code came from mod_auth_digest, which could probably also be
> simplified:
Done, thanks.
Re: svn commit: r1458003 - /httpd/httpd/trunk/server/util_expr_eval.c
Posted by Graham Leggett <mi...@sharp.fm>.
On 18 Mar 2013, at 11:13 PM, sf@apache.org wrote:
> Author: sf
> Date: Mon Mar 18 21:13:31 2013
> New Revision: 1458003
>
> URL: http://svn.apache.org/r1458003
> Log:
> simplify code by using ap_bin2hex()
> - for (idx = 0; idx < APR_SHA1_DIGESTSIZE; idx++) {
> - *hash++ = hex[sha1[idx] >> 4];
> - *hash++ = hex[sha1[idx] & 0xF];
> - }
> - *hash++ = '\0';
> + ap_bin2hex(sha1, APR_SHA1_DIGESTSIZE, out);
This code came from mod_auth_digest, which could probably also be simplified:
static void gen_nonce_hash(char *hash, const char *timestr, const char *opaque,
const server_rec *server,
const digest_config_rec *conf)
{
const char *hex = "0123456789abcdef";
unsigned char sha1[APR_SHA1_DIGESTSIZE];
apr_sha1_ctx_t ctx;
int idx;
memcpy(&ctx, &conf->nonce_ctx, sizeof(ctx));
/*
apr_sha1_update_binary(&ctx, (const unsigned char *) server->server_hostname,
strlen(server->server_hostname));
apr_sha1_update_binary(&ctx, (const unsigned char *) &server->port,
sizeof(server->port));
*/
apr_sha1_update_binary(&ctx, (const unsigned char *) timestr, strlen(timestr));
if (opaque) {
apr_sha1_update_binary(&ctx, (const unsigned char *) opaque,
strlen(opaque));
}
apr_sha1_final(sha1, &ctx);
for (idx=0; idx<APR_SHA1_DIGESTSIZE; idx++) {
*hash++ = hex[sha1[idx] >> 4];
*hash++ = hex[sha1[idx] & 0xF];
}
*hash++ = '\0';
}
Regards,
Graham
--