Documentation
¶
Overview ¶
Package secret provides a type that cannot accidentally be written to a log.
Background: threat T-18 (secrets in logs). A `%+v` on a configuration struct is the most common way credentials end up in log files. A dedicated type with a masking String() makes that mistake impossible instead of merely forbidding it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bytes ¶
type Bytes struct {
// contains filtered or unexported fields
}
Bytes wraps confidential binary material - a key, a derived key, a nonce that must not be reused - the way Secret wraps a confidential string.
A separate type rather than Secret over a string, because key material is not text: converting it to a string to store it costs a copy that no longer masks, invites a comparison with `==`, and makes a length check read as a character count. The two exist side by side for the same reason threat T-18 exists at all - a `%+v` over a struct is how secrets reach log files, and a type that cannot print itself makes that mistake impossible rather than merely forbidden.
func NewBytes ¶
NewBytes takes ownership of the slice. The caller must not keep or reuse it: two references to one key are two places it can be overwritten from, and the copy this would otherwise make would leave the original lying about in the caller's frame either way.
func (Bytes) Equal ¶
Equal compares in constant time. The obvious `bytes.Equal` returns as soon as two bytes differ, which over repeated calls tells an attacker how much of a guess was right (security.md §8).
func (Bytes) Len ¶
Len is the length of the material. Safe to log, and the one thing about a key that is: "the key is 16 bytes where 32 were expected" is what an operator needs in order to fix a configuration.
func (Bytes) MarshalJSON ¶
func (Bytes) MarshalText ¶
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret wraps a confidential value. The plaintext is reachable only through Reveal.