Skip to content

Commit

Permalink
Adding parsing for "period" (#49)
Browse files Browse the repository at this point in the history
* Add Period Parsing

Will parse the "period" query delimiter into a uint

* Update otp.go

Add the import for strconv
  • Loading branch information
ben-rowe committed Apr 12, 2020
1 parent 468c2dd commit 2257f83
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit 2257f83

Please sign in to comment.