Documentation
¶
Overview ¶
Package secret provides opaque secret values.
Index ¶
- Constants
- Variables
- func Equal(a, b Value) bool
- func IsEmpty(value Value) bool
- func WithValue(value Value, fn func([]byte) error) error
- type Value
- func (Value) Format(state fmt.State, verb rune)
- func (*Value) GobDecode([]byte) error
- func (Value) GobEncode() ([]byte, error)
- func (Value) LogValue() slog.Value
- func (Value) MarshalJSON() ([]byte, error)
- func (Value) MarshalText() ([]byte, error)
- func (value *Value) UnmarshalJSON([]byte) error
- func (value *Value) UnmarshalText([]byte) error
Constants ¶
const Redacted = "[REDACTED]"
Redacted is the representation used by formatting, logging, and JSON/text serialization.
Variables ¶
var ( // ErrNilCallback indicates that WithValue was called without a callback. ErrNilCallback = errors.New("secret: value callback is nil") // ErrCannotSerialize indicates that secret values cannot be encoded with gob. ErrCannotSerialize = errors.New("secret: gob encoding of secret values is not supported") // ErrCannotDeserialize indicates that serialized secret values cannot be restored. ErrCannotDeserialize = errors.New("secret: serialized values cannot be restored; supply the secret again") )
Functions ¶
func Equal ¶
Equal reports whether a and b contain the same secret bytes. For equal-length values, the comparison is constant-time. Different lengths return immediately, so secret length is observable. Do not use reflect.DeepEqual to compare secrets; it can inspect Value's private content and is not constant-time.
Types ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is an opaque secret. Its zero value is empty. Use New to construct a value and WithValue for the narrow operation that must consume its contents. Value deliberately has no plaintext String or Unwrap method and is not comparable. reflect.DeepEqual can still inspect its private content and is not constant-time; use Equal for secret comparisons.
func New ¶
New constructs an opaque secret value. The input string is retained as the private representation; callers should avoid keeping unnecessary copies.
func (Value) MarshalJSON ¶
MarshalJSON always emits a redaction marker, never the secret contents.
func (Value) MarshalText ¶
MarshalText always emits a redaction marker, never the secret contents.
func (*Value) UnmarshalJSON ¶
UnmarshalJSON refuses to restore a secret from serialized data.
func (*Value) UnmarshalText ¶
UnmarshalText refuses to restore a secret from serialized data.