Documentation
¶
Overview ¶
Package influxb2 implements github.com/go-crypt/crypt interfaces with variants of InfluxDB 2.x token hashing.
Index ¶
- Constants
- Variables
- func DecodeVariant(v Variant) func(encodedDigest string) (digest algorithm.Digest, err error)
- func RegisterDecoder(r algorithm.DecoderRegister) error
- func RegisterDecoderSHA256(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderSHA512(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderVariant(r algorithm.DecoderRegister, variant Variant) error
- type Digest
- func (d *Digest) Encode() string
- func (d *Digest) Key() []byte
- func (d *Digest) Match(password string) bool
- func (d *Digest) MatchAdvanced(password string) (match bool, err error)
- func (d *Digest) MatchBytes(passwordBytes []byte) 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, salt []byte) (hashed algorithm.Digest, err error)
- func (h *Hasher) MustHash(password string) (hashed algorithm.Digest)
- func (h *Hasher) Validate() (err error)
- func (h *Hasher) Variant() Variant
- func (h *Hasher) WithOptions(opts ...Opt) (err error)
- type Opt
- type Parameter
- type Variant
Constants ¶
const ( // EncodingFmt is the encoding format for this algorithm. EncodingFmt = "$%s$%s" // EncodingSections is the number sections in EncodingFmt delimited by crypt.Delimiter. EncodingSections = 2 // AlgName is the name for this algorithm. AlgName = "influxdb2" // VariantIdentifierSHA256 is the identifier used in SHA256 variants of this algorithm. VariantIdentifierSHA256 = "influxdb2-sha256" // VariantIdentifierSHA512 is the identifier used in SHA512 variants of this algorithm. VariantIdentifierSHA512 = "influxdb2-sha512" )
const ( // ParameterDefaultItemSeparator is the default item separator. ParameterDefaultItemSeparator = "," // ParameterDefaultKeyValueSeparator is the default key value separator. ParameterDefaultKeyValueSeparator = "=" )
const DefaultVariant = VariantSHA256
Variables ¶
var AllVariants []Variant = []Variant{ VariantSHA256, VariantSHA512, }
var ErrDigestInvalid = errors.New("hashed token or password is invalid")
ErrDigestInvalid is an error returned when a hash digest has an invalid or unsupported properties. It is NOT returned on token or password mismatches. It is equivalent to go-crypt's algorithm.ErrPasswordInvalid error, but with a message that makes more sense for our usage with tokens.
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) error
RegisterDecoder registers all influxdb2 decoders.
func RegisterDecoderSHA256 ¶
func RegisterDecoderSHA256(r algorithm.DecoderRegister) (err error)
RegisterDecoderSHA256 registers specifically the SHA256 decoder variant with the algorithm.DecoderRegister.
func RegisterDecoderSHA512 ¶
func RegisterDecoderSHA512(r algorithm.DecoderRegister) (err error)
RegisterDecoderSHA512 registers specifically the SHA512 decoder variant with the algorithm.DecoderRegister.
func RegisterDecoderVariant ¶
func RegisterDecoderVariant(r algorithm.DecoderRegister, variant Variant) error
RegisterDecoderVariant registers the specified decoder variant.
Types ¶
type Digest ¶
type Digest struct {
Variant Variant
// contains filtered or unexported fields
}
Digest is an algorithm.Digest which handles influxdb2 matching.
func NewSHA256Digest ¶
NewSHA256Digest creates a new influxdb2.Digest using the SHA256 for the hash.
func (*Digest) Key ¶
Key returns the raw plaintext key which can be used in situations where the plaintext value is required such as validating JWT's signed by HMAC-SHA256.
func (*Digest) Match ¶
Match returns true if the string password matches the current influxdb2.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 influxdb2.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 influxdb2.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 Hasher.Digest that also accepts a salt. The salt is ignored since we can't support salted hashes because we need to lookup the auth record by the token.
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 influxdb2.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 influxdb2.Opt to the influxdb2.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 Parameter ¶
Parameter is a key value pair.
func DecodeParameterStr ¶
DecodeParameterStr is an alias for DecodeParameterStrAdvanced using item separator and key value separator of ',' and '=' respectively.
func DecodeParameterStrAdvanced ¶
DecodeParameterStrAdvanced decodes parameter strings into a []Parameter where sepItem separates each parameter, and sepKV separates the key and value.
type Variant ¶
type Variant int
Variant is a variant of the influxdb2.Digest.
const ( // VariantNone is a variant of the influxdb2.Digest which is unknown. VariantNone Variant = iota // VariantSHA256 is a variant of the influxdb2.Digest which uses SHA256 as the hash. VariantSHA256 // VariantSHA512 is a variant of the influxdb2.Digest which uses SHA512 as the hash. VariantSHA512 )
func NewVariant ¶
NewVariant converts an identifier string to a influxdb2.Variant.
func (Variant) RegisterDecoder ¶
func (v Variant) RegisterDecoder(r algorithm.DecoderRegister) error
RegisterDecoder registers the variant with a decoder.