influxdb2

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package influxb2 implements github.com/go-crypt/crypt interfaces with variants of InfluxDB 2.x token hashing.

Index

Constants

View Source
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"
)
View Source
const (
	// ParameterDefaultItemSeparator is the default item separator.
	ParameterDefaultItemSeparator = ","

	// ParameterDefaultKeyValueSeparator is the default key value separator.
	ParameterDefaultKeyValueSeparator = "="
)
View Source
const DefaultVariant = VariantSHA256

Variables

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

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) 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

func NewSHA256Digest(password string) (digest Digest)

NewSHA256Digest creates a new influxdb2.Digest using the SHA256 for the hash.

func (*Digest) Encode

func (d *Digest) Encode() string

Encode returns the encoded form of this plaintext.Digest.

func (*Digest) Key

func (d *Digest) Key() []byte

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

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

Match returns true if the string password matches the current influxdb2.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) bool

MatchBytes returns true if the []byte passwordBytes matches the current influxdb2.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 influxdb2.New using a functional options pattern.

func New

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

New returns a *hasher.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, salt []byte) (hashed algorithm.Digest, err error)

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

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 influxdb2.Hasher is going to be reused and you should use it in conjunction with MustHash.

func (*Hasher) Variant

func (h *Hasher) Variant() Variant

Variant returns which variant this hasher implements.

func (*Hasher) WithOptions

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

WithOptions applies the provided functional options provided as an influxdb2.Opt to the influxdb2.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 Parameter

type Parameter struct {
	Key   string
	Value string
}

Parameter is a key value pair.

func DecodeParameterStr

func DecodeParameterStr(input string) (opts []Parameter, err error)

DecodeParameterStr is an alias for DecodeParameterStrAdvanced using item separator and key value separator of ',' and '=' respectively.

func DecodeParameterStrAdvanced

func DecodeParameterStrAdvanced(input string, sepItem, sepKV string) (opts []Parameter, err error)

DecodeParameterStrAdvanced decodes parameter strings into a []Parameter where sepItem separates each parameter, and sepKV separates the key and value.

func (Parameter) Int

func (p Parameter) Int() (int, error)

Int converts the Value to an int using strconv.Atoi.

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

func NewVariant(identifier string) (variant Variant)

NewVariant converts an identifier string to a influxdb2.Variant.

func (Variant) Decode

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

Decode performs the decode operation for this influxdb2.Variant.

func (Variant) Encode

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

Encode performs the encode operation for this influxdb2.Variant.

func (Variant) Hash

func (v Variant) Hash(input []byte) []byte

Hash performs the hashing operation on the input, returning the raw binary.

func (Variant) Prefix

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

Prefix returns the influxdb2.Variant prefix identifier.

func (Variant) RegisterDecoder

func (v Variant) RegisterDecoder(r algorithm.DecoderRegister) error

RegisterDecoder registers the variant with a decoder.

Jump to

Keyboard shortcuts

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