Documentation ¶
Overview ¶
Package plaintext implements github.com/go-crypt/crypt interfaces with variants of plaintext useful for easy uptake of previously unhashed passwords.
This implementation is loaded by crypt.NewDecoderAll.
Index ¶
- Constants
- func Decode(encodedDigest string) (digest algorithm.Digest, err error)
- func DecodeVariant(v Variant) func(encodedDigest string) (digest algorithm.Digest, err error)
- func RegisterDecoder(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderBase64(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderPlainText(r algorithm.DecoderRegister) (err error)
- type Digest
- func (d *Digest) Encode() string
- func (d *Digest) Match(password string) (match bool)
- func (d *Digest) MatchAdvanced(password string) (match bool, err error)
- func (d *Digest) MatchBytes(passwordBytes []byte) (match bool)
- func (d *Digest) MatchBytesAdvanced(passwordBytes []byte) (match bool, err error)
- func (d *Digest) String() string
- type Hasher
- func (h *Hasher) Hash(password string) (hashed algorithm.Digest, err error)
- func (h *Hasher) HashWithSalt(password string, _ []byte) (hashed algorithm.Digest, err error)
- func (h *Hasher) MustHash(password string) (hashed algorithm.Digest)
- func (h *Hasher) Validate() (err error)
- func (h *Hasher) WithOptions(opts ...Opt) (err error)
- type Opt
- type Variant
Constants ¶
const ( // EncodingFmt is the encoding format for this algorithm. EncodingFmt = "$%s$%s" // AlgName is the name for this algorithm. AlgName = "plaintext" // AlgIdentifierPlainText is the identifier used in encoded plaintext variants of this algorithm. AlgIdentifierPlainText = AlgName // AlgIdentifierBase64 is the identifier used in encoded base64 variants of this algorithm. AlgIdentifierBase64 = "base64" )
Variables ¶
This section is empty.
Functions ¶
func DecodeVariant ¶
DecodeVariant the encoded digest into a algorithm.Digest provided it matches the provided plaintext.Variant. If plaintext.VariantNone is used all variants can be decoded.
func RegisterDecoder ¶
func RegisterDecoder(r algorithm.DecoderRegister) (err error)
RegisterDecoder the decoder with the algorithm.DecoderRegister.
func RegisterDecoderBase64 ¶
func RegisterDecoderBase64(r algorithm.DecoderRegister) (err error)
RegisterDecoderBase64 registers specifically the base64 decoder variant with the algorithm.DecoderRegister.
func RegisterDecoderPlainText ¶
func RegisterDecoderPlainText(r algorithm.DecoderRegister) (err error)
RegisterDecoderPlainText registers specifically the plaintext decoder variant with the algorithm.DecoderRegister.
Types ¶
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest is an algorithm.Digest which handles plaintext matching.
func NewBase64Digest ¶
NewBase64Digest creates a new plaintext.Digest using the Base64 plaintext.Variant.
func (*Digest) Match ¶
Match returns true if the string password matches the current plaintext.Digest.
func (*Digest) MatchAdvanced ¶
MatchAdvanced is the same as Match except if there is an error it returns that as well.
func (*Digest) MatchBytes ¶
MatchBytes returns true if the []byte passwordBytes matches the current plaintext.Digest.
func (*Digest) MatchBytesAdvanced ¶
MatchBytesAdvanced is the same as MatchBytes except if there is an error it returns that as well.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a crypt.Hash for plaintext which can be initialized via plaintext.New using a functional options pattern.
func (*Hasher) Hash ¶
Hash performs the hashing operation on a password and resets any relevant parameters such as a manually set salt. It then returns a plaintext.Digest and error.
func (*Hasher) HashWithSalt ¶
HashWithSalt is an overload of plaintext.Digest that also accepts a salt.
func (*Hasher) MustHash ¶
MustHash overloads the Hash method and panics if the error is not nil. It's recommended if you use this method to utilize the Validate method first or handle the panic appropriately.
func (*Hasher) Validate ¶
Validate checks the hasher configuration to ensure it's valid. This should be used when the plaintext.Hasher is going to be reused and you should use it in conjunction with MustHash.
func (*Hasher) WithOptions ¶
WithOptions applies the provided functional options provided as an plaintext.Opt to the plaintext.Hasher.
type Opt ¶
Opt describes the functional option pattern for the plaintext.Hasher.
func WithVariant ¶
WithVariant configures the plaintext.Variant of the resulting plaintext.Digest. Default is plaintext.VariantPlainText.
func WithVariantName ¶
WithVariantName uses the variant name or identifier to configure the plaintext.Variant of the resulting plaintext.Digest. Default is plaintext.VariantPlainText.
type Variant ¶
type Variant int
Variant is a variant of the plaintext.Digest.
const ( // VariantNone is a variant of the plaintext.Digest which is unknown. VariantNone Variant = iota // VariantPlainText is a variant of the plaintext.Digest which stores the key as plain text. VariantPlainText // VariantBase64 is a variant of the plaintext.Digest which stores the key as a base64 string. VariantBase64 )
func NewVariant ¶
NewVariant converts an identifier string to a plaintext.Variant.