mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-06 04:34:08 +01:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUjQDUjKfYub2zxVWMM
39 lines
899 B
Go
39 lines
899 B
Go
package keychain
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"strings"
|
|
)
|
|
|
|
// parseSecurityPassword liest die Zeile „password: …“ aus der Ausgabe von
|
|
// macOS „security find-generic-password -g“. Liegt hier (ohne Build-Tag),
|
|
// damit der Test überall läuft.
|
|
func parseSecurityPassword(out string) (string, error) {
|
|
for _, l := range strings.Split(out, "\n") {
|
|
l = strings.TrimRight(l, "\r")
|
|
if !strings.HasPrefix(l, "password:") {
|
|
continue
|
|
}
|
|
v := strings.TrimSpace(strings.TrimPrefix(l, "password:"))
|
|
if v == "" {
|
|
return "", nil
|
|
}
|
|
if strings.HasPrefix(v, "0x") {
|
|
h := v[2:]
|
|
if i := strings.IndexByte(h, ' '); i >= 0 {
|
|
h = h[:i]
|
|
}
|
|
b, err := hex.DecodeString(h)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(b), nil
|
|
}
|
|
if len(v) >= 2 && v[0] == '"' && v[len(v)-1] == '"' {
|
|
return v[1 : len(v)-1], nil
|
|
}
|
|
return v, nil
|
|
}
|
|
return "", ErrNotFound
|
|
}
|