common

package module
v0.0.0-...-aa52af0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

README

The Common package

This package provides common web-related shortcuts, solutions and algorithms.

Name Link/Badge
Docs GoDoc
Our Jira Jira
We have #gramework channel in the Gophers Slack https://gophers.slack.com
Our Telegram chat @gramework
Our Discord Server https://discord.gg/HkW8DsD

Documentation

Overview

Package common provides common web-related shortcuts, solutions and algorithms

Index

Constants

View Source
const (
	// TOTPLengthShort is the default TOTP password length.
	TOTPLengthShort = 6
	// TOTPLengthLong is the strongest length, but it will *NOT* work with Google Authenticator
	TOTPLengthLong = 8
)

Variables

View Source
var ErrCouldNotScan = errors.New("gramework/common: could not scan value")

Functions

func CalcMTA

func CalcMTA(samplesCount uint64, latestAvg time.Duration, nextSample time.Duration) time.Duration

CalcMTA calculates Moving Time Average

samplesCount should not count the nextSample. given that, when initializing MTA, you should pass 0, not 1; and when calling 2nd time, you should pass 1, not 2.

Warning: this MTA will return approx. value and not the exact one. This is what we paid so we're not storing all values.

func GenerateKey

func GenerateKey() (b []byte, err error)

GenerateKey generates a private key using random source rand.

Types

type MTAState

type MTAState struct {
	SamplesCount uint64
	LatestAvg    time.Duration
	Mu           sync.RWMutex `sql:"-" json:"-" xml:"-" csv:"-"`
}

MTAState holds all required data for Moving Time Average. Useful when using within ORM models

func (*MTAState) Calc

func (mta *MTAState) Calc(nextSample time.Duration) time.Duration

Calc is the wrapper on CalcMTA which uses only current state data and provided next sample. This function automatically updates current state and it is concurrency safe

Warning: this MTA will return approx. value and not the exact one. This is what we paid so we're not storing all values.

func (*MTAState) Scan

func (mta *MTAState) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*MTAState) Value

func (mta *MTAState) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type TOTPState

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

TOTPState handles database/sql interface implementation, recovery password generation and validation

func NewTOTP

func NewTOTP(label, issuer, user string, length ...totpLength) *TOTPState

NewTOTP initializes TOTPState for a user.

WARNING: DO NOT reuse TOTPState instance for more then one user!

func (*TOTPState) GetRecoveryPasswords

func (totp *TOTPState) GetRecoveryPasswords() []string

GetRecoveryPasswords returns a copy of recovery passwords slice to be shown to user when TOTP onboarding succeeded

func (*TOTPState) InvalidateRecoveryPassword

func (totp *TOTPState) InvalidateRecoveryPassword(rp string) (wasValid bool)

InvalidateRecoveryPassword invalidates given recovery password if it valid and returns if it was valid on invalidation

func (*TOTPState) IsValidState

func (totp *TOTPState) IsValidState() bool

IsValidState checks if current totp instance was loaded correctly

func (*TOTPState) QR

func (totp *TOTPState) QR() (image.Image, error)

QR returns 300x300px QR code image for current TOTP user's secret

func (*TOTPState) QRScaled

func (totp *TOTPState) QRScaled(width, height uint16) (image.Image, error)

QR returns QR code image for current TOTP user's secret with given width and height

func (*TOTPState) Scan

func (totp *TOTPState) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*TOTPState) Token

func (totp *TOTPState) Token() string

Token returns a token for current period

func (*TOTPState) Value

func (totp *TOTPState) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (*TOTPState) Verify

func (totp *TOTPState) Verify(token string) bool

Verify verifies given token for current TOTP state

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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