Class SecretBuffer
java.lang.Object
co.ankatech.ankasecure.sdk.security.SecretBuffer
- All Implemented Interfaces:
AutoCloseable
Owning wrapper for a sensitive
byte[]. Zeroizes on close() and nulls the
internal field reference. Use only inside try-with-resources blocks.
The underlying buffer is exposed via bytes() for read-only consumption while the
wrapper is open; access after close() throws IllegalStateException. The
contract takes ownership of the supplied array — the caller must NOT retain a
reference to it.
close() is idempotent: a second call is a no-op. The buffer is overwritten with
0x00 via Zeroization.zeroize(byte[]) before the field is nulled.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SecretBuffer
public SecretBuffer(byte[] owned) Takes ownership of the supplied array. The caller MUST NOT retain a reference toownedafter construction; ownership has transferred.- Throws:
NullPointerException- ifownedisnull
-
-
Method Details
-
bytes
public byte[] bytes()- Returns:
- the underlying buffer (read-only consumption pattern)
- Throws:
IllegalStateException- ifclose()has been called
-
length
public int length()- Returns:
- the length of the underlying buffer
- Throws:
IllegalStateException- ifclose()has been called
-
isClosed
public boolean isClosed()- Returns:
trueifclose()has been called; never throws
-
close
public void close()Zeroizes the underlyingbyte[](overwrites every element with0x00), nulls the internal field, and marks this wrapper as closed. Idempotent.- Specified by:
closein interfaceAutoCloseable
-