mirror of
https://github.com/1f349/twofactor.git
synced 2024-12-22 07:24:12 +00:00
Fixed issue with issuer encoding - made URL() private
This commit is contained in:
parent
737259eaba
commit
93dfb338c7
6
totp.go
6
totp.go
@ -55,7 +55,7 @@ func (otp *Totp) synchronizeCounter(offset int) {
|
|||||||
|
|
||||||
// Label returns the combination of issuer:account string
|
// Label returns the combination of issuer:account string
|
||||||
func (otp *Totp) label() string {
|
func (otp *Totp) label() string {
|
||||||
return url.QueryEscape(fmt.Sprintf("%s:%s", otp.issuer, otp.account))
|
return fmt.Sprintf("%s:%s", url.QueryEscape(otp.issuer), otp.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Counter returns the TOTP's 8-byte counter as unsigned 64-bit integer.
|
// Counter returns the TOTP's 8-byte counter as unsigned 64-bit integer.
|
||||||
@ -275,7 +275,7 @@ func calculateToken(counter []byte, digits int, h hash.Hash) string {
|
|||||||
|
|
||||||
// URL returns a suitable URL, such as for the Google Authenticator app
|
// URL returns a suitable URL, such as for the Google Authenticator app
|
||||||
// example: otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
|
// example: otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
|
||||||
func (otp *Totp) URL() (string, error) {
|
func (otp *Totp) url() (string, error) {
|
||||||
|
|
||||||
// verify the proper initialization
|
// verify the proper initialization
|
||||||
if err := totpHasBeenInitialized(otp); err != nil {
|
if err := totpHasBeenInitialized(otp); err != nil {
|
||||||
@ -316,7 +316,7 @@ func (otp *Totp) URL() (string, error) {
|
|||||||
func (otp *Totp) QR() ([]byte, error) {
|
func (otp *Totp) QR() ([]byte, error) {
|
||||||
|
|
||||||
// get the URL
|
// get the URL
|
||||||
u, err := otp.URL()
|
u, err := otp.url()
|
||||||
|
|
||||||
// check for errors during initialization
|
// check for errors during initialization
|
||||||
// this is already done on the URL method
|
// this is already done on the URL method
|
||||||
|
@ -275,12 +275,12 @@ func TestSerialization(t *testing.T) {
|
|||||||
t.Error("Deserialized hash property differ from original TOTP")
|
t.Error("Deserialized hash property differ from original TOTP")
|
||||||
}
|
}
|
||||||
|
|
||||||
deserializedUrl, err := deserializedOTP.URL()
|
deserializedUrl, err := deserializedOTP.url()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
otpdUrl, err := otp.URL()
|
otpdUrl, err := otp.url()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ func TestSerialization(t *testing.T) {
|
|||||||
|
|
||||||
func TestProperInitialization(t *testing.T) {
|
func TestProperInitialization(t *testing.T) {
|
||||||
otp := Totp{}
|
otp := Totp{}
|
||||||
if _, err := otp.URL(); err == nil {
|
if _, err := otp.url(); err == nil {
|
||||||
t.Fatal("Totp is not properly initialized and the method did not catch it")
|
t.Fatal("Totp is not properly initialized and the method did not catch it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user