gpgme & gpgme_data_write problem

Tyler Retzlaff list at omicron-persei-8.net
Sun Apr 24 17:36:01 CEST 2005


I'm using the following piece of code which is heavily derived from that 
found in the gpgme/test directory.  (With error checking removed for 
clarity, though in the real code all error checking is being done)

The problem is when I use gpgme_data_write() to enter the text into the 
plain text data buffer before encryption it doesn't end up being 
encrypted as a part of cipher text.  The resulting encrypted message is 
empty.

This doesn't happen if I initialize the plain data buffer with 
gpg_data_new_from_mem().  Am I using gpgme_data_new() and 
gpgme_data_write() incorrectly? Or is libgpgme at fault?  btw. using 
gpgme 1.0.1/gnupg 1.2.6 being used.

Advice is appreciated, thanks!

int
main(int argc, char **argv)
         size_t wbytes;
         gpgme_error_t e;
         gpgme_ctx_t ctx;
         gpgme_data_t plain;
         gpgme_data_t cipher;
         gpgme_key_t key[2] = { NULL, NULL };
         gpgme_encrypt_result_t r;
         gpgme_data_encoding_t enc;

         setlocale (LC_ALL, "");
         gpgme_check_version (NULL);
         gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
         gpgme_set_locale(NULL, LC_MESSAGES, setlocale (LC_MESSAGES,
         NULL));

      gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
         gpgme_new(&ctx);
         gpgme_set_armor(ctx, 1);

     gpgme_data_new(&plain);
     gpgme_data_new(&cipher);
     gpgme_get_key(ctx, "93EE05A3D02C75B7B451AF1E6449D89A2D2C2204",
         &key[0], 0);

         wbytes = sizeof("This is the first line.\n");
         gpgme_data_write(plain, "This is the first line.\n", wbytes);
         fprintf(stderr, "wrote %d bytes\n", wbytes);
     gpgme_op_encrypt(ctx, key, 0, plain, cipher);
         r = gpgme_op_encrypt_result(ctx);

         print_data(cipher);
         gpgme_key_unref(key[0]);
         gpgme_data_release(plain);
         gpgme_data_release(cipher);
         gpgme_release(ctx);

         return EXIT_SUCCESS;



More information about the Gnupg-users mailing list