Example usage for org.bouncycastle.openpgp PGPPublicKeyRingCollection iterator

List of usage examples for org.bouncycastle.openpgp PGPPublicKeyRingCollection iterator

Introduction

In this page you can find the example usage for org.bouncycastle.openpgp PGPPublicKeyRingCollection iterator.

Prototype

public Iterator<PGPPublicKeyRing> iterator() 

Source Link

Document

Support method for Iterable where available.

Usage

From source file:org.jivesoftware.smackx.ox.OpenPgpContact.java

License:Apache License

/**
 * Return a {@link PGPPublicKeyRingCollection}, which contains all keys from {@code keys}, which are marked with the
 * {@link OpenPgpTrustStore.Trust} state of {@code trust}.
 *
 * @param keys {@link PGPPublicKeyRingCollection}
 * @param trust {@link OpenPgpTrustStore.Trust}
 *
 * @return all keys from {@code keys} with trust state {@code trust}.
 *
 * @throws IOException IO error// w w  w .ja va2 s  .c  o  m
 */
protected PGPPublicKeyRingCollection getPublicKeysOfTrustState(PGPPublicKeyRingCollection keys,
        OpenPgpTrustStore.Trust trust) throws IOException {

    if (keys == null) {
        return null;
    }

    Set<PGPPublicKeyRing> toRemove = new HashSet<>();
    Iterator<PGPPublicKeyRing> iterator = keys.iterator();
    while (iterator.hasNext()) {
        PGPPublicKeyRing ring = iterator.next();
        OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(ring);
        if (store.getTrust(getJid(), fingerprint) != trust) {
            toRemove.add(ring);
        }
    }

    for (PGPPublicKeyRing ring : toRemove) {
        keys = PGPPublicKeyRingCollection.removePublicKeyRing(keys, ring);
    }

    if (!keys.iterator().hasNext()) {
        return null;
    }

    return keys;
}

From source file:org.jivesoftware.smackx.ox.store.abstr.AbstractOpenPgpKeyStore.java

License:Apache License

@Override
public void deletePublicKeyRing(BareJid owner, OpenPgpV4Fingerprint fingerprint)
        throws IOException, PGPException {
    PGPPublicKeyRingCollection publicKeyRings = getPublicKeysOf(owner);
    if (publicKeyRings.contains(fingerprint.getKeyId())) {
        publicKeyRings = PGPPublicKeyRingCollection.removePublicKeyRing(publicKeyRings,
                publicKeyRings.getPublicKeyRing(fingerprint.getKeyId()));
        if (!publicKeyRings.iterator().hasNext()) {
            publicKeyRings = null;//from w  ww  . ja v a 2 s.com
        }
        this.publicKeyRingCollections.put(owner, publicKeyRings);
        writePublicKeysOf(owner, publicKeyRings);
    }
}