diff --git a/README.md b/README.md index 9359907..6797e40 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/agent.go b/agent.go index 0160d96..daa246c 100644 --- a/agent.go +++ b/agent.go @@ -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 { @@ -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), } } } diff --git a/main.go b/main.go index 3f98e0f..e70f2fb 100644 --- a/main.go +++ b/main.go @@ -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}"`) diff --git a/utils.go b/utils.go index 8e53e19..7a349c7 100644 --- a/utils.go +++ b/utils.go @@ -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 { @@ -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