otp

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

This is a fork of github.com/pquerna/otp that has been trimmed down to remove all external dependencies. Specifically, the following things have been removed:

  • QR code generation support
  • Testing support libraries (replaced with normal built-in tools)
  • Examples

In addition, travis CI has been replaced with Github actions.

Documentation

Index

Constants

This section is empty.

Variables

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

When generating a Key, the Account Name must be set.

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

When generating a Key, the Issuer must be set.

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

The user provided passcode length was not expected.

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

Error when attempting to convert the secret from base32 to raw bytes.

Functions

This section is empty.

Types

type Algorithm

type Algorithm int

Algorithm represents the hashing function to use in the HMAC operation needed for OTPs.

const (
	// AlgorithmSHA1 should be used for compatibility with Google Authenticator.
	//
	// See https://github.com/ecnepsnai/otp/issues/55 for additional details.
	AlgorithmSHA1 Algorithm = iota
	AlgorithmSHA256
	AlgorithmSHA512
	AlgorithmMD5
)

func (Algorithm) Hash

func (a Algorithm) Hash() hash.Hash

func (Algorithm) String

func (a Algorithm) String() string

type Digits

type Digits int

Digits represents the number of digits present in the user's OTP passcode. Six and Eight are the most common values.

const (
	DigitsSix   Digits = 6
	DigitsEight Digits = 8
)

func (Digits) Format

func (d Digits) Format(in int32) string

Format converts an integer into the zero-filled size for this Digits.

func (Digits) Length

func (d Digits) Length() int

Length returns the number of characters for this Digits.

func (Digits) String

func (d Digits) String() string

type Key

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

Key represents an TOTP or HTOP key.

func NewKeyFromURL

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

NewKeyFromURL creates a new Key from an TOTP or HOTP url.

The URL format is documented here:

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

func (*Key) AccountName

func (k *Key) AccountName() string

AccountName returns the name of the user's account.

func (*Key) Algorithm

func (k *Key) Algorithm() Algorithm

Algorithm returns the algorithm used or the default (SHA1).

func (*Key) Digits

func (k *Key) Digits() Digits

Digits returns a tiny int representing the number of OTP digits.

func (*Key) Issuer

func (k *Key) Issuer() string

Issuer returns the name of the issuing organization.

func (*Key) Period

func (k *Key) Period() uint64

Period returns a tiny int representing the rotation time in seconds.

func (*Key) Secret

func (k *Key) Secret() string

Secret returns the opaque secret for this Key.

func (*Key) String

func (k *Key) String() string

func (*Key) Type

func (k *Key) Type() string

Type returns "hotp" or "totp".

func (*Key) URL

func (k *Key) URL() string

URL returns the OTP URL as a string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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