datautil

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: CC0-1.0 Imports: 24 Imported by: 18

Documentation

Overview

Package datautil contains general data handling objects and helper methods.

Package datautil contains general data handling objects and helper methods.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvlaidNonce = errors.New("Invalid nonce value")
)

Default nonce related errors

View Source
var GoodPasswordLength = 12

GoodPasswordLength is a good password length

View Source
var MaxNonceLifetime int64 = 3600 // One hour

MaxNonceLifetime is the maximum lifetime for nonces in seconds.

View Source
var MaxPassHistory = 10

MaxPassHistory is the amount of password history which is kept

View Source
var MinPasswordLength = 8

MinPasswordLength is the minimal password length if strong passwords are enforced

View Source
var UserDBFilePerms os.FileMode = 0600

UserDBFilePerms are the file permissions used for the database file

Functions

func CheckForDictPassword

func CheckForDictPassword(password string) (bool, string, int)

CheckForDictPassword checks if the given password is a common password. Returns if the given password is a direct match, the closest match in the dictionary and how close it is expressed as Levenshtein distance. If the distance is -1 then the given password is not common.

func CheckNonce

func CheckNonce(nonce string) error

CheckNonce checks if a given nonce is valid. The nonce is still valid after this operation.

func ConsumeNonce

func ConsumeNonce(nonce string) error

ConsumeNonce consumes a given nonce. The nonce will no longer be valid after this operation.

func CopyObject

func CopyObject(src interface{}, dest interface{}) error

CopyObject copies contents of a given object reference to another given object reference.

func GetNestedValue

func GetNestedValue(d map[string]interface{}, path []string) (interface{}, error)

GetNestedValue gets a value from a nested object structure.

func MergeMaps

func MergeMaps(maps ...map[string]interface{}) map[string]interface{}

MergeMaps merges all given maps into a new map. Contents are shallow copies and conflicts are resolved as last-one-wins.

func NewNonce

func NewNonce() string

NewNonce generates a new nonce value. The nonce is invalidated either after it was consumed or automatically after MaxNonceLifetime seconds.

Types

type EnforcedUserDB

type EnforcedUserDB struct {
	*UserDB
	// contains filtered or unexported fields
}

EnforcedUserDB is a UserDB in which a high password strength is enforced.

func NewEnforcedUserDB

func NewEnforcedUserDB(filename string, passphrase string) (*EnforcedUserDB, error)

NewEnforcedUserDB creates a new user database object.

func (*EnforcedUserDB) AddUserEntry

func (eud *EnforcedUserDB) AddUserEntry(name, password string, data map[string]interface{}) error

AddUserEntry adds a new user entry.

func (*EnforcedUserDB) EvalPasswordStrength

func (eud *EnforcedUserDB) EvalPasswordStrength(user, password string) (int, []string, error)

EvalPasswordStrength evaluates the strength of a password and returns a number from 0 to 10. Returns an overall scope a list of warnings and an error (CompositeError) if the password is not acceptable.

func (*EnforcedUserDB) IsAcceptablePassword

func (eud *EnforcedUserDB) IsAcceptablePassword(user, password string) error

IsAcceptablePassword checks if a given user password is acceptable.

func (*EnforcedUserDB) PasswordCheckParams

func (eud *EnforcedUserDB) PasswordCheckParams() map[string]bool

PasswordCheckParams returns the current password check configuration.

func (*EnforcedUserDB) SetPasswordCheckParam

func (eud *EnforcedUserDB) SetPasswordCheckParam(key string, value bool)

SetPasswordCheckParam sets a parameter of the password check configuration.

func (*EnforcedUserDB) UpdateUserPassword

func (eud *EnforcedUserDB) UpdateUserPassword(name, password string) error

UpdateUserPassword updates the password of a user entry.

type MapCache

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

MapCache is a map based cache object storing string->interface{}. It is possible to specify a maximum size, which when reached causes the oldest entries to be removed. It is also possible to set an expiry time for values. Values which are old are purged on the next access to the object.

func NewMapCache

func NewMapCache(maxsize uint64, maxage int64) *MapCache

NewMapCache creates a new MapCache object. The calling function can specify the maximum size and the maximum age in seconds for entries. A value of 0 means no size constraint and no age constraint.

func (*MapCache) Clear

func (mc *MapCache) Clear()

Clear removes all entries.

func (*MapCache) Get

func (mc *MapCache) Get(k string) (interface{}, bool)

Get retrieves an item from the MapCache.

func (*MapCache) GetAll

func (mc *MapCache) GetAll() map[string]interface{}

GetAll retrieves all items from the MapCache.

func (*MapCache) Put

func (mc *MapCache) Put(k string, v interface{})

Put stores an item in the MapCache.

func (*MapCache) Remove

func (mc *MapCache) Remove(k string) bool

Remove removes an item in the MapCache.

func (*MapCache) Size

func (mc *MapCache) Size() uint64

Size returns the current size of the MapCache.

