Skip to content

Commit

Permalink
add . shortcut to embed public key
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Dec 26, 2023
1 parent 450afd4 commit a840f3a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ whisper -p='@ysmood:ecdsa' plain > encrypted
# Encrypt content for multiple recipients, such as Jack and Tim.
whisper -a='@ysmood' -p='@jack' -p='@tim' plain > encrypted

# Or embed the default public key file to the output.
whisper -a=. -p='@jack' -p='@tim' plain > encrypted

# Decrypt on Jack's machine, the machine has Jack's private key.
whisper -d encrypted
```
6 changes: 5 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func callAgent(decrypt bool, publicKey string, conf whisper.Config, inFile, outF
// If the public key is remote, the output will be prefixed with "@", the prefix will end with space.
// If the public key is local, the output will be prefixed with ".", the prefix will end with space.
func prefixPublicKey(publicKey string, out io.Writer) secure.KeyWithFilter {
if publicKey == "." {
publicKey = DEFAULT_KEY_NAME + PUB_SUFFIX
}

if publicKey == "" {
_, err := out.Write([]byte("_"))
if err != nil {
Expand Down Expand Up @@ -149,7 +153,7 @@ func extractPublicKey(in io.Reader) secure.KeyWithFilter {
}
default:
return secure.KeyWithFilter{
Key: getKey(DEFAULT_KEY_NAME + ".pub"),
Key: getKey(DEFAULT_KEY_NAME + PUB_SUFFIX),
}
}
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func main() { //nolint: funlen
passphrase := flags.String("s", "", "passphrase to decrypt the private key")

addPublicKey := flags.String("a", "",
`add public key to the beginning of the output, can be a local file path, "@{GITHUB_ID}", or "@{HTTPS_URL}"`)
`add public key to the beginning of the output, can be a local file path,`+
` "@{GITHUB_ID}", "@{HTTPS_URL}, or "." for the default key`)

var publicKeys publicKeysFlag
flags.Var(&publicKeys, "p", `the public keys, each can be a local file path, "@{GITHUB_ID}", or "@{HTTPS_URL}"`)
Expand Down
4 changes: 3 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"golang.org/x/term"
)

const PUB_SUFFIX = ".pub"

func getPublicKeys(paths []string) []secure.KeyWithFilter {
list := []secure.KeyWithFilter{}
for _, p := range paths {
Expand Down Expand Up @@ -111,7 +113,7 @@ func getPublicKey(p string) secure.KeyWithFilter {
}

func pubKeyName(prv string) string {
return prv + ".pub"
return prv + PUB_SUFFIX
}

type publicKeysFlag []string
Expand Down

0 comments on commit a840f3a

Please sign in to comment.