Refactor vmod_digest_update()

Remove duplicate call to update() using a local variable for the hash ctx.

This also adds a check for finalization from vcl_init/vcl_fini
parent 9802ffbb
......@@ -425,6 +425,7 @@ VCL_BOOL
vmod_digest_update(VRT_CTX, struct vmod_blobdigest_digest *h, VCL_BLOB b)
{
struct digest_task *task;
hash_ctx *hctx;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(h, VMOD_BLOBDIGEST_DIGEST_MAGIC);
......@@ -443,18 +444,14 @@ vmod_digest_update(VRT_CTX, struct vmod_blobdigest_digest *h, VCL_BLOB b)
return (0);
}
if (INIT_FINI(ctx)) {
if (b->len > 0 && b->blob != NULL)
update(h->hash, &h->ctx, b->blob, b->len);
return (1);
}
hctx = INIT_FINI(ctx) ? &h->ctx : &task->ctx;
if (task->result != NULL) {
VERR(ctx, "already finalized in %s.update()", h->vcl_name);
return (0);
}
if (b->len > 0 && b->blob != NULL)
update(h->hash, &task->ctx, b->blob, b->len);
update(h->hash, hctx, b->blob, b->len);
return (1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment