Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: GnuPG: devel

gpgme_data_new_from_mem works, gpgme_data_write doesn't

 

 

GnuPG devel RSS feed   Index | Next | Previous | View Threaded


nico-gnupg-dev-0 at schottelius

Jul 6, 2008, 3:10 PM

Post #1 of 2 (174 views)
Permalink
gpgme_data_new_from_mem works, gpgme_data_write doesn't

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.

I created a testfile, containing both cases to show it in
commit 86f3d41a53834231eea54da750bd4564c9c13ae0 of ceofhack.

Anyone a hint, what I am doing wrong in the latter case?

Sincerly

Nico

PS: http://unix.schottelius.org/cgi-bin/gitweb.cgi?p=EOF/ceofhack;a=summary

--
Think about Free and Open Source Software (FOSS).
http://nico.schottelius.org/documentations/foss/the-term-foss/

PGP: BFE4 C736 ABE5 406F 8F42 F7CF B8BE F92A 9885 188C
Attachments: signature.asc (0.18 KB)


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

GnuPG devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.