Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateRandomCode(digits int) (string, error)
- func HOTP(secret []byte, counter uint64, alg HashConstructor, digits int) (string, error)
- func TOTP(secret []byte, t uint64, opts TOTPOpts) (string, error)
- func TOTPGenerateSecret(secretLength int, opts TOTPURI) (string, string, error)
- func TOTPNow(secret []byte, opts TOTPOpts) (string, error)
- func TOTPVerify(params string, code string, hashes Hashes) (bool, error)
- type HashConstructor
- type Hashes
- type TOTPConfig
- type TOTPOpts
- type TOTPURI
Constants ¶
View Source
const ( // TOTPPeriodDefault is the default TOTP period TOTPPeriodDefault uint64 = 30 // OTPDigitsDefault is the default OTP length OTPDigitsDefault = 6 )
View Source
const ( AlgSHA1 = "SHA1" AlgSHA256 = "SHA256" AlgSHA512 = "SHA512" )
Hash algorithms
Variables ¶
View Source
var ( // ErrInvalidOpt is returned when an invalid opt is passed to otp ErrInvalidOpt errInvalidOpt // ErrOptUnsupported is returned when an otp opt is unsupported ErrOptUnsupported errOptUnsupported // ErrParamInvalid is returned when an otp param string is invalid ErrParamInvalid errParamInvalid )
View Source
var DefaultHashes = otpHashes{ AlgSHA1: crypto.SHA1.New, AlgSHA256: crypto.SHA256.New, AlgSHA512: crypto.SHA512.New, }
DefaultHashes are the hashes defined by RFC6238
Functions ¶
func GenerateRandomCode ¶
GenerateRandomCode generates a random code with a specified length
func TOTPGenerateSecret ¶
TOTPGenerateSecret generates an otp secret
Types ¶
type HashConstructor ¶
HashConstructor constructs a new hash
type Hashes ¶
type Hashes interface {
Get(id string) (HashConstructor, bool)
}
Hashes are a map of valid hashes
type TOTPConfig ¶
TOTPConfig are opts for TOTP
func (TOTPConfig) String ¶
func (c TOTPConfig) String() string
type TOTPOpts ¶
type TOTPOpts struct { Alg HashConstructor Digits int Period uint64 }
TOTPOpts are opts for TOTP
Click to show internal directories.
Click to hide internal directories.