Documentation ¶
Overview ¶
Package common provides common web-related shortcuts, solutions and algorithms
Index ¶
- Constants
- Variables
- func CalcMTA(samplesCount uint64, latestAvg time.Duration, nextSample time.Duration) time.Duration
- func GenerateKey() (b []byte, err error)
- type MTAState
- type TOTPState
- func (totp *TOTPState) GetRecoveryPasswords() []string
- func (totp *TOTPState) InvalidateRecoveryPassword(rp string) (wasValid bool)
- func (totp *TOTPState) IsValidState() bool
- func (totp *TOTPState) QR() (image.Image, error)
- func (totp *TOTPState) QRScaled(width, height uint16) (image.Image, error)
- func (totp *TOTPState) Scan(value interface{}) error
- func (totp *TOTPState) Token() string
- func (totp *TOTPState) Value() (driver.Value, error)
- func (totp *TOTPState) Verify(token string) bool
Constants ¶
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 ¶
var ErrCouldNotScan = errors.New("gramework/common: could not scan value")
Functions ¶
func CalcMTA ¶
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 ¶
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 ¶
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.
type TOTPState ¶
type TOTPState struct {
// contains filtered or unexported fields
}
TOTPState handles database/sql interface implementation, recovery password generation and validation
func NewTOTP ¶
NewTOTP initializes TOTPState for a user.
WARNING: DO NOT reuse TOTPState instance for more then one user!
func (*TOTPState) GetRecoveryPasswords ¶
GetRecoveryPasswords returns a copy of recovery passwords slice to be shown to user when TOTP onboarding succeeded
func (*TOTPState) InvalidateRecoveryPassword ¶
InvalidateRecoveryPassword invalidates given recovery password if it valid and returns if it was valid on invalidation
func (*TOTPState) IsValidState ¶
IsValidState checks if current totp instance was loaded correctly
func (*TOTPState) QRScaled ¶
QR returns QR code image for current TOTP user's secret with given width and height