Class PublicKeyStore

java.lang.Object
ch.threema.apitool.PublicKeyStore

public abstract class PublicKeyStore extends Object
Stores and caches public keys for Threema users. Extend this class to provide your own storage implementation, e.g. in a file or database.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract byte[]
    Fetch the public key for the given Threema ID from the store.
    final byte[]
    getPublicKey(String threemaId)
    Get the public key for a given Threema ID.
    protected abstract void
    save(String threemaId, byte[] publicKey)
    Save the public key for a given Threema ID in the store.
    final void
    setPublicKey(String threemaId, byte[] publicKey)
    Store the public key for a given Threema ID in the cache, and the underlying store.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PublicKeyStore

      public PublicKeyStore()
  • Method Details

    • getPublicKey

      public final byte[] getPublicKey(String threemaId)
      Get the public key for a given Threema ID. The cache is checked first; if it is not found in the cache, fetchPublicKey() is called.
      Parameters:
      threemaId - The Threema ID whose public key should be obtained
      Returns:
      The public key, or null if not found.
    • setPublicKey

      public final void setPublicKey(String threemaId, byte[] publicKey)
      Store the public key for a given Threema ID in the cache, and the underlying store.
      Parameters:
      threemaId - The Threema ID whose public key should be stored
      publicKey - The corresponding public key.
    • fetchPublicKey

      protected abstract byte[] fetchPublicKey(String threemaId)
      Fetch the public key for the given Threema ID from the store. Override to provide your own implementation to read from the store.
      Parameters:
      threemaId - The Threema ID whose public key should be obtained
      Returns:
      The public key, or null if not found.
    • save

      protected abstract void save(String threemaId, byte[] publicKey)
      Save the public key for a given Threema ID in the store. Override to provide your own implementation to write to the store.
      Parameters:
      threemaId - The Threema ID whose public key should be stored
      publicKey - The corresponding public key.