gpgme 0.2.3 usage issues (?) resulting in gpgme pending after wait

Charles Duffy cduffy@mvista.com
Fri Nov 30 04:42:02 2001


--=-8fWed0BRVOGcuPe0Vsz5
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

As per the subject. Hopefully I'm making some incorrect usage
assumptions, and this whole thing can be ironed out quickly.

I'm working on Java bindings to gpgme using CNI. It's almost finished
enough for my application (which needs only signatures); I may or may
not continue development after the app works, depending on interest and
my time constraints.=20

Anyhow, my test code first writes to indata and then calls
gpgme_wait(context, false) just prior to gpgme_op_sign(context, indata,
outdata, GPGME_SIG_MODE_NORMAL). I *presume* that this would cause
anything pending (reading the input data?) to be finished. However, even
at the end of the wait call, context->pending is 1 and so the
gpgme_op_sign fails with GPGME_Busy. Checking the process table, I also
notice that the gpg instance gpgme refers to has zombied as of the wait
call.

The (really rough) test which is failing is included below; the API
pretty much is what it looks like. I'd be much obliged to anyone who'd
be so kind as to point out any glaring error, or point me in the
directions of any docs which might clarify what I'm doing wrong.

Thanks!



import java.util.Vector;
import java.util.Iterator;

class MyCallback extends gnu.gpgme.PassphraseCallback {
    String retval;
    public MyCallback(String retval) {
	this.retval =3D retval;
    }
    public String getPassphrase(String desc) {
	return retval;
    }
}

class test {
    public static void main(String[] args) {
	try {
	    System.out.println(gnu.gpgme.Gpgme.checkVersion(null));
	    gnu.gpgme.Gpgme.checkEngine();

	    MyCallback mc =3D new MyCallback("Alas, I am but a test!");

	    gnu.gpgme.Gpgme foo =3D new gnu.gpgme.Gpgme();
	    gnu.gpgme.GpgmeData testInput  =3D new gnu.gpgme.GpgmeData();
	    gnu.gpgme.GpgmeData testOutput =3D new gnu.gpgme.GpgmeData();

	    foo.setTextmode(true);
	    foo.setArmor(true);

	    int keyCount =3D 0;
	    Vector keys =3D foo.getKeys("test", true);
	    for(Iterator it =3D keys.iterator(); it.hasNext();) {
		gnu.gpgme.GpgmeKey key =3D (gnu.gpgme.GpgmeKey)it.next();
		if(key !=3D null) {
		    if(keyCount =3D=3D 0) foo.addSigner(key); // add the first matching p=
rivkey; only list the others
		    System.out.println(key.getAsXML());
		    keyCount++;
		}
	    }

	    System.out.println(keyCount + " keys printed.");

	    System.out.println("Setting passphrase callback");
	    foo.setPassphraseCallback(mc);

	    System.out.println("Reading string into buffer");
	    testInput.write((new String("Foo bar baz")).getBytes());

	    System.out.println("Signing data");
	    foo.wait(false);
	    foo.signData(testInput, testOutput, gnu.gpgme.GpgmeSigMode.GPGME_SIG_M=
ODE_NORMAL);

	    System.out.println("Reading results");
	    byte bar[] =3D testOutput.read(1024);
	    System.out.println(bar);
	} catch(gnu.gpgme.GpgmeError e) {
	    System.out.println("GPGME Error: " + e.getErrorStr());
	}
    }
}

--=-8fWed0BRVOGcuPe0Vsz5
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQA8Bv/DEa21SH+r3Z8RAjtEAJ9+qO8sIiamf0FHYdW7vplNVW9kbwCeOd3u
Y4RxZ23exgY05X3PvB9o/cg=
=jFEd
-----END PGP SIGNATURE-----

--=-8fWed0BRVOGcuPe0Vsz5--