Pad non-padded secrets. This lets us continue building on <= go1.8.

- Add tests for secrets using various padding methods.
- Add a new method/test to append padding to non-padded secrets.
This commit is contained in:
Aaron Bieber
2018-04-18 09:16:40 -06:00
committed by Kyle Isom
parent 5fd928f69a
commit bbc82ff8de
5 changed files with 113 additions and 4 deletions

16
util.go Normal file
View File

@@ -0,0 +1,16 @@
package twofactor
import (
"strings"
)
// Pad calculates the number of '='s to add to our encoded string
// to make base32.StdEncoding.DecodeString happy
func Pad(s string) string {
if !strings.HasSuffix(s, "=") && len(s)%8 != 0 {
for len(s)%8 != 0 {
s += "="
}
}
return s
}