Now send the signature back to the calling function (instead of just printing it to stdout)

This commit is contained in:
Karl-Heinz Zimmer 2001-11-22 09:36:53 +00:00
parent 679d5c2b49
commit 66f4b09b45

View File

@ -671,11 +671,13 @@ bool signMessage( const char* cleartext,
const char* certificate ) const char* certificate )
{ {
GpgmeCtx ctx; GpgmeCtx ctx;
GpgmeData data, sig; GpgmeData data, sig;
size_t rDLen, rSLen;
char buf[1024]; char* rData = 0;
size_t nread; char* rSig = 0;
if( !ciphertext )
return false;
gpgme_new (&ctx); gpgme_new (&ctx);
gpgme_set_armor (ctx, 1); gpgme_set_armor (ctx, 1);
@ -686,28 +688,26 @@ bool signMessage( const char* cleartext,
gpgme_data_new ( &sig ); gpgme_data_new ( &sig );
gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH ); gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH );
fputs ( "Content-Type: multipart/signed;\r\n" rData = gpgme_data_release_and_get_mem( data, &rDLen );
" protocol=\"application/pgp-signature\";\r\n" rSig = gpgme_data_release_and_get_mem( sig, &rSLen );
" boundary=\"42=.42=.42=.42\"\r\n"
"\r\n--42=.42=.42=.42\r\n",
stdout );
gpgme_data_rewind (data); *ciphertext = malloc( rDLen + rSLen + 1000 );
while ( !gpgme_data_read (data, buf, sizeof buf, &nread ) ) { if( *ciphertext ) {
fwrite (buf, nread, 1, stdout ); strcpy( (char*)*ciphertext,
"Content-Type: multipart/signed;\r\n"
" protocol=\"application/pgp-signature\";\r\n"
" boundary=\"42=.42=.42=.42\"\r\n"
"\r\n--42=.42=.42=.42\r\n" );
strncat((char*)*ciphertext, rData, rDLen );
strcat( (char*)*ciphertext,
"\r\n--42=.42=.42=.42\r\n"
"Content-Type: application/pgp-signature\r\n\r\n" );
strncat((char*)*ciphertext, rSig, rSLen );
strcat( (char*)*ciphertext,
"\r\n--42=.42=.42=.42--\r\n" );
} }
fputs ( "\r\n--42=.42=.42=.42\r\n"
"Content-Type: application/pgp-signature\r\n\r\n", stdout);
gpgme_data_rewind (sig);
while ( !gpgme_data_read (sig, buf, sizeof buf, &nread ) ) {
fwrite (buf, nread, 1, stdout );
}
fputs ( "\r\n--42=.42=.42=.42--\r\n", stdout );
gpgme_release (ctx); gpgme_release (ctx);
gpgme_data_release(data);
gpgme_data_release(sig);
return true; return true;
} }