otp

package module
v0.0.0-...-36d49d3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 14 Imported by: 0

README

otp

TOTP, HOTP implementation in golang.

Usage

Package
import "github.com/go-oss/otp"
CLI
$ go install github.com/go-oss/otp/cmd/otp
$ otp -h
Usage of otp:
  -uri string
        Key uri (required)
  -watch
        If specified, display the token each time it expires.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidScheme is error that scheme is not "otpauth".
	ErrInvalidScheme = errors.New("invalid scheme")
	// ErrInvalidOTPType is error that specified otp type is not supported.
	ErrInvalidOTPType = errors.New("invalid otp type")
	// ErrEmptySecret is error that secret is empty.
	ErrEmptySecret = errors.New("secret param is required")
	// ErrInvalidAlgorithm is error that specified algorithm is not supported.
	ErrInvalidAlgorithm = errors.New("invalid algorithm")
	// ErrEmptyCounter is error that counter is empty.
	ErrEmptyCounter = errors.New("counter param is required for HOTP")
)

Functions

This section is empty.

Types

type HOTP

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

HOTP represents HMAC-based One Time Password.

func NewHOTP

func NewHOTP(uri *KeyURI) (*HOTP, error)

NewHOTP returns a new HOTP generator.

func (*HOTP) Generate

func (p *HOTP) Generate(count uint64) (string, error)

Generate returns HOTP token from count.

func (*HOTP) Next

func (p *HOTP) Next() (string, error)

Next returns next HOTP token.

type KeyURI

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

KeyURI represents OTP configurations.

func ParseKeyURI

func ParseKeyURI(uri string) (*KeyURI, error)

ParseKeyURI parses key uri formatted string. Key Uri Format: https://github.com/google/google-authenticator/wiki/Key-Uri-Format

func (*KeyURI) String

func (k *KeyURI) String() string

String encodes to key uri formatted string.

type TOTP

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

TOTP represents Time-based One Time Password.

func NewTOTP

func NewTOTP(uri *KeyURI) (*TOTP, error)

NewTOTP returns a new TOTP generator.

func (*TOTP) Expires

func (p *TOTP) Expires(t time.Time) time.Time

Expires returns next expiry time.

func (*TOTP) Generate

func (p *TOTP) Generate(t time.Time) (string, error)

Generate TOTP token from time.

Directories

Path Synopsis
cmd
otp

Jump to

Keyboard shortcuts

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