diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-05-12 23:56:07 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-12 23:56:07 -0400 |
commit | 38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8 (patch) | |
tree | a4fde09672192b97d453ad605b030bd5a10c5a45 /vendor/github.com/mattermost/rsc/cmd/crypt | |
parent | 84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (diff) | |
download | chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.gz chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.bz2 chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.zip |
Moving to glide
Diffstat (limited to 'vendor/github.com/mattermost/rsc/cmd/crypt')
-rw-r--r-- | vendor/github.com/mattermost/rsc/cmd/crypt/crypt.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/rsc/cmd/crypt/crypt.go b/vendor/github.com/mattermost/rsc/cmd/crypt/crypt.go new file mode 100644 index 000000000..4a2150540 --- /dev/null +++ b/vendor/github.com/mattermost/rsc/cmd/crypt/crypt.go @@ -0,0 +1,79 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Crypt is a simple password-based encryption program, +// demonstrating how to use github.com/mattermost/rsc/crypt. +// +// Encrypt input to output using password: +// crypt password <input >output +// +// Decrypt input to output using password: +// crypt -d password <input >output +// +// Yes, the password is a command-line argument. This is a demo of the +// github.com/mattermost/rsc/crypt package. It's not intended for real use. +// +package main + +import ( + "encoding/base64" + "fmt" + "io/ioutil" + "os" + "strings" + + "github.com/mattermost/rsc/crypt" +) + +func main() { + args := os.Args[1:] + encrypt := true + if len(args) >= 1 && args[0] == "-d" { + encrypt = false + args = args[1:] + } + if len(args) != 1 || strings.HasPrefix(args[0], "-") { + fmt.Fprintf(os.Stderr, "usage: crypt [-d] password < input > output\n") + os.Exit(2) + } + password := args[0] + + data, err := ioutil.ReadAll(os.Stdin) + if err != nil { + fmt.Fprintf(os.Stderr, "reading stdin: %v\n", err) + os.Exit(1) + } + if encrypt { + pkt, err := crypt.Encrypt(password, data) + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } + str := base64.StdEncoding.EncodeToString(pkt) + for len(str) > 60 { + fmt.Printf("%s\n", str[:60]) + str = str[60:] + } + fmt.Printf("%s\n", str) + } else { + pkt, err := base64.StdEncoding.DecodeString(strings.Map(noSpace, string(data))) + if err != nil { + fmt.Fprintf(os.Stderr, "decoding input: %v\n", err) + os.Exit(1) + } + dec, err := crypt.Decrypt(password, pkt) + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } + os.Stdout.Write(dec) + } +} + +func noSpace(r rune) rune { + if r == ' ' || r == '\t' || r == '\n' { + return -1 + } + return r +} |