fix nak key encrypt reading from stdin.

This commit is contained in:
fiatjaf 2024-06-12 08:54:00 -03:00
parent 1ba39ca7d7
commit 9f98a0aea3

7
key.go
View File

@ -72,20 +72,19 @@ var encrypt = &cli.Command{
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
var content string keys := make([]string, 0, 1)
var password string var password string
switch c.Args().Len() { switch c.Args().Len() {
case 1: case 1:
content = ""
password = c.Args().Get(0) password = c.Args().Get(0)
case 2: case 2:
content = c.Args().Get(0) keys = append(keys, c.Args().Get(0))
password = c.Args().Get(1) password = c.Args().Get(1)
} }
if password == "" { if password == "" {
return fmt.Errorf("no password given") return fmt.Errorf("no password given")
} }
for sec := range getSecretKeysFromStdinLinesOrSlice(c, []string{content}) { for sec := range getSecretKeysFromStdinLinesOrSlice(c, keys) {
ncryptsec, err := nip49.Encrypt(sec, password, uint8(c.Int("logn")), 0x02) ncryptsec, err := nip49.Encrypt(sec, password, uint8(c.Int("logn")), 0x02)
if err != nil { if err != nil {
lineProcessingError(c, "failed to encrypt: %s", err) lineProcessingError(c, "failed to encrypt: %s", err)