On 18 Mar 2013, at 11:13 PM, [email protected] 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
--

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to