Class SecretPassword

java.lang.Object
zeroecho.sdk.content.builtin.SecretPassword
All Implemented Interfaces:
Destroyable, DataContent, PlainContent, SecretContent

public final class SecretPassword extends Object implements SecretContent, Destroyable
Destroyable password content backed exclusively by an owned character array.

Textual diagnostics are always redacted. Callers obtain explicit copies through chars() or toBytes() and remain responsible for wiping those copies.

Lifecycle operations are synchronized. Destruction is idempotent, wipes the complete owned character array, and prevents subsequent access to password material. Streams returned by getStream() wipe their private UTF-8 buffer when closed.

Author:
Leo Galambos
  • Constructor Details

    • SecretPassword

      public SecretPassword(int length)
      Constructs a password with randomly generated printable characters.
      Parameters:
      length - the length of the generated passwordKey
      Throws:
      IllegalArgumentException - if length is less than or equal to zero
    • SecretPassword

      public SecretPassword(char[] password)
      Constructs a password from a caller-owned character array. The supplied array is cloned and remains owned by the caller.
      Parameters:
      password - password characters; must not be null
      Throws:
      NullPointerException - if password is null
  • Method Details

    • chars

      public char[] chars()
      Returns an owned copy of the password characters.
      Returns:
      a newly allocated password copy
      Throws:
      IllegalStateException - if this password has been destroyed
    • toBytes

      public byte[] toBytes()
      Returns a UTF-8 encoding owned by the caller.
      Specified by:
      toBytes in interface DataContent
      Returns:
      a newly allocated UTF-8 byte array
      Throws:
      IllegalStateException - if this password has been destroyed
    • getStream

      public InputStream getStream()
      Returns a stream over a private UTF-8 buffer. Closing the stream wipes that buffer.
      Specified by:
      getStream in interface DataContent
      Returns:
      a stream that wipes its buffer when closed
      Throws:
      IllegalStateException - if this password has been destroyed
    • toText

      public String toText()
      Returns a redacted diagnostic representation.
      Specified by:
      toText in interface DataContent
      Returns:
      "[REDACTED]"
    • toString

      public String toString()
      Returns a redacted diagnostic representation.
      Overrides:
      toString in class Object
      Returns:
      "[REDACTED]"
    • setInput

      public void setInput(DataContent input)
      Rejects preceding content because a password is a chain source.
      Specified by:
      setInput in interface DataContent
      Parameters:
      input - preceding content; must be null
      Throws:
      IllegalArgumentException - if input is non-null
    • destroy

      public void destroy()
      Specified by:
      destroy in interface Destroyable
    • isDestroyed

      public boolean isDestroyed()
      Specified by:
      isDestroyed in interface Destroyable