crypto

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlgorithmNotSupported = errors.New("the algorithm is not supported")
	ErrBoundsError           = errors.New("the hash parameters are not within the configured limits")
	ErrInvalidHash           = errors.New("the hash is invalid")
)

Functions

func ParsePrivateJWK

func ParsePrivateJWK(s string) (*rsa.PrivateKey, error)

func ParsePrivatePEMKey

func ParsePrivatePEMKey(s string) (*rsa.PrivateKey, error)

func ParseRSAKey

func ParseRSAKey(s string) (*rsa.PrivateKey, error)

Types

type Argon2LimitsConfig

type Argon2LimitsConfig struct {
	MinTime    uint32
	MaxTime    uint32
	MinMemory  uint32
	MaxMemory  uint32
	MinThreads uint8
	MaxThreads uint8
}

type BcryptLimitsConfig

type BcryptLimitsConfig struct {
	MinCost int
	MaxCost int
}

type Crypter

type Crypter interface {
	Encrypter
	Decrypter
}

type Decrypter

type Decrypter interface {
	Decrypt(string) (string, error)
}

type DecrypterFunc

type DecrypterFunc = func(ctx context.Context, keyID string, algorithm jose.ContentEncryption) (op.Decrypter, error)

type Drupal7LimitsConfig

type Drupal7LimitsConfig struct {
	MinIterations int
	MaxIterations int
}

type Encrypter

type Encrypter interface {
	Encrypt(string) (string, error)
}

type HashConfig

type HashConfig struct {
	Verifiers []HashName
	Hasher    HasherConfig
	Limits    HashLimitsConfig
}

func (*HashConfig) NewHasher

func (c *HashConfig) NewHasher() (*PasswapHasher, error)

type HashLimitsConfig

type HashLimitsConfig struct {
	Bcrypt  BcryptLimitsConfig
	Argon2  Argon2LimitsConfig
	Scrypt  ScryptLimitsConfig
	PBKDF2  PBKDF2LimitsConfig
	Sha2    Sha2LimitsConfig
	PHPass  PHPassLimitsConfig
	Drupal7 Drupal7LimitsConfig
}

type HashMode

type HashMode string
const (
	HashModeSHA1   HashMode = "sha1"
	HashModeSHA224 HashMode = "sha224"
	HashModeSHA256 HashMode = "sha256"
	HashModeSHA384 HashMode = "sha384"
	HashModeSHA512 HashMode = "sha512"
)

HashMode defines a underlying hash.Hash implementation for algorithms like pbkdf2

type HashName

type HashName string
const (
	HashNameArgon2    HashName = "argon2"    // used for the common argon2 verifier
	HashNameArgon2i   HashName = "argon2i"   // hash only
	HashNameArgon2id  HashName = "argon2id"  // hash only
	HashNameBcrypt    HashName = "bcrypt"    // hash and verify
	HashNameMd5       HashName = "md5"       // verify only, as hashing with md5 is insecure and deprecated
	HashNameMd5Plain  HashName = "md5plain"  // verify only, as hashing with md5 is insecure and deprecated
	HashNameMd5Salted HashName = "md5salted" // verify only, as hashing with md5 is insecure and deprecated
	HashNamePHPass    HashName = "phpass"    // verify only, as hashing with md5 is insecure and deprecated
	HashNameSha2      HashName = "sha2"      // hash and verify
	HashNameScrypt    HashName = "scrypt"    // hash and verify
	HashNamePBKDF2    HashName = "pbkdf2"    // hash and verify
	HashNameDrupal7   HashName = "drupal7"   // verify only, Drupal 7 legacy hashes
)

type HashValidator

type HashValidator interface {
	ValidateHash(encoded string) error
}

type HashVerifier

type HashVerifier interface {
	VerifyHash(encoded string, target string) error
}

type Hasher

type Hasher interface {
	Hash(string) (string, error)
}

type HasherConfig

type HasherConfig struct {
	Algorithm HashName
	Params    map[string]any `mapstructure:",remain"`
}

type InverseCrypter

type InverseCrypter struct {
}

InverseCrypter is an implementation of Crypter which can be used for testing purposes. The encrypted value is the bitwise inverse of the original.

func (*InverseCrypter) Decrypt

func (c *InverseCrypter) Decrypt(s string) (string, error)

func (*InverseCrypter) Encrypt

func (c *InverseCrypter) Encrypt(s string) (string, error)

type PBKDF2LimitsConfig

type PBKDF2LimitsConfig struct {
	MinRounds uint32
	MaxRounds uint32
}

type PHPassLimitsConfig

type PHPassLimitsConfig struct {
	MinRounds int
	MaxRounds int
}

type PasswapHasher

type PasswapHasher struct {
	*passwap.Swapper
	Prefixes     []string
	HexSupported bool
}

func (*PasswapHasher) EncodingSupported

func (h *PasswapHasher) EncodingSupported(encodedHash string) bool

func (*PasswapHasher) ValidateHash

func (h *PasswapHasher) ValidateHash(encoded string) error

ValidateHash checks that encoded is parseable by a configured verifier and that its cost parameters are within configured bounds. Use when accepting pre-encoded hashes from untrusted sources (import, create with hash).

func (*PasswapHasher) VerifyHash

func (h *PasswapHasher) VerifyHash(encoded string, target string) error

type ScryptLimitsConfig

type ScryptLimitsConfig struct {
	MinLN int
	MaxLN int
	MinR  int
	MaxR  int
	MinP  int
	MaxP  int
}

type Sha2LimitsConfig

type Sha2LimitsConfig struct {
	MinSha256Rounds int
	MaxSha256Rounds int
	MinSha512Rounds int
	MaxSha512Rounds int
}

Directories

Path Synopsis
Package cryptomock is a generated GoMock package.
Package cryptomock is a generated GoMock package.

Jump to

Keyboard shortcuts

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