Documentation ¶
Overview ¶
Package datautil contains general data handling objects and helper methods.
Package datautil contains general data handling objects and helper methods.
Index ¶
- Variables
- func CheckForDictPassword(password string) (bool, string, int)
- func CheckNonce(nonce string) error
- func ConsumeNonce(nonce string) error
- func CopyObject(src interface{}, dest interface{}) error
- func GetNestedValue(d map[string]interface{}, path []string) (interface{}, error)
- func MergeMaps(maps ...map[string]interface{}) map[string]interface{}
- func NewNonce() string
- type EnforcedUserDB
- func (eud *EnforcedUserDB) AddUserEntry(name, password string, data map[string]interface{}) error
- func (eud *EnforcedUserDB) EvalPasswordStrength(user, password string) (int, []string, error)
- func (eud *EnforcedUserDB) IsAcceptablePassword(user, password string) error
- func (eud *EnforcedUserDB) PasswordCheckParams() map[string]bool
- func (eud *EnforcedUserDB) SetPasswordCheckParam(key string, value bool)
- func (eud *EnforcedUserDB) UpdateUserPassword(name, password string) error
- type MapCache
- type PersistentMap
- type PersistentStringMap
- type RingBuffer
- func (rb *RingBuffer) Add(e interface{})
- func (rb *RingBuffer) Get(p int) interface{}
- func (rb *RingBuffer) IsEmpty() bool
- func (rb *RingBuffer) Log(v ...interface{})
- func (rb *RingBuffer) Poll() interface{}
- func (rb *RingBuffer) Reset()
- func (rb *RingBuffer) Size() int
- func (rb *RingBuffer) Slice() []interface{}
- func (rb *RingBuffer) String() string
- func (rb *RingBuffer) StringSlice() []string
- type UserDB
- func (ud *UserDB) AddUserEntry(name, password string, data map[string]interface{}) error
- func (ud *UserDB) AllUsers() []string
- func (ud *UserDB) CheckUserPassword(name string, password string) bool
- func (ud *UserDB) CheckUserPasswordHistory(name string, password string) bool
- func (ud *UserDB) RemoveUserEntry(name string) error
- func (ud *UserDB) UpdateUserData(name string, data map[string]interface{}) error
- func (ud *UserDB) UpdateUserPassword(name, password string) error
- func (ud *UserDB) UserData(name string) (map[string]interface{}, bool)
- func (ud *UserDB) UserExists(name string) bool
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvlaidNonce = errors.New("Invalid nonce value")
)
Default nonce related errors
var GoodPasswordLength = 12
GoodPasswordLength is a good password length
var MaxNonceLifetime int64 = 3600 // One hour
MaxNonceLifetime is the maximum lifetime for nonces in seconds.
var MaxPassHistory = 10
MaxPassHistory is the amount of password history which is kept
var MinPasswordLength = 8
MinPasswordLength is the minimal password length if strong passwords are enforced
var UserDBFilePerms os.FileMode = 0600
UserDBFilePerms are the file permissions used for the database file
Functions ¶
func CheckForDictPassword ¶
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 ¶
CheckNonce checks if a given nonce is valid. The nonce is still valid after this operation.
func ConsumeNonce ¶
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 ¶
GetNestedValue gets a value from a nested object structure.
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 ¶
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.
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) 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 (*UserDB) AddUserEntry ¶
AddUserEntry adds a new user entry.
func (*UserDB) CheckUserPassword ¶
CheckUserPassword checks a given user password.
func (*UserDB) CheckUserPasswordHistory ¶
CheckUserPasswordHistory checks if a given password is part of the password history.
func (*UserDB) RemoveUserEntry ¶
RemoveUserEntry removes an existing user entry.
func (*UserDB) UpdateUserData ¶
UpdateUserData updates the data of a user entry.
func (*UserDB) UpdateUserPassword ¶
UpdateUserPassword updates the password of a user entry.
func (*UserDB) UserExists ¶
UserExists checks if a user exists.