aboutsummaryrefslogtreecommitdiff
path: root/sign_input.go
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2016-10-01 21:56:29 +0200
committerGibheer <gibheer+git@zero-knowledge.org>2016-10-01 21:56:29 +0200
commitd01892150eed9d58210eb40b7c005d5fa8e93238 (patch)
treef9d37f3d5b4f0d9afd01755801826713f47d83c3 /sign_input.go
parentfaaf7d8859895767b5e64d32c14d561d6fdb5a14 (diff)
rework program flow
This commit is a complete rebuild of pkictl. Before everything was all over the place and adding new commands was kind of a hassle. Now each command has its own file and can be adjusted on a command basis. Options are still used by the same name, but can now use different descriptions.
Diffstat (limited to 'sign_input.go')
-rw-r--r--sign_input.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/sign_input.go b/sign_input.go
new file mode 100644
index 0000000..e2c2320
--- /dev/null
+++ b/sign_input.go
@@ -0,0 +1,50 @@
+package main
+
+import (
+ "crypto"
+ "encoding/base64"
+ "flag"
+ "io"
+ "io/ioutil"
+)
+
+func SignInput(args []string) error {
+ fs := flag.NewFlagSet("pkictl sign-input", flag.ExitOnError)
+ flagPrivate := fs.String("private-key", "", "path to the private key or read from stdin")
+ flagInput := fs.String("input", "stdin", "path to the message to sign or stdin")
+ flagOutput := fs.String("output", "stdout", "write private key to file")
+ fs.Parse(args)
+
+ pk, err := loadPrivateKey(*flagPrivate)
+ if err != nil {
+ return err
+ }
+
+ out, err := openOutput(*flagOutput)
+ if err != nil {
+ return err
+ }
+ defer out.Close()
+
+ in, err := openInput(*flagInput)
+ if err != nil {
+ return err
+ }
+ defer in.Close()
+
+ message, err := ioutil.ReadAll(in)
+ if err != nil {
+ return err
+ }
+
+ signature, err := pk.Sign(message, crypto.SHA256)
+ if err != nil {
+ return err
+ }
+
+ _, err = io.WriteString(out, base64.StdEncoding.EncodeToString(signature))
+ if err != nil {
+ return err
+ }
+ return nil
+}