Examples of PGPPublicKeyRingCollection


Examples of org.bouncycastle.openpgp.PGPPublicKeyRingCollection

        "AQE=");

    public void test1()
        throws Exception
    {
        PGPPublicKeyRingCollection    pubRings = new PGPPublicKeyRingCollection(pub1);

        int                                        count = 0;

        Iterator    rIt = pubRings.getKeyRings();
       
        while (rIt.hasNext())
        {
            PGPPublicKeyRing                    pgpPub = (PGPPublicKeyRing)rIt.next();

            count++;
           
            int    keyCount = 0;
           
            byte[]    bytes = pgpPub.getEncoded();
           
            pgpPub = new PGPPublicKeyRing(bytes);
           
            Iterator    it = pgpPub.getPublicKeys();
            while (it.hasNext())
            {
                keyCount++;

                PGPPublicKey    pubKey = (PGPPublicKey)it.next();
               
                Iterator   sIt = pubKey.getSignatures();
                while (sIt.hasNext())
                {
                    ((PGPSignature)sIt.next()).getSignatureType();
                }
            }
           
            if (keyCount != 2)
            {
                fail("wrong number of public keys");
            }
        }
       
        if (count != 1)
        {
            fail("wrong number of public keyrings");
        }
       
        //
        // exact match
        //
        rIt = pubRings.getKeyRings("test (Test key) <test@ubicall.com>");
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 1)
        {
            fail("wrong number of public keyrings on exact match");
        }
       
        //
        // partial match 1 expected
        //
        rIt = pubRings.getKeyRings("test", true);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 1)
        {
            fail("wrong number of public keyrings on partial match 1");
        }
       
        //
        // partial match 0 expected
        //
        rIt = pubRings.getKeyRings("XXX", true);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 0)
        {
            fail("wrong number of public keyrings on partial match 0");
        }

        //
        // case-insensitive partial match
        //
        rIt = pubRings.getKeyRings("TEST@ubicall.com", true, true);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.