Files
lazysecrets/internal/provider/value.go
T
keb 19299631b8
CI / Checks (pull_request) Successful in 37s
PR title / Conventional title (pull_request) Successful in 1s
refactor: drop dead code and use the standard library where it already does the job
No behaviour change.

- Deleted, unused or one-line wrappers: panes.RuneIndexes, Detail.Refresh (SetDescribed does it), SecretValue.Len, Query.Empty, Clipboard.Native, config.Load, get's value, Model.done, providerOf (cachefile.ProviderOf), contextWithTimeout, searchCoverage, startCrawl, showKeybindings, the expiry aliases and daysLeft.
- cmp.Or instead of the two cmpOr copies; slices.Sorted(maps.Keys(…)), maps.Copy, wg.Go, utf8.RuneCountInString and new(true) instead of loops and helpers that do the same.
- A container's pane title is set once, not twice; a redundant length check in share links and a no-op assignment in linkhandler.Launch are gone.
- Tests call ansi.Strip and lastLines directly; gofmt -s on links.go.
2026-10-15 08:54:42 +02:00

33 lines
998 B
Go

package provider
import (
"fmt"
"log/slog"
)
const masked = "••••••"
// SecretValue holds a secret's plaintext. Every formatting, logging and
// encoding path renders it masked; the plaintext is only available through
// Reveal, so it cannot leak through a stray Printf, slog call or error.
type SecretValue struct {
b []byte
}
func NewSecretValue(b []byte) SecretValue {
return SecretValue{b: append([]byte(nil), b...)}
}
// Reveal returns the plaintext. Call it only to display or copy the value.
func (v SecretValue) Reveal() string { return string(v.b) }
func (v SecretValue) String() string { return masked }
func (v SecretValue) GoString() string { return masked }
// Format covers every fmt verb, including %#v and %x.
func (v SecretValue) Format(f fmt.State, _ rune) { _, _ = f.Write([]byte(masked)) }
func (v SecretValue) LogValue() slog.Value { return slog.StringValue(masked) }
func (v SecretValue) MarshalText() ([]byte, error) { return []byte(masked), nil }