secret

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 5 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 holds credential material in an opaque Secret type whose formatting and marshalling methods return only the redacted form. It imports nothing from TokenHound.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Split added in v0.2.0

func Split(n int) (pre, suf int)

Split returns how many leading and trailing runes the redacted form of an n-rune key shows. pre+suf never exceeds n/2. Readers of a redacted form use it to find the prefix and suffix by length, never by searching for "...".

Types

type Secret

type Secret struct {
	// contains filtered or unexported fields
}

Secret holds key material. Every formatting, marshalling and logging method returns only the redacted form; Reveal returns the value and is allowed only where a request or a fingerprint needs it (forbidigo, AD-3).

The value sits behind an unexported pointer to a closure, so even reflection-based printing of a struct that holds a Secret in an unexported field (fmt prints such fields without calling their methods, and dereferences pointers for bad verbs such as %s) shows only addresses and the length.

func New

func New(v string) Secret

New wraps v. An empty v yields the zero Secret.

func (Secret) Format

func (s Secret) Format(f fmt.State, verb rune)

Format writes the redacted form for every verb; %q quotes it.

func (Secret) GoString

func (s Secret) GoString() string

GoString returns the redacted form, for %#v.

func (Secret) IsZero

func (s Secret) IsZero() bool

IsZero reports whether s holds no key.

func (Secret) Len

func (s Secret) Len() int

Len returns the length of the key in runes.

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

LogValue logs the redacted form.

func (Secret) MarshalJSON

func (s Secret) MarshalJSON() ([]byte, error)

MarshalJSON marshals the redacted form as a JSON string.

func (Secret) MarshalText

func (s Secret) MarshalText() ([]byte, error)

MarshalText returns the redacted form.

func (Secret) Redacted

func (s Secret) Redacted() string

Redacted returns the display form: the first 6 runes, "...", the last 4 runes and the length, for example "sk-pro...a1b2 (51)". Keys of 12 to 19 runes show 4 and 2; shorter keys show at most half their runes in total.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the key material. Call it only in internal/verify, internal/detect, internal/netx and internal/gitx.

func (Secret) String

func (s Secret) String() string

String returns the redacted form.

Jump to

Keyboard shortcuts

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