secret

package
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package secret provides opaque secret values.

Index

Constants

View Source
const Redacted = "[REDACTED]"

Redacted is the representation used by formatting, logging, and JSON/text serialization.

Variables

View Source
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

func Equal(a, b Value) bool

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.

func IsEmpty

func IsEmpty(value Value) bool

IsEmpty reports whether value contains no secret bytes.

func WithValue

func WithValue(value Value, fn func([]byte) error) error

WithValue provides a temporary byte copy of value to fn and clears that copy when fn returns. Callers must not retain or copy the bytes. Go cannot promise erasure of the immutable source string or any copies made by the caller.

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

func New(value string) Value

New constructs an opaque secret value. The input string is retained as the private representation; callers should avoid keeping unnecessary copies.

func (Value) Format

func (Value) Format(state fmt.State, verb rune)

Format prevents fmt from exposing the secret for any formatting verb.

func (*Value) GobDecode

func (*Value) GobDecode([]byte) error

GobDecode refuses to restore a secret value from gob data.

func (Value) GobEncode

func (Value) GobEncode() ([]byte, error)

GobEncode refuses to serialize secret values through gob.

func (Value) LogValue

func (Value) LogValue() slog.Value

LogValue prevents slog from recording the secret contents.

func (Value) MarshalJSON

func (Value) MarshalJSON() ([]byte, error)

MarshalJSON always emits a redaction marker, never the secret contents.

func (Value) MarshalText

func (Value) MarshalText() ([]byte, error)

MarshalText always emits a redaction marker, never the secret contents.

func (*Value) UnmarshalJSON

func (value *Value) UnmarshalJSON([]byte) error

UnmarshalJSON refuses to restore a secret from serialized data.

func (*Value) UnmarshalText

func (value *Value) UnmarshalText([]byte) error

UnmarshalText refuses to restore a secret from serialized data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL