butcher: zntr.io/butcher Index | Files | Directories

package butcher

import "zntr.io/butcher"

Index

Package Files

lib.go nonce.go options.go

Constants

const (
    // DefaultAlgorithm defines the default algorithm to use when not specified
    DefaultAlgorithm = hasher.Argon2id
    // ExpectedAlgorithmVersion defines the lower supported version of the hashing strategy
    ExpectedAlgorithmVersion = uint8(0x01)
)

Variables

var (
    // ErrInvalidHash is raised when caller try to invoke not supported algorithm
    ErrInvalidHash = errors.New("butcher: invalid hash")
    // ErrStrategyNotSupported is raised when caller try to invoke not supported algorithm
    ErrStrategyNotSupported = errors.New("butcher: given strategy is not supported")
)
var DefaultSaltFunc = RandomNonce(32)

DefaultSaltFunc defines the default salt generation factory to use when not specified

func FixedNonce Uses

func FixedNonce(salt []byte) func() []byte

FixedNonce returns a nonce factory that returns the given salt

func Hash Uses

func Hash(password []byte) (string, error)

Hash password using default instance

func NeedsUpgrade Uses

func NeedsUpgrade(encoded []byte) bool

NeedsUpgrade returns the password hash upgrade need when DefaultAlgorithm is changed

func RandomNonce Uses

func RandomNonce(length int) func() []byte

RandomNonce returns a nonce factory that returns a random length bound salt

func Verify Uses

func Verify(encoded, password []byte) (bool, error)

Verify password using default instance

type Butcher Uses

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

Butcher defines the hasher configuration

func New Uses

func New(options ...Option) (*Butcher, error)

New butcher instance is buildded according options

func (*Butcher) Hash Uses

func (b *Butcher) Hash(password []byte) (string, error)

Hash the given password with the hash strategy

func (*Butcher) NeedsUpgrade Uses

func (b *Butcher) NeedsUpgrade(encoded []byte) bool

NeedsUpgrade returns the password hash upgrade need when DefaultAlgorithm is changed

func (*Butcher) Verify Uses

func (b *Butcher) Verify(encoded, password []byte) (bool, error)

Verify cleartext password with encoded one

type Option Uses

type Option func(*Butcher)

Option is the butcher option setting function signature

func WithAlgorithm Uses

func WithAlgorithm(algo hasher.Algorithm) Option

WithAlgorithm defines the algorithm to use for hashing password

func WithPepper Uses

func WithPepper(value []byte) Option

WithPepper defines the password peppering value

func WithSaltFunc Uses

func WithSaltFunc(factory func() []byte) Option

WithSaltFunc defines the salt factory value for salt generation

Directories

PathSynopsis
hasher

Package butcher imports 7 packages (graph). Updated 2020-06-05. Refresh now. Tools for package owners.