[PGPME] Help with deleting keys

Dennis Opacki dopacki at adotout.com
Tue Jan 14 10:14:13 CET 2003


I am looking for some assistance with deleting keys using
pgpme_op_delete. The code I am working on is part of a Perl XSUB which
will accept a text string and delete all matching keys. When I call the
function below, however, it returns the proper list of keys (claiming
that they have been deleted), but but pgpme_op_delete returns
GPGME_No_Error and fails to delete the keys. Earlier today, I tried
putting pgpme_op_delete within the pgpme_op_keylist_next loop below,
but was getting a return code of GPGME_Busy. I am assuming that this
was because the keychain was open for reading.

What is the proper way to search for and delete specific keys? I even
tried releasing and re-creating a new context between the end of
pgpme_op_keylist_next and pgpme_op_delete. No dice.

I am only trying to delete public keys and am using gpgme-0.3.14 built
from source.

TIA,

-Dennis Opacki
  dopacki at adotout.com


void delKey ( ascii )
         char *ascii

         INIT:
                 GpgmeCtx ctx;
                 GpgmeError err;
                 GpgmeKey key;

                 // init linked list
                 struct key_list {
                         GpgmeKey key;
                         struct key_list *next;
                 };
                 struct key_list *curr, *head, *tmp;
                 head = NULL;

         PPCODE:

                 // create a new context
                 if (  gpgme_new(&ctx) != GPGME_No_Error ) {
                         gpgme_release(ctx);
                         XSRETURN_UNDEF;
                 }

                 // search for key
                 if ( gpgme_op_keylist_start( ctx, ascii, 0) !=
GPGME_No_Error ) {
                         gpgme_release(ctx);
                         XSRETURN_UNDEF;
                 }


                 // walk through key list
                 while ( gpgme_op_keylist_next( ctx, &key ) != GPGME_EOF
) {

                         // add keys found to linked list
                         curr = (struct key_list *) malloc (sizeof
(struct key_list));
                         curr->key = key;
                         curr->next = head;
                         head = curr;
                 }

                 // purge keys
                 while (curr) {

                         // delete key and return fingerprint
		    PUSHs(sv_2mortal(newSVpv( gpgme_key_get_string_attr( curr->key,
GPGME_ATTR_FPR, 0, 0), 0 ) ) );
                         if ( gpgme_op_delete( ctx, curr->key, 0 ) !=
GPGME_No_Error ) {
				 // debug debug debug
                                 printf("error: %d\n",err);
                         }

                         gpgme_key_release(curr->key);
                         tmp  = curr;
                         curr = curr->next;
                         free (tmp);
                 }
               gpgme_release(ctx);





More information about the Gnupg-devel mailing list