util

package
v0.0.0-...-ef7a112 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Argon2SaltSize represents the recommended salt size for argon2, which is 16 bytes
	// https://tools.ietf.org/id/draft-irtf-cfrg-argon2-05.html#rfc.section.3.1
	Argon2SaltSize = 16
)

Variables

This section is empty.

Functions

func Argon2KeyGen

func Argon2KeyGen(password string, salt []byte, keyLen int) ([]byte, error)

Argon2KeyGen returns an encoded string generation of a key generated using the go crypto argon2 impl specifically, the Argon2id version, a "hybrid version of Argon2 combining Argon2i and Argon2d."

func FirstNonErrorWithValue

func FirstNonErrorWithValue[T any](ctx context.Context, autoCancel bool, returnOnError func(error) bool, runs ...func(context.Context) (T, error)) (T, error)

func FromPointer

func FromPointer[T comparable](s *T) T

FromPointer returns the value of a pointer, or the zero value of the pointer's type if the pointer is nil.

func FromPointerSlice

func FromPointerSlice[T any](s []*T) []T

func GenerateSalt

func GenerateSalt(size int) ([]byte, error)

GenerateSalt generates a random salt value for a given size

func GetKeyIDFromJWT

func GetKeyIDFromJWT(token keyaccess.JWT) (string, error)

func GetMethodForDID

func GetMethodForDID(did string) (didsdk.Method, error)

GetMethodForDID gets a DID method from a did, the second part of the did (e.g. did:test:abcd, the method is 'test')

func Is2xxResponse

func Is2xxResponse(statusCode int) bool

Is2xxResponse returns true if the given status code is a 2xx response

func IsEmpty

func IsEmpty[T any](s *T) bool

func IsShutdown

func IsShutdown(err error) bool

IsShutdown checks to see if the shutdown error is contained in the specified error value.

func IsStructPtr

func IsStructPtr(obj any) bool

IsStructPtr checks if the given object is a pointer to a struct

func NewShutdownError

func NewShutdownError(message string) error

NewShutdownError returns an error that causes the framework to signal. a graceful shutdown

func ParseJWT

func ParseJWT(token keyaccess.JWT) (*jws.Signature, jwt.Token, error)

ParseJWT parses a JWT token and returns the jws signature and jwt claims

func SanitizeLog

func SanitizeLog(log string) string

SanitizeLog prevents certain classes of injection attacks before logging https://codeql.github.com/codeql-query-help/go/go-log-injection/

func ToPointer

func ToPointer[T any](s T) *T

func ToPointerSlice

func ToPointerSlice[T any](s []T) []*T

func XChaCha20Poly1305Decrypt

func XChaCha20Poly1305Decrypt(key, data []byte) ([]byte, error)

XChaCha20Poly1305Decrypt takes a 32 byte key and uses XChaCha20-Poly1305 to decrypt a piece of data

func XChaCha20Poly1305Encrypt

func XChaCha20Poly1305Encrypt(key, data []byte) ([]byte, error)

XChaCha20Poly1305Encrypt takes a 32 byte key and uses XChaCha20-Poly1305 to encrypt a piece of data

Types

type ErrHTTP

type ErrHTTP struct {
	Err        error
	StatusCode int
	URL        string
}

ErrHTTP represents an error returned from an HTTP request

func (ErrHTTP) Error

func (h ErrHTTP) Error() string

func (ErrHTTP) Unwrap

func (h ErrHTTP) Unwrap() error

type ErrorResponse

type ErrorResponse struct {
	Error  string `json:"error"`
	Fields string `json:"fields,omitempty"`
}

ErrorResponse is the structure of response error payloads sent back to the requester when validation of a request payload fails.

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Error string `json:"error"`
}

FieldError is used to indicate an error with a field in a request payload.

type SafeError

type SafeError struct {
	Err        error
	StatusCode int
	Fields     []FieldError
}

SafeError is used to pass an error during the request through the server with web specific context. 'Safe' here means that the error messages do not include any sensitive information and can be sent straight back to the requester

func (*SafeError) Error

func (err *SafeError) Error() string

SafeError implements the `error` interface. It uses the default message of the wrapped error. This is what will be shown in a server's logs

func (*SafeError) FieldErrors

func (err *SafeError) FieldErrors() string

FieldErrors returns a string containing all field errors.

Jump to

Keyboard shortcuts

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