otp

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

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

Go to latest
Published: Apr 21, 2018 License: MIT Imports: 12 Imported by: 0

README

Build Status

One-Time Password Algorithm in Go

One-Time Password algorithm in Go language

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGenerateMissingAccountName = errors.New("AccountName must be set")

ErrGenerateMissingAccountName 在生成一个密钥时如果未指定Account Name,则返回该error

View Source
var ErrGenerateMissingIssuer = errors.New("Issuer must be set")

ErrGenerateMissingIssuer 在生成一个密钥时如果未指定issuer,则返回该error

View Source
var ErrValidateInputInvalidLength = errors.New("Input length unexpected")

ErrValidateInputInvalidLength 在用户提供了错误的密码长度时,返回该error

View Source
var ErrValidateSecretInvalidBase32 = errors.New("Decoding of secret as base32 failed")

ErrValidateSecretInvalidBase32 在我们尝试将secret从base32字符串转换为原始字节数组时发生错误,就返回该error

Functions

This section is empty.

Types

type Algorithm

type Algorithm int

Algorithm 表示计算一次性密码时使用的哈希函数

const (
	AlgorithmSHA1 Algorithm = iota
	AlgorithmSHA256
	AlgorithmSHA512
	AlgorithmMD5
)

consts

func (Algorithm) Hash

func (a Algorithm) Hash() hash.Hash

Hash 返回算法对应的hash.Hash

func (Algorithm) String

func (a Algorithm) String() string

type Digits

type Digits int

Digits 表示最终生成的一次性密码位数 6或8位是最常见的

const (
	DigitsSix   Digits = 6
	DigitsEight Digits = 8
)

consts

func (Digits) Format

func (d Digits) Format(in int32) string

Format 将一个整数使用0填充为具有d位的字符串

func (Digits) Length

func (d Digits) Length() int

Length 返回此数字的字符数

func (Digits) String

func (d Digits) String() string

type Key

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

Key 表示一个HOTP或TOTP的密钥 一般用于谷歌验证器

func NewKeyFromURL

func NewKeyFromURL(orig string) (*Key, error)

NewKeyFromURL 基于TOTP或HOTP URL创建一个密钥

func (*Key) AccountName

func (k *Key) AccountName() string

AccountName 返回用户帐号

func (*Key) Image

func (k *Key) Image(width int, height int) (image.Image, error)

Image 创建一个二维码图片

func (*Key) Issuer

func (k *Key) Issuer() string

Issuer 返回发布者

func (*Key) Secret

func (k *Key) Secret() string

Secret 返回密钥中包含的secret

func (*Key) String

func (k *Key) String() string

func (*Key) Type

func (k *Key) Type() string

Type 返回"hotp"或者"totp"

func (*Key) URL

func (k *Key) URL() string

URL 返回OTP的URL字符串

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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