signing message problem

Werner Koch wk at gnupg.org
Wed Aug 9 10:19:27 CEST 2006


On Tue,  8 Aug 2006 22:38, Hajdu Péter said:

> 	gpgme_key_ref( key );

Why are you doing this?  KEY will only be initialized with the next call.

> 	while ( !(error = gpgme_op_keylist_next (context, &key)) ) {

while ( !error && !(error = gpgme_op_keylist_next (context, &key)) )

Is better to catch an error in gpgme_op_keylist_next.  BTW, better
don't use the name "error" because it is commonly used as a fucntion
name (e.g. in glibc).

> 	memset(buf,0,sizeof(buf));
> 	printf("%d\n",gpgme_data_read( signature, buf, sizeof(buf) ));
> 	printf("%s",buf);


        ret = gpgme_data_seek (signature, 0, SEEK_SET);
 	printf("%d\n", (ret=gpgme_data_read( signature, buf, sizeof(buf)) ));
 	printf("%.*s",(int)ret, buf);

You should also use gpgme_set_armor if you want to use printf.  Please
also read the chapter about Largefile support in the gpgme manual.

Better code to print a result goes like this:

  ret = gpgme_data_seek (dh, 0, SEEK_SET);
  if (ret)
    fail_if_err (gpgme_error_from_errno (errno));
  while ((ret = gpgme_data_read (dh, buf, sizeof buf)) > 0)
    fwrite (buf, ret, 1, stdout);
  if (ret < 0)
    fail_if_err (gpgme_error_from_errno (errno));



Salam-Shalom,

   Werner




More information about the Gnupg-devel mailing list