totp

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

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

Go to latest
Published: Jan 12, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package totp implements Time-Based One Time Password(RFC 6238).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decrypter

type Decrypter interface {
	Decrypt(msg []byte) ([]byte, error)
}

Decrypter is the interface that wraps the basic Decrypt method

type EncDecrypter

type EncDecrypter interface {
	Encrypter
	Decrypter
}

EncDecrypter is the interface that groups the basic Encrypt and Decrypt methods.

type Encrypter

type Encrypter interface {
	Encrypt(msg []byte) ([]byte, error)
}

Encrypter is the interface that wraps the basic Encrypt method

type Key

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

Key is a configuration for Time-Based One Time Password(RFC 6238)

func FromEncryptedString

func FromEncryptedString(encryptedStr string, decrypter Decrypter) (*Key, error)

FromEncryptedString decrypts and returns key

func NewKey

func NewKey(options ...Option) (*Key, error)

NewKey creates a new TOTP key

func (*Key) GenerateCode

func (k *Key) GenerateCode() string

GenerateCode generates a TOTP code using the current time.

func (*Key) GenerateCodeAt

func (k *Key) GenerateCodeAt(t time.Time) string

GenerateCodeAt generates a TOTP code using a specified time.

func (*Key) ToEncryptedString

func (k *Key) ToEncryptedString(encrypter Encrypter) (string, error)

ToEncryptedString converts key to encrypted string

func (*Key) URI

func (k *Key) URI(issuer, account string) string

URI returns the OTP URI as a string.

See https://github.com/google/google-authenticator/wiki/Key-Uri-Format

func (*Key) ValidateCode

func (k *Key) ValidateCode(code string) bool

ValidateCode validates a TOTP code using the current time.

func (*Key) ValidateCodeAt

func (k *Key) ValidateCodeAt(code string, t time.Time) bool

ValidateCodeAt validates a TOTP code using a specified time.

type Option

type Option func(k *Key) error

Option is a functional option for Key constructor.

func Algorithm

func Algorithm(alg string) Option

Algorithm returns a functional option for the TOTP algorithm.

Currently "sha1", "sha256" and "sha512" are supported.

The default value is "sha1".

func Digits

func Digits(digits int) Option

Digits returns a functional option for the TOTP digits parameter that determines how long of a one-time passcode.

The default value is 6.

func Period

func Period(period int) Option

Period returns a functional option for the TOTP period parameter that defines a period that a TOTP code will be valid for, in seconds.

The default value is 30.

func Secret

func Secret(secret []byte) Option

Secret returns a functional option for the TOTP secret parameter.

If omitted, it is automatically generated.

Jump to

Keyboard shortcuts

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