Top Description Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPPublicKeyRingCollection

extends Object
implements Iterable<PGPPublicKeyRing>
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Iterable, java.lang.Iterable
Known Direct Subclasses
org.bouncycastle.openpgp.jcajce.JcaPGPPublicKeyRingCollection
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collection, .HashMap, .Iterator, .List, .Map, org.bouncycastle.bcpg.BCPGOutputStream, org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator, org.bouncycastle.util.Iterable, .Strings

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.

Field Summary

Modifier and TypeField and Description
private List<Long>
private Map<Long, PGPPublicKeyRing>

Constructor Summary

AccessConstructor and Description
private
public
PGPPublicKeyRingCollection(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator)

public
PGPPublicKeyRingCollection(InputStream
input stream containing data
in
,
KeyFingerPrintCalculator fingerPrintCalculator)

Build a PGPPublicKeyRingCollection from the passed in input stream.

public

Method Summary

Modifier and TypeMethod and Description
public static PGPPublicKeyRingCollection

Returns:

a new collection merging the current one with the passed in ring.
addPublicKeyRing
(PGPPublicKeyRingCollection
the collection the ring to be added to.
ringCollection
,
PGPPublicKeyRing
the key ring to be added.
publicKeyRing
)

Return a new collection object containing the contents of the passed in collection and the passed in public key ring.

public boolean

Returns:

true if keyID present, false otherwise.
contains
(long
key ID to look for.
keyID
)

Return true if a key matching the passed in key ID is present, false otherwise.

public boolean

Returns:

true if keyID present, false otherwise.
contains
(byte[]
hte key fingerprint to look for.
fingerprint
)

Return true if a key matching the passed in fingerprint is present, false otherwise.

public void
encode(OutputStream outStream)

public byte[]
public Iterator<PGPPublicKeyRing>
getKeyRings()

return the public key rings making up this collection.

public Iterator<PGPPublicKeyRing>

Returns:

an iterator (possibly empty) of key rings which matched.
getKeyRings
(String
the user ID to be matched.
userID
)

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

public Iterator<PGPPublicKeyRing>

Returns:

an iterator (possibly empty) of key rings which matched.
getKeyRings
(String
the user ID to be matched.
userID
,
boolean
if true userID need only be a substring of an actual ID string to match.
matchPartial
)

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

public Iterator<PGPPublicKeyRing>

Returns:

an iterator (possibly empty) of key rings which matched.
getKeyRings
(String
the user ID to be matched.
userID
,
boolean
if true userID need only be a substring of an actual ID string to match.
matchPartial
,
boolean
if true case is ignored in user ID comparisons.
ignoreCase
)

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

public Iterator<PGPPublicKey>

Returns:

an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.
getKeysWithSignaturesBy
(long
the key id to be matched against.
keyID
)

Return any keys carrying a signature issued by the key represented by keyID.

public PGPPublicKey

Returns:

the PGP public key
getPublicKey
(long
if of the PGP public key
keyID
)

Return the PGP public key associated with the given key id.

public PGPPublicKey

Returns:

the PGP public key matching fingerprint.
getPublicKey
(byte[]
the public key fingerprint to match against.
fingerprint
)

Return the PGP public key associated with the given key fingerprint.

public PGPPublicKeyRing

Returns:

the public key ring
getPublicKeyRing
(long
key ID to match against
keyID
)

Return the public key ring which contains the key referred to by keyID.

public PGPPublicKeyRing

Returns:

the PGP public key ring containing the PGP public key matching fingerprint.
getPublicKeyRing
(byte[]
the public key fingerprint to match against.
fingerprint
)

Return the PGP public key associated with the given key fingerprint.

public Iterator<PGPPublicKeyRing>
iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.
public static PGPPublicKeyRingCollection

Returns:

a new collection not containing the passed in ring.
removePublicKeyRing
(PGPPublicKeyRingCollection
the collection the ring to be removed from.
ringCollection
,
PGPPublicKeyRing
the key ring to be removed.
publicKeyRing
)

Return a new collection object containing the contents of this collection with the passed in public key ring removed.

public int

Returns:

size of the collection
size
()

Return the number of rings in this collection.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

orderback to summary
private List<Long> order
pubRingsback to summary
private Map<Long, PGPPublicKeyRing> pubRings

Constructor Detail

