Search in sources :

Example 6 with PGPPublicKeyRingCollection

use of org.bouncycastle.openpgp.PGPPublicKeyRingCollection in project gerrit by GerritCodeReview.

the class PublicKeyStore method saveToNotes.

private void saveToNotes(ObjectInserter ins, PGPPublicKeyRing keyRing) throws PGPException, IOException {
    long keyId = keyRing.getPublicKey().getKeyID();
    PGPPublicKeyRingCollection existing = get(keyId);
    List<PGPPublicKeyRing> toWrite = new ArrayList<>(existing.size() + 1);
    boolean replaced = false;
    for (PGPPublicKeyRing kr : existing) {
        if (sameKey(keyRing, kr)) {
            toWrite.add(keyRing);
            replaced = true;
        } else {
            toWrite.add(kr);
        }
    }
    if (!replaced) {
        toWrite.add(keyRing);
    }
    notes.set(keyObjectId(keyId), ins.insert(OBJ_BLOB, keysToArmored(toWrite)));
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) PGPPublicKeyRingCollection(org.bouncycastle.openpgp.PGPPublicKeyRingCollection) ArrayList(java.util.ArrayList)

Aggregations

PGPPublicKeyRingCollection (org.bouncycastle.openpgp.PGPPublicKeyRingCollection)6 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)4 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)3 ArrayList (java.util.ArrayList)2 PublicKeyStore.keyIdToString (com.google.gerrit.gpg.PublicKeyStore.keyIdToString)1 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)1 TestKey (com.google.gerrit.gpg.testutil.TestKey)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1 TreeSet (java.util.TreeSet)1 PGPException (org.bouncycastle.openpgp.PGPException)1 BcKeyFingerprintCalculator (org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator)1