diff --git a/cmd/authy-export/authy-export.go b/cmd/authy-export/authy-export.go index b542138..8697480 100644 --- a/cmd/authy-export/authy-export.go +++ b/cmd/authy-export/authy-export.go @@ -70,7 +70,7 @@ func main() { for _, tok := range tokensResponse.AuthenticatorTokens { decrypted, err := tok.Decrypt(string(pp)) if err != nil { - log.Printf("Failed to decrypt token %s: %v", tok.OriginalName, err) + log.Printf("Failed to decrypt token %s: %v", tok.Description(), err) continue } @@ -80,7 +80,7 @@ func main() { u := url.URL{ Scheme: "otpauth", Host: "totp", - Path: tok.OriginalName, + Path: tok.Description(), RawQuery: params.Encode(), } fmt.Println(u.String()) diff --git a/objects.go b/objects.go index 42dc96e..eff004a 100644 --- a/objects.go +++ b/objects.go @@ -182,3 +182,15 @@ func (t AuthenticatorToken) Decrypt(passphrase string) (string, error) { } return strings.ToUpper(string(buf)), nil } + +// Description returns OriginalName if not empty, otherwise Name, +// otherwise `Token-{UniqueID}`. +func (t AuthenticatorToken) Description() string { + if t.OriginalName != "" { + return t.OriginalName + } + if t.Name != "" { + return t.Name + } + return "Token-" + t.UniqueID +}