Class Secret
java.lang.Object
codes.grow.packages.betterstack.core.Secret
A credential held in a
char[] that never prints itself.
toString() and JSON serialisation return "[REDACTED]". Call reveal() only where the value is sent, and clear() to overwrite the characters when
the credential is no longer needed.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Overwrites the characters with zeros; laterreveal()calls throw.booleanReturns whetherclear()was called.booleanisEmpty()Returns whether the value is empty.static Secretof(char[] value) Wraps a copy of a character array; the caller may clear its own array afterwards.static SecretWraps a string value.reveal()Returns the credential as a string.char[]Returns a copy of the credential characters.booleanCompares the values in constant time.toString()Always "[REDACTED]".
-
Method Details
-
of
Wraps a string value.- Parameters:
value- the credential- Returns:
- a new secret
-
of
Wraps a copy of a character array; the caller may clear its own array afterwards.- Parameters:
value- the credential- Returns:
- a new secret
-
reveal
Returns the credential as a string.- Returns:
- the value
- Throws:
IllegalStateException- afterclear()
-
revealChars
public char[] revealChars()Returns a copy of the credential characters.- Returns:
- a new array the caller should clear after use
- Throws:
IllegalStateException- afterclear()
-
isEmpty
public boolean isEmpty()Returns whether the value is empty.- Returns:
- true for an empty credential
-
isCleared
public boolean isCleared()Returns whetherclear()was called.- Returns:
- true once cleared
-
clear
public void clear()Overwrites the characters with zeros; laterreveal()calls throw. Idempotent. -
sameValue
Compares the values in constant time.- Parameters:
other- another secret- Returns:
- true when both hold the same characters
-
toString
Always "[REDACTED]".
-