
marcus.brinkmann at ruhr-uni-bochum
Jul 30, 2008, 5:49 PM
Post #2 of 2
(110 views)
Permalink
|
|
Re: gpgme_data_new_from_mem works, gpgme_data_write doesn't
[In reply to]
|
|
At Mon, 7 Jul 2008 00:10:10 +0200, Nico Schottelius <nico-gnupg-dev-0[at]schottelius.org> wrote: > > [1 <multipart/signed (7bit)>] > [1.1 <text/plain; us-ascii (quoted-printable)>] > Hello! > > I am testing around with gpgme and it seems I am doing something > wrong with gpgme_data_write(): > > If I do > > gerr = gpgme_data_new(&g_test); > if(gerr != GPG_ERR_NO_ERROR) return 20; > i = strlen(b_encrypt); > > /* THIS WORKS */ > gerr = gpgme_data_new_from_mem(&g_encrypt_send, b_encrypt, i, 1); > if(gerr != GPG_ERR_NO_ERROR) return 24; > > /* decrypt: from gpgme_data_new_from_mem() */ > gerr = gpgme_op_decrypt(g_context, g_encrypt_send, g_plain_recv); > if(gerr != GPG_ERR_NO_ERROR) { > printf("gerr=%d\n",gerr); > return 19; > } > > > it works. If I do > > gerr = gpgme_data_new(&g_test); > if(gerr != GPG_ERR_NO_ERROR) return 20; > i = strlen(b_encrypt); > printf("strlen(%s) = %d\n",b_encrypt,i); > > /* THIS DOES NOT WORK */ > tmp = gpgme_data_write(g_test, b_encrypt, i); > printf("gpgmedatawrite: %d\n", tmp); > > /* decrypt: from gpgme_data_write() */ > gerr = gpgme_op_decrypt(g_context, g_test, g_plain_recv2); > if(gerr != GPG_ERR_NO_ERROR) { > printf("gerr=%d\n",gerr); > return 41; > } > > it does *NOT* work. As I wrote before: "gpgme data objects have a file pointer that must be rewound to read written data (gpgme_data_seek). To use the seek function make sure you compile with large file support. See the documentation." The gpgme_data_write() above works just fine, but after it the file pointer is at the end of the data, and the gpgme_op_decrypt sees an empty data buffer: g_test: some-data ^ | "file" pointer You need to rewind the file pointer to the beginning after gpgme_data_write. Please see the documentation, and take notice of the large file support necessary when using gpgme_data_seek. Thanks, Marcus _______________________________________________ Gnupg-devel mailing list Gnupg-devel[at]gnupg.org http://lists.gnupg.org/mailman/listinfo/gnupg-devel
|