secret

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedToBaseDecode = credstackError.NewError(500, "FAILED_TO_BASE_DECODE", "user: failed to decode base64 data during user credential validation")

ErrFailedToBaseDecode - Provides a named error for when base64 decoding data fails during a user credential validation

Functions

func DecodeBase64

func DecodeBase64(data []byte, length uint32) ([]byte, error)

DecodeBase64 - Decodes base64 data passed in the data parameter. A length is provided here to enforce specific size requirements in the event that they are required.

Any errors propagated here are returned in the form of the named error: ErrFailedToBaseDecode. This error is wrapped, so if you need to access the underlying error you can use errors.Unwrap

func EncodeBase64

func EncodeBase64(data []byte) string

EncodeBase64 - Encodes any data passed into the data parameter to a URL-Safe Base64 Encoded byte array

func GenerateUUID

func GenerateUUID(basis string) string

GenerateUUID - Generates a basic version 5 UUID to use in the header.Identifier field. The basis that is passed in the parameter here is hashed along with the UUID namespace URL and a new UUID is generated from it. Using a basis for this generation provides an additional layer of protection against duplication as if the same basis is used, then the same UUID is generated

func NewArgon2Hash

func NewArgon2Hash(secret []byte, opts *options.CredentialOptions) ([]byte, []byte, error)

NewArgon2Hash - Generates a ArgonV2ID hash for the secret provided in the first parameter. Any options that are provided here for hashing should be persisted using the user.UserCredential model as this ensures the same ones can be used when you need to validate the hash

Unlike other functions implemented in this library, the opts parameter is forced. This is done to ensure that the caller is fully aware of the parameters that they are passing to this function.

func RandBytes

func RandBytes(length uint32) ([]byte, error)

RandBytes - A function for generating cryptographically secure, random byte arrays of a fixed size. Most commonly used for generating Argon2 hashes, or secured version 5 UUIDs. The error returned from this function can be safely ignored as it is passed directly from rand.Read

func RandString

func RandString(length uint32) (string, error)

RandString - Generates a base64 encoded string that was generated with a cryptographically secure byte array. This is primarily used for client ID generation for the application struct, but can be used in other situations

func ValidateArgon2Hash

func ValidateArgon2Hash(secret []byte, salt []byte, target []byte, opts *options.CredentialOptions) bool

ValidateArgon2Hash - Validates that the hashed result of 'secret' matches the hash provided in 'target'. The secret parameter should be a raw, non-encoded secret provided by the user. The salt parameter should be the salt that both hashes share, and the target parameter should be an Argon2 hashed secret. The salt is required here as it ensures that we can adequately hash the result. Any options provided with opts, should reflect what is stored in the user.UserCredential structure.

A returned value of true indicates that the hashes match, any other result indicates that they do not

Types

This section is empty.

Jump to

Keyboard shortcuts

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