Commit eacd95c4 authored by Geoff Simmons's avatar Geoff Simmons

Redeuce code repetition for exit on failure from .encrypt().

parent fe3cd1b4
......@@ -466,8 +466,7 @@ vmod_symmetric_encrypt(VRT_CTX, struct vmod_gcrypt_symmetric *symmetric,
if (plaintext == NULL) {
VERRNOMEM(ctx, "Allocating padded plaintext in "
"%s.encrypt()", symmetric->vcl_name);
WS_Reset(ctx->ws, snap);
return NULL;
goto fail;
}
}
else {
......@@ -477,21 +476,17 @@ vmod_symmetric_encrypt(VRT_CTX, struct vmod_gcrypt_symmetric *symmetric,
if ((ciphertext->priv = WS_Alloc(ctx->ws, len)) == NULL) {
VERRNOMEM(ctx, "Allocating ciphertext result in %s.encrypt",
symmetric->vcl_name);
WS_Reset(ctx->ws, snap);
return NULL;
goto fail;
}
hd = get_symmetric_hd(ctx, symmetric, "encrypt");
if (hd == NULL) {
WS_Reset(ctx->ws, snap);
return NULL;
}
if (hd == NULL)
goto fail;
if (need_iv[symmetric->mode]) {
if (iv == NULL) {
VERR(ctx, "Required initialization vector is NULL in "
"%s.encrypt()", symmetric->vcl_name);
WS_Reset(ctx->ws, snap);
return NULL;
goto fail;
}
assert(iv->len >= 0);
/* A NULL iv of length 0 is permitted. */
......@@ -502,16 +497,14 @@ vmod_symmetric_encrypt(VRT_CTX, struct vmod_gcrypt_symmetric *symmetric,
VERR(ctx, "Cannot set initialization vector in "
"%s.encrypt(): %s/%s", symmetric->vcl_name,
gcry_strsource(err), gcry_strerror(err));
WS_Reset(ctx->ws, snap);
return NULL;
goto fail;
}
}
if (need_ctr[symmetric->mode]) {
if (ctr == NULL || ctr->priv == NULL) {
VERR(ctx, "Required counter vector is NULL in "
"%s.encrypt()", symmetric->vcl_name);
WS_Reset(ctx->ws, snap);
return NULL;
goto fail;
}
assert(ctr->len >= 0);
if ((err = gcry_cipher_setctr(*hd, ctr->priv, ctr->len))
......@@ -519,8 +512,7 @@ vmod_symmetric_encrypt(VRT_CTX, struct vmod_gcrypt_symmetric *symmetric,
VERR(ctx, "Cannot set counter vector in %s.encrypt(): "
"%s/%s", symmetric->vcl_name, gcry_strsource(err),
gcry_strerror(err));
WS_Reset(ctx->ws, snap);
return NULL;
goto fail;
}
}
if ((err = gcry_cipher_encrypt(*hd, ciphertext->priv, len, plaintext,
......@@ -528,12 +520,15 @@ vmod_symmetric_encrypt(VRT_CTX, struct vmod_gcrypt_symmetric *symmetric,
!= GPG_ERR_NO_ERROR) {
VERR(ctx, "in %s.encrypt(): %s/%s", symmetric->vcl_name,
gcry_strsource(err), gcry_strerror(err));
WS_Reset(ctx->ws, snap);
return NULL;
goto fail;
}
ciphertext->len = len;
ciphertext->free = NULL;
return ciphertext;
fail:
WS_Reset(ctx->ws, snap);
return NULL;
}
VCL_BLOB
......
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