From 1195ae3fc1ff009e1eab6959bfe89282a2a69169 Mon Sep 17 00:00:00 2001 From: Karl-Heinz Zimmer Date: Thu, 22 Nov 2001 09:36:53 +0000 Subject: [PATCH] Now send the signature back to the calling function (instead of just printing it to stdout) --- trunk/gpgmeplug/gpgmeplug.c | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/trunk/gpgmeplug/gpgmeplug.c b/trunk/gpgmeplug/gpgmeplug.c index 248eebe..88582b2 100644 --- a/trunk/gpgmeplug/gpgmeplug.c +++ b/trunk/gpgmeplug/gpgmeplug.c @@ -671,11 +671,13 @@ bool signMessage( const char* cleartext, const char* certificate ) { GpgmeCtx ctx; - GpgmeData data, sig; - - char buf[1024]; - size_t nread; + GpgmeData data, sig; + size_t rDLen, rSLen; + char* rData = 0; + char* rSig = 0; + if( !ciphertext ) + return false; gpgme_new (&ctx); gpgme_set_armor (ctx, 1); @@ -686,28 +688,26 @@ bool signMessage( const char* cleartext, gpgme_data_new ( &sig ); gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH ); - fputs ( "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", - stdout ); - - gpgme_data_rewind (data); - while ( !gpgme_data_read (data, buf, sizeof buf, &nread ) ) { - fwrite (buf, nread, 1, stdout ); - } - 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 ); + rData = gpgme_data_release_and_get_mem( data, &rDLen ); + rSig = gpgme_data_release_and_get_mem( sig, &rSLen ); + + *ciphertext = malloc( rDLen + rSLen + 1000 ); + if( *ciphertext ) { + 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", stdout ); gpgme_release (ctx); - gpgme_data_release(data); - gpgme_data_release(sig); return true; } -- 2.26.2