diff options
| author | ishaan <contact@ishaan.cc> | 2026-07-19 12:51:29 +0530 |
|---|---|---|
| committer | ishaan <contact@ishaan.cc> | 2026-07-19 12:51:29 +0530 |
| commit | 80b1c6deec723095f08de6aee289d4fb32ca9337 (patch) | |
| tree | d087da09b13969b16be1a3f06b3054e94f4e9aa7 /internal/crud/cli_new.go | |
| parent | e192902465651afc53547c90cb518d0adfe7df83 (diff) | |
add key discovery
Diffstat (limited to 'internal/crud/cli_new.go')
| -rw-r--r-- | internal/crud/cli_new.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/internal/crud/cli_new.go b/internal/crud/cli_new.go index 9bf9af5..8823c4f 100644 --- a/internal/crud/cli_new.go +++ b/internal/crud/cli_new.go @@ -184,7 +184,11 @@ func PromptRecipientKeys(defaultPubKeyBytes []byte) ([][]byte, bool, error) { if addMore { for { - fmt.Print("Enter a public key, or path to a public key file (comma-separated for multiple): ") + fmt.Println("Enter public keys (comma-separated for multiple):") + fmt.Println("Examples: ~/keys/bob.pub, ./tommy.key") + fmt.Println(" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AA..., ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAZ...") + fmt.Println(" bob@github, james@gitlab") + fmt.Print("Public Keys: ") utils.StdinScanner.Scan() if err := utils.StdinScanner.Err(); err != nil { return nil, false, fmt.Errorf("failed to read public key: %v", err) @@ -202,9 +206,23 @@ func PromptRecipientKeys(defaultPubKeyBytes []byte) ([][]byte, bool, error) { } var keyBytes []byte + + if strings.Contains(part, "@") && !strings.HasPrefix(part, "ssh-") { + parts := strings.Split(part, "@") + if len(parts) != 2 { + return nil, false, fmt.Errorf("unsupported source or invalid key format: %s", part) + } + + username, service := parts[0], parts[1] + keyBytes, err = utils.GetPubKeyFromService(username, service) + if err != nil { + return nil, false, fmt.Errorf("failed to get public key from %s: %v", part, err) + } + } + if strings.HasPrefix(part, "ssh-") { keyBytes = []byte(part) - } else { + } else if len(keyBytes) == 0 { var err error keyBytes, err = os.ReadFile(part) if err != nil { @@ -288,9 +306,6 @@ func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath if err != nil { return err } - if err != nil { - return err - } _, err = file.Write(encrypted) if err != nil { |