Browse Source

Allow sign and encrypt.

Support simultaneous signing and encryption.
develop
Damien Goutte-Gattat 2 years ago
parent
commit
912dcf1fd7
  1. 14
      src/fmail.c

14
src/fmail.c

@ -443,7 +443,8 @@ encrypt_stream(gpgme_ctx_t ctx,
FILE *in,
FILE *out,
const char **recipients,
size_t nr)
size_t nr,
int sign)
{
gpgme_data_t gin, gout;
gpgme_key_t *keys, *key;
@ -455,7 +456,10 @@ encrypt_stream(gpgme_ctx_t ctx,
gpgme_data_new_from_stream(&gin, in);
gpgme_data_new(&gout);
gerr = gpgme_op_encrypt(ctx, keys, 0, gin, gout);
if ( sign )
gerr = gpgme_op_encrypt_sign(ctx, keys, 0, gin, gout);
else
gerr = gpgme_op_encrypt(ctx, keys, 0, gin, gout);
if ( gerr != GPG_ERR_NO_ERROR )
errx(EXIT_FAILURE, "encrypting failed: %s", gpgme_strerror(gerr));
@ -735,8 +739,6 @@ main(int argc, char *argv[])
}
}
if ( do_sign && ctx.rcp_count )
errx(EXIT_FAILURE, "encrypt and sign is not currently supported");
if ( do_sign || ctx.rcp_count )
ctx.crypto_ctx = initialize_gpgme();
@ -761,10 +763,10 @@ main(int argc, char *argv[])
process_text_body(&ctx, tmp);
fseek(tmp, 0, SEEK_SET);
if ( do_sign )
if ( ctx.rcp_count == 0 )
sign_stream(ctx.crypto_ctx, tmp, stdout);
else
encrypt_stream(ctx.crypto_ctx, tmp, stdout, ctx.recipients, ctx.rcp_count);
encrypt_stream(ctx.crypto_ctx, tmp, stdout, ctx.recipients, ctx.rcp_count, do_sign);
fclose(tmp);
gpgme_release(ctx.crypto_ctx);

Loading…
Cancel
Save