plaintext

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 4 Imported by: 1

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

View Source
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 Decode

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

Decode the encoded digest into a algorithm.Digest.

func DecodeVariant

func DecodeVariant(v Variant) func(encodedDigest string) (digest algorithm.Digest, err error)

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

func NewBase64Digest(password string) (digest Digest)

NewBase64Digest creates a new plaintext.Digest using the Base64 plaintext.Variant.

func NewDigest

func NewDigest(password string) (digest Digest)

NewDigest creates a new plaintext.Digest using the plaintext.Variant.

func (*Digest) Encode

func (d *Digest) Encode() string

Encode returns the encoded form of this plaintext.Digest.

func (*Digest) Match

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

Match returns true if the string password matches the current plaintext.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 plaintext.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 plaintext.Digest encoded hash.

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 New

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

New returns a *plaintext.Hasher without any settings configured.

func (*Hasher) Hash

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

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

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

HashWithSalt is an overload of plaintext.Digest that also accepts a salt.

func (*Hasher) MustHash

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

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

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

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

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

WithOptions applies the provided functional options provided as an plaintext.Opt to the plaintext.Hasher.

type Opt

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

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

func WithVariant

func WithVariant(variant Variant) Opt

WithVariant configures the plaintext.Variant of the resulting plaintext.Digest. Default is plaintext.VariantPlainText.

func WithVariantName

func WithVariantName(identifier string) Opt

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

func NewVariant(identifier string) (variant Variant)

NewVariant converts an identifier string to a plaintext.Variant.

func (Variant) Decode

func (v Variant) Decode(src string) (dst []byte, err error)

Decode performs the decode operation for this plaintext.Variant.

func (Variant) Encode

func (v Variant) Encode(src []byte) (dst string)

Encode performs the encode operation for this plaintext.Variant.

func (Variant) Prefix

func (v Variant) Prefix() (prefix string)

Prefix returns the plaintext.Variant prefix identifier.

Jump to

Keyboard shortcuts

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