gpgme encrypting a buffer at a time (streaming)

Tyler Retzlaff list at omicron-persei-8.net
Tue Apr 26 02:22:16 CEST 2005


I previously saw a post that indicated encrypting a buffer at a time was
possible in the case the producer of the data being encrypted was streaming.

The algorithm went a little something like this:

while ((n_read = getdata( buffer )) > 0)
{
 write_data_to_gpgme (buffer);
 enc = get_encrypted_data_from_gpgme ();
 do_something_with_encrypted_data (enc);
}

My producer is a source of memory (a stream buffer infact).  So I tried
to do the following with no success.

gpgme_data_new(&plain);
gpgme_data_new(&cipher);

gpgme_encrypt_op_start(ctx, keys, plain, cipher);
while ((wbytes = getdata(srcbuffer)) > 0) {
   gpgme_data_write(plain, srcbuffer, wbytes);
   while (gpgme_data_read(cipher, dstbuffer, wbytes) != GPGME_EOF) {
       gpgme_data_read(cipher, dstbuffer, dstbuf_sz);
       /* do something with dst buffer */
   }
}

I realize this isn't how it should be done, does anyone have an example
of how to do this without using the fd or file stream gpgme interface?
I'm dealing with strictly memory based producers and consumers and at no
time want anything in a file.

Example code would be greatly appreciated!

Thanks




More information about the Gnupg-users mailing list