otpauth

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: BSD-3-Clause Imports: 7 Imported by: 6

Documentation

Overview

Package otpauth handles the URL format used to specify OTP parameters.

This package conforms to the specification at: https://github.com/google/google-authenticator/wiki/Key-Uri-Format

The general form of an OTP URL is:

otpauth://TYPE/LABEL?PARAMETERS

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type URL

type URL struct {
	Type      string // normalized to lowercase, e.g., "totp"
	Issuer    string // also called "provider" in some docs
	Account   string // without provider prefix
	RawSecret string // base32-encoded, no padding
	Algorithm string // normalized to uppercase; default is "SHA1"
	Digits    int    // default is 6
	Period    int    // in seconds; default is 30
	Counter   uint64
}

A URL contains the parsed representation of an otpauth URL.

func ParseURL

func ParseURL(s string) (*URL, error)

ParseURL parses s as a URL in the otpauth scheme.

The input may omit a scheme, but if present the scheme must be otpauth://. The parser will report an error for invalid syntax, including unknown URL parameters, but does not otherwise validate the results. In particular, the values of the Type and Algorithm fields are not checked.

Fields of the URL corresponding to unset parameters are populated with default values as described on the URL struct. If a different issuer is set on the label and in the parameters, the parameter takes priority.

func (*URL) MarshalText added in v0.3.2

func (u *URL) MarshalText() ([]byte, error)

MarshalText implemens the encoding.TextMarshaler interface. It emits the same URL string produced by the String method.

func (*URL) Secret added in v0.2.3

func (u *URL) Secret() ([]byte, error)

Secret parses the contents of the RawSecret field.

func (*URL) SetSecret

func (u *URL) SetSecret(key []byte)

SetSecret encodes key as base32 and updates the RawSecret field.

func (*URL) String

func (u *URL) String() string

String converts u to a URL in the standard encoding.

func (*URL) UnmarshalText added in v0.3.2

func (u *URL) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. It expects its input to be a URL in the standard encoding.

Jump to

Keyboard shortcuts

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