gotp

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 11 Imported by: 0

README

🔒 gotp

GitHub Release Go Reference MIT License Go Report Card

gotp is a library for generating and verifying One-Time Passwords (OTP).

It supports both the TOTP (Time-based One-Time Password) algorithm as defined in RFC 6238, and the HOTP (HMAC-Based One-Time Password) algorithm as defined in RFC 4226.

Each package has been tesed against the test vectors provided in their respective RFC specifications.

Installation

go get -u github.com/Jaytpa01/gotp

Features

  • TOTP:
    • Generate OTPs based off of the current time, or a specified time.
  • HOTP:
    • Generate OTPs based off of a counter value.
  • High-Level OTP Handling:
    • Unified interface for both TOTP and HOTP generation.
    • Easy to use API with flexible configuration and sensible defaults.

Usage

TODO: provide usage examples for the high-level otp handling, as well as examples for direct use of the hotp and totp packages.

Options

TODO: provide a reference for all options when creating a new otp instance. (functional options pattern)

Documentation

Index

Constants

View Source
const (
	DefaultWindow = 0
	DefaultDigits = 6
	DefaultPeriod = 30
)

Variables

View Source
var DefaultHashingAlgorithm = sha1.New

Functions

func Base32Decode added in v0.2.0

func Base32Decode(s string) ([]byte, error)

func Base32Encode added in v0.2.0

func Base32Encode(data []byte) string

func RandomSecret added in v0.2.0

func RandomSecret(length int) ([]byte, error)

func WithBase32Secret added in v0.2.0

func WithBase32Secret(s string) option

func WithCount added in v0.2.0

func WithCount(count int64) option

func WithDigits added in v0.2.0

func WithDigits(digits int) option

func WithHOTP added in v0.2.0

func WithHOTP() option

func WithHashingAlgorithm added in v0.2.0

func WithHashingAlgorithm(ha HashingAlgorithm) option

func WithIssuer added in v0.2.0

func WithIssuer(issuer string) option

func WithPeriod added in v0.2.0

func WithPeriod(period int) option

func WithSecret added in v0.2.0

func WithSecret(secret []byte) option

Types

type Algorithm added in v0.2.1

type Algorithm int
const (
	TOTP Algorithm = iota
	HOTP
)

type HashingAlgorithm added in v0.2.1

type HashingAlgorithm int
const (
	SHA1 HashingAlgorithm = iota
	SHA256
	SHA512
)

type OTP

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

func New added in v0.2.0

func New(accountName string, options ...option) (*OTP, error)

func (*OTP) At added in v0.2.1

func (o *OTP) At(time time.Time) *OTP

func (*OTP) Base32Secret added in v0.2.1

func (o *OTP) Base32Secret() string

func (*OTP) Generate added in v0.2.1

func (o *OTP) Generate() (string, error)

func (*OTP) Secret added in v0.2.1

func (o *OTP) Secret() []byte

Directories

Path Synopsis
Package hotp implements the HMAC-based One-Time Password (HOTP) algorithm.
Package hotp implements the HMAC-based One-Time Password (HOTP) algorithm.
Package totp implements the Time-based One-Time Password (TOTP) algorithm.
Package totp implements the Time-based One-Time Password (TOTP) algorithm.

Jump to

Keyboard shortcuts

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