lib

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MasterKeyEnv = "MASTER_KEY"
)

Variables

View Source
var (
	ErrInvalidHash         = errors.New("the encoded hash is in an invalid format")
	ErrIncompatibleVersion = errors.New("the encoded hash is using an incompatible version of Argon2")
	ErrInvalidPassword     = errors.New("the password is invalid")
)
View Source
var ErrInvalidSecret = errors.New("invalid secret")
View Source
var ErrNoMasterKey = errors.New("missing master key")
View Source
var ScryptParamsDefault = ScryptParams{
	SaltLength:  32,
	Iterations:  1,
	Memory:      64 * 1024,
	Parallelism: 4,
	KeyLength:   32,
}
View Source
var URLCharList = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

URLCharList is a list of URL-valid characters, for generating random strings.

Functions

func CompareScrypt

func CompareScrypt(password, encodedHash string) error

CompareScrypt compares a password with an encoded hash generated by GenerateScrypt. It returns true if the password matches the hash, and false otherwise.

This method is similar to bcrypt.CompareHashAndPassword, but based on the newer Argon2 algorithm.

func ConsumeDAOKey

func ConsumeDAOKey(ctx context.Context, key *dao.KeyEntity, private bool) (*jwa.JWK, error)

ConsumeDAOKey converts a key from DAO entity to aJWK object.

func DecryptMasterKey

func DecryptMasterKey(ctx context.Context, data []byte, output any) error

DecryptMasterKey decrypts the input using the master key.

func EncryptMasterKey

func EncryptMasterKey(ctx context.Context, data any) ([]byte, error)

EncryptMasterKey encrypts the input using the master key.

func GenerateScrypt

func GenerateScrypt(password string, params ScryptParams) (string, error)

GenerateScrypt is a secure hash method, similar to bcrypt.GenerateFromPassword, but based on the newer Argon2 algorithm.

func MasterKeyContext

func MasterKeyContext(ctx context.Context) ([32]byte, error)

func NewAgoraContext

func NewAgoraContext(parentCTX context.Context) (context.Context, error)

func NewMasterKeyContext

func NewMasterKeyContext(ctx context.Context) (context.Context, error)

func NewRandomURLString

func NewRandomURLString(length int) (string, error)

func SendMail

func SendMail(ctx context.Context, message *mail.SGMailV3)

Types

type ScryptParams

type ScryptParams struct {
	// SaltLength is the length of the salt in bytes.
	SaltLength uint
	// Iterations is the number of iterations to use.
	Iterations uint32
	// Memory is the amount of memory used by the algorithm.
	Memory uint32
	// Parallelism is the number of threads to use.
	Parallelism uint8
	// KeyLength is the length of the derived key.
	KeyLength uint32
}

ScryptParams contains the parameters used to generate a hash using the Argon2 algorithm.

You can use ScryptParamsDefault unless you have specific requirements.

Jump to

Keyboard shortcuts

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