sha1crypt

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sha1crypt provides helpful abstractions for an implementation of crypt (SHA1) and implements github.com/go-crypt/crypt interfaces.

This implementation is loaded by crypt.NewDecoderAll.

Index

Constants

View Source
const (
	// EncodingFmt is the encoding format for this algorithm.
	EncodingFmt = "$sha1$%d$%s$%s"

	// AlgName is the name for this algorithm.
	AlgName = "sha1crypt"

	// AlgIdentifier is the identifier used in this algorithm.
	AlgIdentifier = "sha1"

	// SaltLengthMin is the minimum salt size accepted.
	SaltLengthMin = 0

	// SaltLengthMax is the maximum salt size accepted.
	SaltLengthMax = 64

	// SaltLengthDefault is the default salt size.
	SaltLengthDefault = 8

	// SaltCharSet are the valid characters for the salt.
	SaltCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"

	// IterationsMin is the minimum iterations accepted.
	IterationsMin = 0

	// IterationsMax is the maximum iterations accepted.
	IterationsMax uint32 = math.MaxUint32

	// IterationsDefault is the default iterations.
	IterationsDefault = 480000
)

Variables

This section is empty.

Functions

func Decode

func Decode(encodedDigest string) (digest algorithm.Digest, err error)

Decode the encoded digest into a algorithm.Digest.

func RegisterDecoder

func RegisterDecoder(r algorithm.DecoderRegister) (err error)

RegisterDecoder the decoder with the algorithm.DecoderRegister.

func RegisterDecoderCommon

func RegisterDecoderCommon(r algorithm.DecoderRegister) (err error)

RegisterDecoderCommon registers specifically the common decoder variant with the algorithm.DecoderRegister.

Types

type Digest

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

Digest is a algorithm.Digest which handles sha1crypt hashes.

func (*Digest) Encode

func (d *Digest) Encode() string

Encode returns the encoded form of this sha1crypt.Digest.

func (*Digest) Match

func (d *Digest) Match(password string) (match bool)

Match returns true if the string password matches the current sha1crypt.Digest.

func (*Digest) MatchAdvanced

func (d *Digest) MatchAdvanced(password string) (match bool, err error)

MatchAdvanced is the same as Match except if there is an error it returns that as well.

func (*Digest) MatchBytes

func (d *Digest) MatchBytes(passwordBytes []byte) (match bool)

MatchBytes returns true if the []byte passwordBytes matches the current sha1crypt.Digest.

func (*Digest) MatchBytesAdvanced

func (d *Digest) MatchBytesAdvanced(passwordBytes []byte) (match bool, err error)

MatchBytesAdvanced is the same as MatchBytes except if there is an error it returns that as well.

func (*Digest) String

func (d *Digest) String() string

String returns the storable format of the sha1crypt.Digest encoded hash.

type Hasher

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

Hasher is a crypt.Hash for sha1crypt which can be initialized via sha1crypt.New using a functional options pattern.

func New

func New(opts ...Opt) (hasher *Hasher, err error)

New returns a *sha1crypt.Hasher with the additional opts applied if any.

func (*Hasher) Hash

func (h *Hasher) Hash(password string) (digest algorithm.Digest, err error)

Hash performs the hashing operation and returns either a algorithm.Digest or an error.

func (*Hasher) HashWithSalt

func (h *Hasher) HashWithSalt(password string, salt []byte) (digest algorithm.Digest, err error)

HashWithSalt overloads the Hash method allowing the user to provide a salt. It's recommended instead to configure the salt size and let this be a random value generated using crypto/rand.

func (*Hasher) MustHash

func (h *Hasher) MustHash(password string) (digest algorithm.Digest)

MustHash overloads the Hash method and panics if the error is not nil. It's recommended if you use this option to utilize the Validate method first or handle the panic appropriately.

func (*Hasher) Validate

func (h *Hasher) Validate() (err error)

Validate checks the settings/parameters for this sha1crypt.Hasher and returns an error.

func (*Hasher) WithOptions

func (h *Hasher) WithOptions(opts ...Opt) (err error)

WithOptions applies the provided functional options provided as a sha1crypt.Opt to the sha1crypt.Hasher.

type Opt

type Opt func(h *Hasher) (err error)

Opt describes the functional option pattern for the sha1crypt.Hasher.

func WithIterations

func WithIterations(iterations uint32) Opt

WithIterations sets the iterations parameter of the resulting sha1crypt.Digest. Minimum is 0, Maximum is 4294967295. Default is 480000.

func WithRounds

func WithRounds(rounds uint32) Opt

WithRounds is an alias for sha1crypt.WithIterations.

func WithSaltLength

func WithSaltLength(bytes int) Opt

WithSaltLength adjusts the salt size (in bytes) of the resulting sha1crypt.Digest. Minimum is 1, Maximum is 64. Default is 8.

Jump to

Keyboard shortcuts

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