Class OpenPGPKeyMaterialPool<M extends OpenPGPCertificate>

java.lang.Object
org.bouncycastle.openpgp.api.OpenPGPKeyMaterialPool<M>
Type Parameters:
M - OpenPGPCertificate or OpenPGPKey
All Implemented Interfaces:
OpenPGPKeyMaterialProvider<M>
Direct Known Subclasses:
OpenPGPKeyMaterialPool.OpenPGPCertificatePool, OpenPGPKeyMaterialPool.OpenPGPKeyPool

public abstract class OpenPGPKeyMaterialPool<M extends OpenPGPCertificate> extends Object implements OpenPGPKeyMaterialProvider<M>
Implementation of the OpenPGPKeyMaterialProvider which caches items in a HashMap. It allows to provide key or certificates dynamically via a callback that can be set using setMissingItemCallback(OpenPGPKeyMaterialProvider). Results from this callback are automatically cached for later access. This behavior can be adjusted via setCacheResultsFromCallback(boolean).
  • Constructor Details

    • OpenPGPKeyMaterialPool

      public OpenPGPKeyMaterialPool()
      Create an empty pool.
    • OpenPGPKeyMaterialPool

      public OpenPGPKeyMaterialPool(M item)
      Create a pool from the single provided item.
      Parameters:
      item - item
    • OpenPGPKeyMaterialPool

      public OpenPGPKeyMaterialPool(Collection<M> items)
      Create a pool and initialize its contents with the provided collection of items.
      Parameters:
      items - collection of keys or certificates
  • Method Details

    • setMissingItemCallback

      public OpenPGPKeyMaterialPool<M> setMissingItemCallback(OpenPGPKeyMaterialProvider<M> callback)
      Set a callback that gets fired whenever an item is requested, which is not found in the pool.
      Parameters:
      callback - callback
      Returns:
      this
    • setCacheResultsFromCallback

      public OpenPGPKeyMaterialPool<M> setCacheResultsFromCallback(boolean cacheResults)
      Decide, whether the implementation should add certificates returned by callback to the pool of cached certificates.
      Parameters:
      cacheResults - if true, cache certificates from callback
      Returns:
      this
    • provide

      public M provide(KeyIdentifier componentKeyIdentifier)
      Description copied from interface: OpenPGPKeyMaterialProvider
      Provide the requested OpenPGPCertificate or OpenPGPKey containing the component key identified by the passed in KeyIdentifier.
      Specified by:
      provide in interface OpenPGPKeyMaterialProvider<M extends OpenPGPCertificate>
      Parameters:
      componentKeyIdentifier - identifier of a component key (primary key or subkey)
      Returns:
      the OpenPGP certificate or key containing the identified component key
    • addItem

      public OpenPGPKeyMaterialPool<M> addItem(M item)
      Add a certificate to the pool. Note: If multiple items share the same subkey material, adding an item might overwrite the reference to another item for that subkey.
      Parameters:
      item - OpenPGP key or certificate that shall be added into the pool
      Returns:
      this
    • getAllItems

      public Collection<M> getAllItems()
      Return all items from the pool.
      Returns:
      all items