func (*MapCache) String

func (mc *MapCache) String() string

String returns a string representation of this MapCache.

type PersistentMap

type PersistentMap struct {
	Data map[string]interface{} // Data of the persistent map
	// contains filtered or unexported fields
}

PersistentMap is a persistent map storing string values. This implementation returns more encoding / decoding errors since not all possible values are supported.

func LoadPersistentMap

func LoadPersistentMap(filename string) (*PersistentMap, error)

LoadPersistentMap loads a persistent map from a file.

func NewPersistentMap

func NewPersistentMap(filename string) (*PersistentMap, error)

NewPersistentMap creates a new persistent map.

func (*PersistentMap) Flush

func (pm *PersistentMap) Flush() error

Flush writes contents of the persistent map to the disk.

type PersistentStringMap

type PersistentStringMap struct {
	Data map[string]string // Data of the persistent map
	// contains filtered or unexported fields
}

PersistentStringMap is a persistent map storing string values.

func LoadPersistentStringMap

func LoadPersistentStringMap(filename string) (*PersistentStringMap, error)

LoadPersistentStringMap loads a persistent map from a file.

func NewPersistentStringMap

func NewPersistentStringMap(filename string) (*PersistentStringMap, error)

NewPersistentStringMap creates a new persistent map.

func (*PersistentStringMap) Flush

func (pm *PersistentStringMap) Flush() error

Flush writes contents of the persistent map to the disk.

type RingBuffer

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

RingBuffer is a classic thread-safe ringbuffer implementation. It stores abstract interface{} objects. It has specific methods so it can be used as a print logger.

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

NewRingBuffer creates a new ringbuffer with a given size.

func (*RingBuffer) Add

func (rb *RingBuffer) Add(e interface{})

Add adds an item to the ringbuffer.

func (*RingBuffer) Get

func (rb *RingBuffer) Get(p int) interface{}

Get returns an element of the ringbuffer from a given position.

func (*RingBuffer) IsEmpty

func (rb *RingBuffer) IsEmpty() bool

IsEmpty returns if this ringbuffer is empty.

func (*RingBuffer) Log

func (rb *RingBuffer) Log(v ...interface{})

Log writes the given arguments as strings into the ring buffer. Each line is a separate item.

func (*RingBuffer) Poll

func (rb *RingBuffer) Poll() interface{}

Poll removes and returns the head of the ringbuffer.

func (*RingBuffer) Reset

func (rb *RingBuffer) Reset()

Reset removes all content from the ringbuffer.

func (*RingBuffer) Size

func (rb *RingBuffer) Size() int

Size returns the size of the ringbuffer.

func (*RingBuffer) Slice

func (rb *RingBuffer) Slice() []interface{}

Slice returns the contents of the buffer as a slice.

func (*RingBuffer) String

func (rb *RingBuffer) String() string

String retusn the contents of the buffer as a string. Each item of the buffer is treated as a separate line.

func (*RingBuffer) StringSlice

func (rb *RingBuffer) StringSlice() []string

StringSlice returns the contents of the buffer as a slice of strings. Each item of the buffer is a separate string.

type UserDB

type UserDB struct {
	Data     map[string]*userDBEntry // Data of the persistent map
	DataLock *sync.RWMutex           // Lock for data
	// contains filtered or unexported fields
}

UserDB is a thread-safe user database which is stored in an encrypted file. User passwords are hashed with an individual salt.

func NewUserDB

func NewUserDB(filename string, passphrase string) (*UserDB, error)

NewUserDB creates a new user database object.

func (*UserDB) AddUserEntry

func (ud *UserDB) AddUserEntry(name, password string, data map[string]interface{}) error

AddUserEntry adds a new user entry.

func (*UserDB) AllUsers

func (ud *UserDB) AllUsers() []string

AllUsers returns a list of all known users.

func (*UserDB) CheckUserPassword

func (ud *UserDB) CheckUserPassword(name string, password string) bool

CheckUserPassword checks a given user password.

func (*UserDB) CheckUserPasswordHistory

func (ud *UserDB) CheckUserPasswordHistory(name string, password string) bool

CheckUserPasswordHistory checks if a given password is part of the password history.

func (*UserDB) RemoveUserEntry

func (ud *UserDB) RemoveUserEntry(name string) error

RemoveUserEntry removes an existing user entry.

func (*UserDB) UpdateUserData

func (ud *UserDB) UpdateUserData(name string, data map[string]interface{}) error

UpdateUserData updates the data of a user entry.

func (*UserDB) UpdateUserPassword

func (ud *UserDB) UpdateUserPassword(name, password string) error

UpdateUserPassword updates the password of a user entry.

func (*UserDB) UserData

func (ud *UserDB) UserData(name string) (map[string]interface{}, bool)

UserData returns the user data for a given user.

func (*UserDB) UserExists

func (ud *UserDB) UserExists(name string) bool

UserExists checks if a user exists.

Jump to

Keyboard shortcuts

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