otpauth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPeriod is a default value of period
	DefaultPeriod = 30
)

Variables

View Source
var ErrInvalidDigitsLength = errors.New("digits length unexpected")

ErrInvalidDigitsLength is an error when the digits length unexpected

View Source
var ErrOtpAuthOptionIsNil = errors.New("otpauth option is nil")

ErrOtpAuthOptionIsNil is an error when the otpauth option is nil

Functions

This section is empty.

Types

type Algorithm

type Algorithm int

Algorithm is the hash function to use in the HMAC operation

const (
	// AlgorithmSHA1 is a cryptographic hash function of SHA-1
	AlgorithmSHA1 Algorithm = iota
	// AlgorithmSHA256 is a cryptographic hash function of SHA-256
	AlgorithmSHA256
	// AlgorithmSHA512 is a cryptographic hash function of SHA-512
	AlgorithmSHA512
	// AlgorithmMD5 is a cryptographic hash function of MD5
	AlgorithmMD5
)

func (Algorithm) Enabled

func (a Algorithm) Enabled() bool

Enabled returns a boolean value for whether algorithm are valid

func (Algorithm) Hash

func (a Algorithm) Hash() hash.Hash

Hash returns an initialization function of each hash algorithm

type Digits

type Digits int

Digits is the number of digits

const (
	// DigitsSix represents that the digit is 6.
	DigitsSix Digits = 6
	// DigitsEight represents that the digit is 8.
	DigitsEight Digits = 8
)

func (Digits) Enabled

func (d Digits) Enabled() bool

Enabled returns a boolean value for whether digits are valid

func (Digits) Format

func (d Digits) Format(in int32) string

Format converts from argument to zero-filled characters

func (Digits) Length

func (d Digits) Length() int

Length returns the number of digits

type Host

type Host int

Host is a host of otpauth

const (
	// HostHOTP is a host of HMAC-based One Time Password
	HostHOTP Host = iota
	// HostTOTP is a host of Time-based One Time Password
	HostTOTP
)

type Option

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

Option is used when generates otpauth

func NewOption

func NewOption() (*Option, error)

NewOption generates an option by passing issuer, account name and host

func (*Option) Secret

func (opt *Option) Secret() string

Secret returns a secret that option has

func (*Option) SetAlgorithm

func (opt *Option) SetAlgorithm(a Algorithm) error

SetAlgorithm sets the hash algorithm

func (*Option) SetDigits

func (opt *Option) SetDigits(d Digits) error

SetDigits sets the number of digits

func (*Option) SetIconURL

func (opt *Option) SetIconURL(url string) error

SetIconURL sets a url of icon

func (*Option) SetPeriod

func (opt *Option) SetPeriod(period uint) error

SetPeriod sets a period that Time-based One Time Password hash is valid

func (*Option) SetSecret

func (opt *Option) SetSecret(secret string) error

SetSecret sets a secret that has already been generated

func (*Option) SetSecretSize

func (opt *Option) SetSecretSize(secretSize uint) error

SetSecretSize sets a secretSize of the generated Secret

type OtpAuth

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

OtpAuth has an optauth url and a secret key

func GenerateOtpAuth

func GenerateOtpAuth(issuer, accountName string, host Host) (*OtpAuth, error)

GenerateOtpAuth generates an otpAuth by passing issuer, account name and host

func GenerateOtpAuthWithOption

func GenerateOtpAuthWithOption(issuer, accountName string, host Host, opt *Option) (*OtpAuth, error)

GenerateOtpAuthWithOption generates an otpAuth by passing option

func (*OtpAuth) QRCode

func (oa *OtpAuth) QRCode() (string, error)

QRCode returns value is the base64 encoded image data

func (*OtpAuth) Secret

func (oa *OtpAuth) Secret() string

Secret returns a secret that is included in otpAuth

func (*OtpAuth) URL

func (oa *OtpAuth) URL() string

URL returns an url that is included in otpAuth

Jump to

Keyboard shortcuts

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