Class SecretPassword
java.lang.Object
zeroecho.sdk.content.builtin.SecretPassword
- All Implemented Interfaces:
Destroyable, DataContent, PlainContent, SecretContent
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
-
Field Summary
Fields inherited from interface DataContent
DEFAULT_MAX_READ_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionSecretPassword(char[] password) Constructs a password from a caller-owned character array.SecretPassword(int length) Constructs a password with randomly generated printable characters. -
Method Summary
Modifier and TypeMethodDescriptionchar[]chars()Returns an owned copy of the password characters.voiddestroy()Returns a stream over a private UTF-8 buffer.booleanvoidsetInput(DataContent input) Rejects preceding content because a password is a chain source.byte[]toBytes()Returns a UTF-8 encoding owned by the caller.toString()Returns a redacted diagnostic representation.toText()Returns a redacted diagnostic representation.
-
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- iflengthis 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 benull- Throws:
NullPointerException- ifpasswordisnull
-
-
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:
toBytesin interfaceDataContent- Returns:
- a newly allocated UTF-8 byte array
- Throws:
IllegalStateException- if this password has been destroyed
-
getStream
Returns a stream over a private UTF-8 buffer. Closing the stream wipes that buffer.- Specified by:
getStreamin interfaceDataContent- Returns:
- a stream that wipes its buffer when closed
- Throws:
IllegalStateException- if this password has been destroyed
-
toText
Returns a redacted diagnostic representation.- Specified by:
toTextin interfaceDataContent- Returns:
"[REDACTED]"
-
toString
-
setInput
Rejects preceding content because a password is a chain source.- Specified by:
setInputin interfaceDataContent- Parameters:
input- preceding content; must benull- Throws:
IllegalArgumentException- ifinputis non-null
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-