Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding parsing for "period" #49

Merged
merged 3 commits into from
Apr 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"image"
"net/url"
"strings"
"strconv"
)

// Error when attempting to convert the secret from base32 to raw bytes.
Expand Down Expand Up @@ -138,6 +139,18 @@ func (k *Key) Secret() string {
return q.Get("secret")
}

// Period returns a tiny int representing the rotation time in seconds.
func (k *Key) Period() uint64 {
q := k.url.Query()

if u, err := strconv.ParseUint(q.Get("period"), 10, 64); err == nil {
return u
}

// If no period is defined 30 seconds is the default per (rfc6238)
return 30
}

// URL returns the OTP URL as a string
func (k *Key) URL() string {
return k.url.String()
Expand Down