Skip to content

Commit 8e6a1a7

Browse files
committed
2fa: drop spaces from key text before decoding
Fixes #2.
1 parent c9558c5 commit 8e6a1a7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

‎main.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ func (c *Keychain) list() {
207207
}
208208
}
209209

210+
func noSpace(r rune) rune {
211+
if unicode.IsSpace(r) {
212+
return -1
213+
}
214+
return r
215+
}
216+
210217
func (c *Keychain) add(name string) {
211218
size := 6
212219
if *flag7 {
@@ -223,7 +230,7 @@ func (c *Keychain) add(name string) {
223230
if err != nil {
224231
log.Fatalf("error reading key: %v", err)
225232
}
226-
text = text[:len(text)-1] // chop \n
233+
text = strings.Map(noSpace, text)
227234
if _, err := decodeKey(text); err != nil {
228235
log.Fatalf("invalid key: %v", err)
229236
}

0 commit comments

Comments
 (0)