utils

package
v0.0.0-...-ee7fb9c Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthFirstFactor    string = "auth_first_factor"
	AuthSecondFactor   string = "auth_second_factor"
	CreateAccount      string = "create_account"
	LogoutAccount      string = "logout_account"
	TestAuthReq        string = "test_auth_req"
	RetrieveUser       string = "retrieve_user"
	VerifyEmailTry     string = "verify_email_try"
	VerifyEmailConfirm string = "verify_email_confirm"
	VerifyPhoneTry     string = "verify_phone_try"
	VerifyPhoneConfirm string = "verify_phone_confirm"

	// vaults
	CreateUser    string = "create_user"
	CreateVault   string = "create_vault"
	CreateEntry   string = "create_entry"
	CreateSecret  string = "create_secret"
	ListVaults    string = "list_vaults"
	RetrieveVault string = "retrieve_vault"
	RetrieveEntry string = "retrieve_entry"
	UpdateVault   string = "update_vault"
	UpdateEntry   string = "update_entry"
	UpdateSecret  string = "update_secret"
	MoveSecret    string = "move_secret"
	DeleteVault   string = "delete_vault"
	DeleteEntry   string = "delete_entry"
	DeleteSecret  string = "delete_secret"
)
View Source
const (
	ErrorBadRequest   string = "Bad request."
	ErrorToken        string = "Invalid token."
	ErrorMFAToken     string = "Invalid MFA token."
	ErrorPhoneOTP     string = "Invalid phone OTP."
	ErrorServer       string = "Oops, something went wrong!"
	ErrorDiffEmail    string = "Oops, failed to create account - try using a different email address or phone number."
	ErrorFailedLogin  string = "Oops, failed to log in - try again!"
	ErrorAuthenticate string = "Oops, failed to authenticate - try again!"
)
View Source
const (
	ErrorClientOperation     string = "Non-matching client operation header."
	ErrorParse               string = "Failed to parse request body."
	ErrorAcctName            string = "Invalid `name`."
	ErrorAcctEmail           string = "Invalid `email`."
	ErrorAcctPW              string = "Invalid `password`."
	ErrorAcctPhone           string = "Invalid `phone_number`."
	ErrorNonMatchPW          string = "Non-matching password inputs."
	ErrorCreateUser          string = "Failed create user transaction."
	ErrorVaultsCreateUser    string = "Failed vaults API create_user."
	ErrorVaultsCreateVault   string = "Failed vaults API create_vault."
	ErrorVaultsListVaults    string = "Failed vaults API list_vaults."
	ErrorVaultsRetrieveVault string = "Failed vaults API retrieve_vault."
	ErrorVaultsUpdateVault   string = "Failed vaults API update_vault."
	ErrorVaultsDeleteVault   string = "Failed vaults API delete_vault."
	ErrorVaultsCreateEntry   string = "Failed vaults API create_entry."
	ErrorVaultsRetrieveEntry string = "Failed vaults API retrieve_entry."
	ErrorVaultsUpdateEntry   string = "Failed vaults API update_entry."
	ErrorVaultsDeleteEntry   string = "Failed vaults API delete_entry."
	ErrorVaultsCreateSecret  string = "Failed vaults API create_secret."
	ErrorVaultsUpdateSecret  string = "Failed vaults API update_secret."
	ErrorVaultsMoveSecret    string = "Failed vaults API move_secret."
	ErrorVaultsDeleteSecret  string = "Failed vaults API delete_secret."
	ErrorVaultsDeleteUser    string = "Failed vaults API delete_user."
	ErrorFailedDB            string = "Failed DB operation."
	ErrorNoRowsAffected      string = "result.RowsAffected == 0"
	ErrorIPMismatch          string = "Different IP addresses."
	ErrorBadClient           string = "Client did something it shouldn't have."
	ErrorParams              string = "Invalid URL parameters."
	ErrorUserContext         string = "Invalid user context."
	ErrorAlreadyVerified     string = "User already verified"
)
View Source
const DIGITS string = "0123456789"
View Source
const LOWERCASE_LETTERS string = "abcdefghijklmnopqrstuvwxyz"
View Source
const PASSWORD_ALPHABET = OTP_ALPHABET + SPECIAL_CHARS
View Source
const SLUG_ALPHABET = OTP_ALPHABET + "_-"
View Source
const SPECIAL_CHARS string = "`~!@#$%^&*()-=_+,./<>?;':\"[]\\{}|"
View Source
const UPPERCASE_LETTERS string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Variables

View Source
var (
	EmailRegexp            = regexp.MustCompile("^[\u00BF-\u1FFF\u2C00-\uD7FF\\w\\.\\+\\-]+@[\u00BF-\u1FFF\u2C00-\uD7FF\\w\\-]+(\\.[\u00BF-\u1FFF\u2C00-\uD7FF\\w\\-]+)+$")
	NameRegexp             = regexp.MustCompile(`^[\\u00BF-\\u1FFF\\u2C00-\\uD7FF\w \-\,\.\']{1,50}$`)
	PhoneRegexp            = regexp.MustCompile(`^\+[1-9]\d{1,14}$`)
	HexEncodedKeyRegexp    = regexp.MustCompile(`^[A-Fa-f0-9]{64}$`)
	SlugRegexp             = regexp.MustCompile(`^[\w-]{16}$`)
	TokenRegexp            = regexp.MustCompile(`^[\w-]{80}$`)
	RowsRegexp             = regexp.MustCompile(`^result.RowsAffected \([0-9]+\) > 1$`)
	AuthHeaderRegexp       = regexp.MustCompile(`^[Tt]oken [\w-]{80}$`)
	TokenNullRegexp        = regexp.MustCompile(`^[Tt]oken (null)?$`)
	UniqueConstraintRegexp = regexp.MustCompile(`(UNIQUE constraint failed: users\.(email_address|phone_number)|ERROR: duplicate key value violates unique constraint "users_(email_address|phone_number)_key")`)
)

Functions

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword, password, salt []byte) bool

func ContainsLowercase

func ContainsLowercase(s string) bool

func ContainsNumber

func ContainsNumber(s string) bool

func ContainsSpecialChar

func ContainsSpecialChar(s string) bool

func ContainsUppercase

func ContainsUppercase(s string) bool

func ContainsWhitespace

func ContainsWhitespace(s string) bool

func GenerateOTP

func GenerateOTP() ([]string, error)

func GeneratePassword

func GeneratePassword(n int) (string, error)

func GenerateSalt

func GenerateSalt(n int) (salt []byte, err error)

func GenerateSlug

func GenerateSlug(n int) (string, error)

func GenerateUserCredentials

func GenerateUserCredentials(password []byte) (hash, salt []byte, err error)

func HashToken

func HashToken(token string) []byte

func HideEmail

func HideEmail(email string) string

func HidePhone

func HidePhone(phone string) string

func RespondWithError

func RespondWithError(
	c *fiber.Ctx, statusCode int, detail string, fieldErrors map[string][]string,
	nonFieldErrors []string,
) error

Types

type ErrorResponseBody

type ErrorResponseBody struct {
	Detail         string              `json:"detail"`
	FieldErrors    map[string][]string `json:"field_errors"`
	NonFieldErrors []string            `json:"non_field_errors"`
}

type VaultsErrorResponseBody

type VaultsErrorResponseBody struct {
	ClientOperation string `json:"client_operation"`
	Message         string `json:"message"`
	ContextString   string `json:"context_string"`
	RequestBody     string `json:"request_body"`
	Detail          string `json:"detail"`
}

Jump to

Keyboard shortcuts

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