util

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DocFolderName = "/documents"
	SaltLength    = 32
)

Variables

View Source
var (
	Docker    bool
	Debug     bool
	Host      string
	Port      int
	DocFolder string
)

Functions

func ClearFilename

func ClearFilename(filename string) string

Removes spaces and converts filename to lowercase

func DecryptData

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

Decrypts data with the given key using AES-256-GCM

func DeriveKey

func DeriveKey(pass, salt []byte) []byte

Derives a key from the password and salt using Argon2id, retrieves from the cache if already did before

func EncryptData

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

Encrypts data with the given key using AES-256-GCM

func Env

func Env(name string, def string) string

func EnvBool

func EnvBool(env string) bool

func EnvInt

func EnvInt[V Integer](env string, def V) V

func HandleError

func HandleError(err error, message string)

If err is not nil and message is not empty, prints the message. If message is empty, prints the error

func IfThenElse

func IfThenElse[V any](cond bool, a, b V) V

Returns the first argument if the condition is true, the second if false.

Original from https://github.com/shomali11/util/blob/f0771b70947f1d04b0e6826d333ab3ed295b05a0/xconditions/xconditions.go#L12. Modified for generics

func Init

func Init()

func NewSalt

func NewSalt() ([]byte, error)

Generates a random salt

Types

type Cache

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

cache is a thread-safe map of keys to passwords.

The idea was to have something that is strongly typed compared to sync.Map

func NewCache

func NewCache() *Cache

func (*Cache) Load

func (c *Cache) Load(pass []byte) (key []byte, ok bool)

Loads a key from the cache, returns (nil, false) if not found

func (*Cache) Store

func (c *Cache) Store(pass, key []byte)

Stores a key in the cache with the hex of pass as key

type Float

type Float interface {
	~float32 | ~float64
}

type Integer

type Integer interface {
	Signed | Unsigned
}

type Number

type Number interface {
	Integer | Float
}

type Ordered

type Ordered interface {
	Number | Float | ~string
}

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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