cecrets

package
v0.0.0-...-ce9259a Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SHA256 hashAlg = iota
	HMAC_SHA256
	Plaintext
	Flatmask
)

Variables

This section is empty.

Functions

func Conceal

func Conceal(a any) string

Conceal runs the currently configured hashing algorithm on the parameterized value.

func ConcealWith

func ConcealWith(alg hashAlg, s string) string

Conceal runs one of clues' hashing algorithms on the provided string.

func Hide

func Hide(a any) secret

Hide embeds the value in a secret struct where the Conceal() call contains a truncated hash of value. The hash function defaults to SHA256, but can be changed through configuration.

func HideAll

func HideAll(a ...any) []secret

HideAll is a quality-of-life wrapper for transforming multiple values to secret structs.

func Mask

func Mask(a any) secret

Mask embeds the value in a secret struct where the Conceal() call always returns a flat string: "***"

func SetHasher

func SetHasher(sc HashCfg)

SetHasher sets the hashing configuration used in all concealer structs, and Conceal() and Hash() calls.

Types

type Concealer

type Concealer interface {
	// Conceal produces an obfuscated representation of the value.
	Conceal() string
	// Concealers also need to comply with Format.
	// Complying with Conceal() alone doesn't guarantee that
	// the variable won't pass into fmt.Printf("%v") and skip
	// the whole conceal process.
	Format(fs fmt.State, verb rune)
	// PlainStringer is the opposite of conceal.
	// Useful for if you want to retrieve the raw value of a secret.
	PlainString() string
}

type HashCfg

type HashCfg struct {
	HashAlg hashAlg
	HMACKey []byte
}

func DefaultHash

func DefaultHash() HashCfg

DefaultHash creates a secrets configuration using the HMAC_SHA256 hash with a random key. This value is already set upon initialization of the package.

func NoHash

func NoHash() HashCfg

NoHash provides a secrets configuration with no hashing or masking of values.

Jump to

Keyboard shortcuts

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