image: add functions to add and remove signatures

Rather than setting ->sigbuf directly, add two functions to handle image
signature addition and removal:

 image_add_signature(image, sig, sigsize);
 image_remove_signature(image);

And warn when a signature is to be overwritten.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
Jeremy Kerr 2012-08-03 10:03:14 +08:00
parent 36e79114d2
commit d27647ba69
7 changed files with 56 additions and 12 deletions

View file

@ -112,8 +112,8 @@ int main(int argc, char **argv)
{
const char *keyfilename, *certfilename;
struct sign_context *ctx;
uint8_t *buf;
int rc, c;
uint8_t *buf, *tmp;
int rc, c, sigsize;
ctx = talloc_zero(NULL, struct sign_context);
@ -220,12 +220,13 @@ int main(int argc, char **argv)
if (rc)
return EXIT_FAILURE;
ctx->image->sigsize = i2d_PKCS7(p7, NULL);
ctx->image->sigbuf = buf = talloc_array(ctx->image,
uint8_t, ctx->image->sigsize);
i2d_PKCS7(p7, &buf);
sigsize = i2d_PKCS7(p7, NULL);
tmp = buf = talloc_array(ctx->image, uint8_t, sigsize);
i2d_PKCS7(p7, &tmp);
ERR_print_errors_fp(stdout);
image_add_signature(ctx->image, buf, sigsize);
if (ctx->detached)
image_write_detached(ctx->image, ctx->outfilename);
else