Package org.bouncycastle.openpgp

## Class PGPPublicKeyRingCollection

- java.lang.Object
- - org.bouncycastle.openpgp.PGPPublicKeyRingCollection

- All Implemented Interfaces:
    `java.lang.Iterable<PGPPublicKeyRing>`, `org.bouncycastle.util.Iterable<PGPPublicKeyRing>`
  Direct Known Subclasses:
    `BcPGPPublicKeyRingCollection`, `JcaPGPPublicKeyRingCollection`

      public class PGPPublicKeyRingCollection
      extends java.lang.Object
      implements org.bouncycastle.util.Iterable<PGPPublicKeyRing>

  Often a PGP key ring file is made up of a succession of master/sub-key key rings. If you want to read an entire public key file in one hit this is the class for you.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `PGPPublicKeyRingCollection​(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator)` |
    `PGPPublicKeyRingCollection​(java.io.InputStream in, KeyFingerPrintCalculator fingerPrintCalculator)` | Build a PGPPublicKeyRingCollection from the passed in input stream.
    `PGPPublicKeyRingCollection​(java.util.Collection<PGPPublicKeyRing> collection)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static PGPPublicKeyRingCollection` | `addPublicKeyRing​(PGPPublicKeyRingCollection ringCollection, PGPPublicKeyRing publicKeyRing)` | Return a new collection object containing the contents of the passed in collection and the passed in public key ring.
    `boolean` | `contains​(byte[] fingerprint)` | Return true if a key matching the passed in fingerprint is present, false otherwise.
    `boolean` | `contains​(long keyID)` | Return true if a key matching the passed in key ID is present, false otherwise.
    `void` | `encode​(java.io.OutputStream outStream)` |
    `byte[]` | `getEncoded()` |
    `java.util.Iterator<PGPPublicKeyRing>` | `getKeyRings()` | return the public key rings making up this collection.
    `java.util.Iterator<PGPPublicKeyRing>` | `getKeyRings​(java.lang.String userID)` | Return an iterator of the key rings associated with the passed in userID.
    `java.util.Iterator<PGPPublicKeyRing>` | `getKeyRings​(java.lang.String userID, boolean matchPartial)` | Return an iterator of the key rings associated with the passed in userID.
    `java.util.Iterator<PGPPublicKeyRing>` | `getKeyRings​(java.lang.String userID, boolean matchPartial, boolean ignoreCase)` | Return an iterator of the key rings associated with the passed in userID.
    `java.util.Iterator<PGPPublicKey>` | `getKeysWithSignaturesBy​(long keyID)` | Return any keys carrying a signature issued by the key represented by keyID.
    `PGPPublicKey` | `getPublicKey​(byte[] fingerprint)` | Return the PGP public key associated with the given key fingerprint.
    `PGPPublicKey` | `getPublicKey​(long keyID)` | Return the PGP public key associated with the given key id.
    `PGPPublicKeyRing` | `getPublicKeyRing​(byte[] fingerprint)` | Return the PGP public key associated with the given key fingerprint.
    `PGPPublicKeyRing` | `getPublicKeyRing​(long keyID)` | Return the public key ring which contains the key referred to by keyID.
    `java.util.Iterator<PGPPublicKeyRing>` | `iterator()` | Support method for Iterable where available.
    `static PGPPublicKeyRingCollection` | `removePublicKeyRing​(PGPPublicKeyRingCollection ringCollection, PGPPublicKeyRing publicKeyRing)` | Return a new collection object containing the contents of this collection with the passed in public key ring removed.
    `int` | `size()` | Return the number of rings in this collection.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Constructor Detail

    - #### PGPPublicKeyRingCollection

          public PGPPublicKeyRingCollection​(byte[] encoding,
                                            KeyFingerPrintCalculator fingerPrintCalculator)
                                     throws java.io.IOException,
                                            PGPException

      Throws:
        `java.io.IOException`
        `PGPException`

    - #### PGPPublicKeyRingCollection

          public PGPPublicKeyRingCollection​(java.io.InputStream in,
                                            KeyFingerPrintCalculator fingerPrintCalculator)
                                     throws java.io.IOException,
                                            PGPException

      Build a PGPPublicKeyRingCollection from the passed in input stream.
      Parameters:
        `in` - input stream containing data
      Throws:
        `java.io.IOException` - if a problem parsing the base stream occurs
        `PGPException` - if an object is encountered which isn't a PGPPublicKeyRing

    - #### PGPPublicKeyRingCollection

          public PGPPublicKeyRingCollection​(java.util.Collection<PGPPublicKeyRing> collection)
                                     throws java.io.IOException,
                                            PGPException

      Throws:
        `java.io.IOException`
        `PGPException`

  - ### Method Detail

    - #### size

          public int size()

      Return the number of rings in this collection.
      Returns:
        size of the collection

    - #### getKeyRings

          public java.util.Iterator<PGPPublicKeyRing> getKeyRings()

      return the public key rings making up this collection.

    - #### getKeyRings

          public java.util.Iterator<PGPPublicKeyRing> getKeyRings​(java.lang.String userID)
                                                           throws PGPException

      Return an iterator of the key rings associated with the passed in userID.
      Parameters:
        `userID` - the user ID to be matched.
      Returns:
        an iterator (possibly empty) of key rings which matched.
      Throws:
        `PGPException`

    - #### getKeyRings

          public java.util.Iterator<PGPPublicKeyRing> getKeyRings​(java.lang.String userID,
                                                                  boolean matchPartial)
                                                           throws PGPException

      Return an iterator of the key rings associated with the passed in userID.

      Parameters:
        `userID` - the user ID to be matched.
        `matchPartial` - if true userID need only be a substring of an actual ID string to match.
      Returns:
        an iterator (possibly empty) of key rings which matched.
      Throws:
        `PGPException`

    - #### getKeyRings

          public java.util.Iterator<PGPPublicKeyRing> getKeyRings​(java.lang.String userID,
                                                                  boolean matchPartial,
                                                                  boolean ignoreCase)
                                                           throws PGPException

      Return an iterator of the key rings associated with the passed in userID.

      Parameters:
        `userID` - the user ID to be matched.
        `matchPartial` - if true userID need only be a substring of an actual ID string to match.
        `ignoreCase` - if true case is ignored in user ID comparisons.
      Returns:
        an iterator (possibly empty) of key rings which matched.
      Throws:
        `PGPException`

    - #### getPublicKey

          public PGPPublicKey getPublicKey​(long keyID)
                                    throws PGPException

      Return the PGP public key associated with the given key id.
      Parameters:
        `keyID` -
      Returns:
        the PGP public key
      Throws:
        `PGPException`

    - #### getPublicKeyRing

          public PGPPublicKeyRing getPublicKeyRing​(long keyID)
                                            throws PGPException

      Return the public key ring which contains the key referred to by keyID.
      Parameters:
        `keyID` - key ID to match against
      Returns:
        the public key ring
      Throws:
        `PGPException`

    - #### getPublicKey

          public PGPPublicKey getPublicKey​(byte[] fingerprint)
                                    throws PGPException

      Return the PGP public key associated with the given key fingerprint.
      Parameters:
        `fingerprint` - the public key fingerprint to match against.
      Returns:
        the PGP public key matching fingerprint.
      Throws:
        `PGPException`

    - #### getPublicKeyRing

          public PGPPublicKeyRing getPublicKeyRing​(byte[] fingerprint)
                                            throws PGPException

      Return the PGP public key associated with the given key fingerprint.
      Parameters:
        `fingerprint` - the public key fingerprint to match against.
      Returns:
        the PGP public key ring containing the PGP public key matching fingerprint.
      Throws:
        `PGPException`

    - #### getKeysWithSignaturesBy

          public java.util.Iterator<PGPPublicKey> getKeysWithSignaturesBy​(long keyID)

      Return any keys carrying a signature issued by the key represented by keyID.
      Parameters:
        `keyID` - the key id to be matched against.
      Returns:
        an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.

    - #### contains

          public boolean contains​(long keyID)
                           throws PGPException

      Return true if a key matching the passed in key ID is present, false otherwise.
      Parameters:
        `keyID` - key ID to look for.
      Returns:
        true if keyID present, false otherwise.
      Throws:
        `PGPException`

    - #### contains

          public boolean contains​(byte[] fingerprint)
                           throws PGPException

      Return true if a key matching the passed in fingerprint is present, false otherwise.
      Parameters:
        `fingerprint` - hte key fingerprint to look for.
      Returns:
        true if keyID present, false otherwise.
      Throws:
        `PGPException`

    - #### getEncoded

          public byte[] getEncoded()
                            throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### encode

          public void encode​(java.io.OutputStream outStream)
                      throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### addPublicKeyRing

          public static PGPPublicKeyRingCollection addPublicKeyRing​(PGPPublicKeyRingCollection ringCollection,
                                                                    PGPPublicKeyRing publicKeyRing)

      Return a new collection object containing the contents of the passed in collection and the passed in public key ring.
      Parameters:
        `ringCollection` - the collection the ring to be added to.
        `publicKeyRing` - the key ring to be added.
      Returns:
        a new collection merging the current one with the passed in ring.
      Throws:
        `java.lang.IllegalArgumentException` - if the keyID for the passed in ring is already present.

    - #### removePublicKeyRing

          public static PGPPublicKeyRingCollection removePublicKeyRing​(PGPPublicKeyRingCollection ringCollection,
                                                                       PGPPublicKeyRing publicKeyRing)

      Return a new collection object containing the contents of this collection with the passed in public key ring removed.
      Parameters:
        `ringCollection` - the collection the ring to be removed from.
        `publicKeyRing` - the key ring to be removed.
      Returns:
        a new collection not containing the passed in ring.
      Throws:
        `java.lang.IllegalArgumentException` - if the keyID for the passed in ring not present.

    - #### iterator

          public java.util.Iterator<PGPPublicKeyRing> iterator()

      Support method for Iterable where available.
      Specified by:
        `iterator` in interface `java.lang.Iterable<PGPPublicKeyRing>`
      Specified by:
        `iterator` in interface `org.bouncycastle.util.Iterable<PGPPublicKeyRing>`