Skip to content

Commit

Permalink
Add a flag to trim whitespace when encrypting
Browse files Browse the repository at this point in the history
  • Loading branch information
rbvigilante committed Nov 29, 2019
1 parent 279a408 commit 2c67541
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Plaintext input can also be provided on the command-line, e.g.

shush encrypt KEY-ID 'this is a secret' > secret.encrypted

With the `-t` or `--trim` flag, `encrypt` will automatically remove leading and trailing whitespace from the plaintext. This can be especially useful when piping input from commands which always leave a trailing newline.

shush encrypt -t KEY_ID ' I don't really need this whitespace ' > secret.encrypted

### Decrypting things

Encrypted secrets are easy to decrypt, like this:
Expand All @@ -30,7 +34,7 @@ There's no need to specify a KEY-ID here, as it's encoded in the ciphertext.

Appropriate AWS credentials must be provided by one of the [mechanisms supported by aws-sdk-go](https://github.com/aws/aws-sdk-go/wiki/Getting-Started-Credentials), e.g. environment variables, or EC2 instance profile.

When used within EC2, `shush` selects the appropriate region automatically.
When used within EC2, `shush` selects the appropriate region automatically.
Outside EC2, you'll need to specify it, via `--region` or by setting `$AWS_DEFAULT_REGION`.

### Encryption context
Expand Down Expand Up @@ -81,7 +85,7 @@ Binaries for official releases may be downloaded from the [releases page on GitH
If you want to compile it from source, try:

$ go get github.com/realestate-com-au/shush

For Unix/Linux users, you can install `shush` using the following command. You may want to change the version number in the command below from `v1.3.4` to whichever version you want:

```
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func main() {
{
Name: "encrypt",
Usage: "Encrypt with a KMS key",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "trim, t",
Usage: "If set, remove leading and trailing whitespace from plaintext",
},
},
Action: func(c *cli.Context) {
if len(c.Args()) == 0 {
sys.Abort(sys.UsageError, "no key specified")
Expand All @@ -50,6 +56,9 @@ func main() {
if err != nil {
sys.Abort(sys.UsageError, err)
}
if(c.Bool("trim")) {
plaintext = strings.TrimSpace(plaintext)
}
ciphertext, err := handle.Encrypt(plaintext, key)
if err != nil {
sys.Abort(sys.KmsError, err)
Expand Down

0 comments on commit 2c67541

Please sign in to comment.