Class KeyringPassword

java.lang.Object
zeroecho.core.storage.KeyringPassword
All Implemented Interfaces:
AutoCloseable, Destroyable

public final class KeyringPassword extends Object implements Destroyable, AutoCloseable
Destroyable owner of a keyring password.

The constructor and copy() use defensive copies. Callers retain ownership of the array supplied to the constructor and must clear it. The returned copy belongs to the receiver and must be cleared immediately after key derivation. This object never creates an immutable password String.

Instances are thread-safe. Destruction is idempotent and makes subsequent access fail deterministically.

  • Constructor Details

    • KeyringPassword

      public KeyringPassword(char[] password)
      Creates a password owner.
      Parameters:
      password - password characters, which are defensively copied
      Throws:
      NullPointerException - if password is null
      IllegalArgumentException - if password is empty
  • Method Details

    • copy

      public char[] copy()
      Returns a receiver-owned password copy.
      Returns:
      a new mutable array that the receiver must clear
      Throws:
      IllegalStateException - if this object has been destroyed
    • destroy

      public void destroy() throws DestroyFailedException
      Clears the owned password characters.
      Specified by:
      destroy in interface Destroyable
      Throws:
      DestroyFailedException - never thrown by this implementation
    • isDestroyed

      public boolean isDestroyed()
      Reports whether the password has been destroyed.
      Specified by:
      isDestroyed in interface Destroyable
      Returns:
      true after destruction
    • close

      public void close()
      Destroys the password.
      Specified by:
      close in interface AutoCloseable
    • toString

      public String toString()
      Returns a redacted representation.
      Overrides:
      toString in class Object
      Returns:
      a constant redacted value