utils

package
v0.0.0-...-a5ef9a9 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "dev"

Variables

View Source
var (
	// ErrorInvalidJWT is returned when the given JWT is invalid
	ErrorInvalidJWT = NewSealdError("INVALID_JWT", "invalid JWT")
	// ErrorInvalidAuthChallenge is returned when the given authentication challenge is invalid
	ErrorInvalidAuthChallenge = NewSealdError("INVALID_AUTH_CHALLENGE", "invalid auth challenge")
	// ErrorInvalidUUID is returned when a UUID is invalid
	ErrorInvalidUUID = NewSealdError("INVALID_UUID", "invalid UUID")
	// ErrorInvalidUUIDSlice is returned when the given slice of UUID include an invalid UUID
	ErrorInvalidUUIDSlice = NewSealdError("INVALID_UUID_SLICE", "invalid UUID in slice")
	// ErrorNotUnique is returned when items in a slice are not unique.
	ErrorNotUnique = NewSealdError("NOT_UNIQUE", "not unique")
	// ErrorInvalidAuthFactorType is returned when an authentication factor has an invalid type
	ErrorInvalidAuthFactorType     = NewSealdError("INVALID_AUTH_FACTOR_TYPE", "authentication factor type must be 'EM' or 'SMS'")
	ErrorInvalidAuthFactorValueEM  = NewSealdError("INVALID_AUTH_FACTOR_VALUE_EM", "Invalid authentication factor value. It must be a valid email address.")
	ErrorInvalidAuthFactorValueSMS = NewSealdError("INVALID_AUTH_FACTOR_VALUE_SMS", "Invalid authentication factor value. Cannot parse phone number.")
)
View Source
var (
	UUIDRegexp = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)
)

Functions

func B64UUID

func B64UUID(uuid string) (string, error)

func B64toS64

func B64toS64(str string) string

func Base64DecodeString

func Base64DecodeString(s string) ([]byte, error)

Base64DecodeString decodes a Base64-encoded string, handling both padded and non-padded input, as well as new-lines.

func CheckAuthFactor

func CheckAuthFactor(af *common_models.AuthFactor) error

func CheckSliceUnique

func CheckSliceUnique[T comparable](slice []T) error

func CheckUUID

func CheckUUID(uuid string) error

func CheckUUIDSlice

func CheckUUIDSlice(uuids []string) error

func CheckValidAuthChallenge

func CheckValidAuthChallenge(challenge string) error

func CheckValidJWT

func CheckValidJWT(jwt string) error

func ChunkSlice

func ChunkSlice[T any](slice []T, chunkSize int) [][]T

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

func GenerateRandomNonce

func GenerateRandomNonce() (string, error)

func GenerateUserLicenseToken

func GenerateUserLicenseToken(nonce string, userId string, appId string, validationKey string, validationKeyId string) (string, error)

func IsB64UUID

func IsB64UUID(uuid string) bool

func IsEmail

func IsEmail(email string) bool

func IsUUID

func IsUUID(uuid string) bool

func Max

func Max[T constraints.Ordered](a, b T) T

func Min

func Min[T constraints.Ordered](a, b T) T

func NormalizeString

func NormalizeString(s string) []byte

func S64toB64

func S64toB64(str string) string

func SliceIncludes

func SliceIncludes[T comparable](s []T, u T) bool

func SliceMap

func SliceMap[T interface{}, U interface{}](s []T, f func(T) U) []U

func SliceSameMembers

func SliceSameMembers[T comparable](s1 []T, s2 []T) bool

func Ternary

func Ternary[T any](condition bool, valTrue T, valFalse T) T

Ternary is a helper function to inline ternary operations

func UnB64UUID

func UnB64UUID(id string) (string, error)

func UniqueSlice

func UniqueSlice[T comparable](slice []T) []T

Types

type APIError

type APIError struct {
	Status  int
	Url     string
	Method  string
	Code    string
	Id      string
	Details string
	Raw     string
}

func (APIError) Error

func (err APIError) Error() string

func (APIError) Is

func (err APIError) Is(target error) bool

type MutexGroup

type MutexGroup struct {
	// contains filtered or unexported fields
}

func (*MutexGroup) Lock

func (group *MutexGroup) Lock(key string)

func (*MutexGroup) LockAll

func (group *MutexGroup) LockAll()

func (*MutexGroup) LockMultiple

func (group *MutexGroup) LockMultiple(keys []string)

func (*MutexGroup) Unlock

func (group *MutexGroup) Unlock(key string)

func (*MutexGroup) UnlockAll

func (group *MutexGroup) UnlockAll()

func (*MutexGroup) UnlockMultiple

func (group *MutexGroup) UnlockMultiple(keys []string)

type PreValidationToken

type PreValidationToken struct {
	DomainValidationKeyId string `json:"domain_validation_key_id"`
	Nonce                 string `json:"nonce"`
	Token                 string `json:"token"`
}

func GeneratePreValidationToken

func GeneratePreValidationToken(connectorValue string, domainValidationKey string, domainValidationKeyId string) (*PreValidationToken, error)

type SealdError

type SealdError struct {
	Code        string
	Description string
	Details     string
}

func NewSealdError

func NewSealdError(code string, description string) SealdError

func (SealdError) AddDetails

func (err SealdError) AddDetails(details string) SealdError

func (SealdError) Error

func (err SealdError) Error() string

func (SealdError) Is

func (err SealdError) Is(target error) bool

type SerializableError

type SerializableError struct {
	Status      int    `json:"status"`
	Code        string `json:"code"`
	Id          string `json:"id"`
	Description string `json:"description"`
	Details     string `json:"details"`
	Raw         string `json:"raw"`
	Stack       string `json:"stack"`
}

func ToSerializableError

func ToSerializableError(err error) *SerializableError

func (SerializableError) Error

func (e SerializableError) Error() string

type Set

type Set[T comparable] map[T]struct{}

Set implements three methods: Add, Remove & Has. It needs to be defined with a comparable generic type such as int or string. The len operator can be used on Set. Internally a Set represents the presence of an element with a map of struct{}{} for efficiency, as explained here: https://itnext.io/set-in-go-map-bool-and-map-struct-performance-comparison-5315b4b107b.

func (Set[T]) Add

func (s Set[T]) Add(element T)

Add adds the given element to the Set.

func (Set[T]) Has

func (s Set[T]) Has(element T) bool

Has checks if element is in Set, and returns true or false.

func (Set[T]) Remove

func (s Set[T]) Remove(element T)

Remove removes given element from Set. If element is not in Set, Remove is a no-op.

Jump to

Keyboard shortcuts

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