Fixed issue with issuer encoding - made URL() private

This commit is contained in:
silenteh 2015-08-04 17:21:09 +02:00
parent 737259eaba
commit 93dfb338c7
2 changed files with 6 additions and 6 deletions

View File

@ -55,7 +55,7 @@ func (otp *Totp) synchronizeCounter(offset int) {
// Label returns the combination of issuer:account 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.
@ -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
// 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
if err := totpHasBeenInitialized(otp); err != nil {
@ -316,7 +316,7 @@ func (otp *Totp) URL() (string, error) {
func (otp *Totp) QR() ([]byte, error) {
// get the URL
u, err := otp.URL()
u, err := otp.url()
// check for errors during initialization
// this is already done on the URL method

View File

@ -275,12 +275,12 @@ func TestSerialization(t *testing.T) {
t.Error("Deserialized hash property differ from original TOTP")
}
deserializedUrl, err := deserializedOTP.URL()
deserializedUrl, err := deserializedOTP.url()
if err != nil {
t.Error(err)
}
otpdUrl, err := otp.URL()
otpdUrl, err := otp.url()
if err != nil {
t.Error(err)
}
@ -309,7 +309,7 @@ func TestSerialization(t *testing.T) {
func TestProperInitialization(t *testing.T) {
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")
}
}