PGPPublicKeyRingCollectionback to summary
private PGPPublicKeyRingCollection(Map<Long, PGPPublicKeyRing> pubRings, List<Long> order)
PGPPublicKeyRingCollectionback to summary
public PGPPublicKeyRingCollection(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException
PGPPublicKeyRingCollectionback to summary
public PGPPublicKeyRingCollection(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException

Build a PGPPublicKeyRingCollection from the passed in input stream.

Parameters
in:InputStream

input stream containing data

Exceptions
IOException:
if a problem parsing the base stream occurs
PGPException:
if an object is encountered which isn't a PGPPublicKeyRing
PGPPublicKeyRingCollectionback to summary
public PGPPublicKeyRingCollection(Collection<PGPPublicKeyRing> collection)

Method Detail

addPublicKeyRingback to summary
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:PGPPublicKeyRingCollection

the collection the ring to be added to.

publicKeyRing:PGPPublicKeyRing

the key ring to be added.

Returns:PGPPublicKeyRingCollection

a new collection merging the current one with the passed in ring.

Exceptions
IllegalArgumentException:
if the keyID for the passed in ring is already present.
containsback to summary
public boolean contains(long keyID)

Return true if a key matching the passed in key ID is present, false otherwise.

Parameters
keyID:long

key ID to look for.

Returns:boolean

true if keyID present, false otherwise.

containsback to summary
public boolean contains(byte[] fingerprint)

Return true if a key matching the passed in fingerprint is present, false otherwise.

Parameters
fingerprint:byte[]

hte key fingerprint to look for.

Returns:boolean

true if keyID present, false otherwise.

encodeback to summary
public void encode(OutputStream outStream) throws IOException
getEncodedback to summary
public byte[] getEncoded() throws IOException
getKeyRingsback to summary
public Iterator<PGPPublicKeyRing> getKeyRings()

return the public key rings making up this collection.

getKeyRingsback to summary
public Iterator<PGPPublicKeyRing> getKeyRings(String userID)

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

Parameters
userID:String

the user ID to be matched.

Returns:Iterator<PGPPublicKeyRing>

an iterator (possibly empty) of key rings which matched.

getKeyRingsback to summary
public Iterator<PGPPublicKeyRing> getKeyRings(String userID, boolean matchPartial)

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

Parameters
userID:String

the user ID to be matched.

matchPartial:boolean

if true userID need only be a substring of an actual ID string to match.

Returns:Iterator<PGPPublicKeyRing>

an iterator (possibly empty) of key rings which matched.

getKeyRingsback to summary
public Iterator<PGPPublicKeyRing> getKeyRings(String userID, boolean matchPartial, boolean ignoreCase)

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

Parameters
userID:String

the user ID to be matched.

matchPartial:boolean

if true userID need only be a substring of an actual ID string to match.

ignoreCase:boolean

if true case is ignored in user ID comparisons.

Returns:Iterator<PGPPublicKeyRing>

an iterator (possibly empty) of key rings which matched.

getKeysWithSignaturesByback to summary
public Iterator<PGPPublicKey> getKeysWithSignaturesBy(long keyID)

Return any keys carrying a signature issued by the key represented by keyID.

Parameters
keyID:long

the key id to be matched against.

Returns:Iterator<PGPPublicKey>

an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.

getPublicKeyback to summary
public PGPPublicKey getPublicKey(long keyID)

Return the PGP public key associated with the given key id.

Parameters
keyID:long

if of the PGP public key

Returns:PGPPublicKey

the PGP public key

getPublicKeyback to summary
public PGPPublicKey getPublicKey(byte[] fingerprint)

Return the PGP public key associated with the given key fingerprint.

Parameters
fingerprint:byte[]

the public key fingerprint to match against.

Returns:PGPPublicKey

the PGP public key matching fingerprint.

getPublicKeyRingback to summary
public PGPPublicKeyRing getPublicKeyRing(long keyID)

Return the public key ring which contains the key referred to by keyID.

Parameters
keyID:long

key ID to match against

Returns:PGPPublicKeyRing

the public key ring

getPublicKeyRingback to summary
public PGPPublicKeyRing getPublicKeyRing(byte[] fingerprint)

Return the PGP public key associated with the given key fingerprint.

Parameters
fingerprint:byte[]

the public key fingerprint to match against.

Returns:PGPPublicKeyRing

the PGP public key ring containing the PGP public key matching fingerprint.

iteratorback to summary
public Iterator<PGPPublicKeyRing> iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.

Returns:Iterator<PGPPublicKeyRing>

Doc from org.bouncycastle.util.Iterable.iterator.

an Iterator.

removePublicKeyRingback to summary
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:PGPPublicKeyRingCollection

the collection the ring to be removed from.

publicKeyRing:PGPPublicKeyRing

the key ring to be removed.

Returns:PGPPublicKeyRingCollection

a new collection not containing the passed in ring.

Exceptions
IllegalArgumentException:
if the keyID for the passed in ring not present.
sizeback to summary
public int size()

Return the number of rings in this collection.

Returns:int

size of the collection