aboutsummaryrefslogtreecommitdiffstats
path: root/internal/build/pgp.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-11-03 00:21:05 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-11-03 16:32:53 +0800
commit3b62c145f8d699767e13770d1bb21d07c2ba9b46 (patch)
tree341fbd27e33b08431a6b950f009d6230d502fd3e /internal/build/pgp.go
parent1b73c79234a1597f1f8b11cff5e01b935f6817a2 (diff)
downloaddexon-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar
dexon-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.gz
dexon-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.bz2
dexon-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.lz
dexon-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.xz
dexon-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.zst
dexon-3b62c145f8d699767e13770d1bb21d07c2ba9b46.zip
travis, build: implement uploading archives to azure
Diffstat (limited to 'internal/build/pgp.go')
-rw-r--r--internal/build/pgp.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/build/pgp.go b/internal/build/pgp.go
new file mode 100644
index 000000000..cc60d64fb
--- /dev/null
+++ b/internal/build/pgp.go
@@ -0,0 +1,58 @@
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
+
+// signFile reads the contents of an input file and signs it (in armored format)
+// with the key provided, placing the signature into the output file.
+
+package build
+
+import (
+ "bytes"
+ "fmt"
+ "os"
+
+ "golang.org/x/crypto/openpgp"
+)
+
+// PGPSignFile parses a PGP private key from the specified string and creates a
+// signature file into the output parameter of the input file.
+//
+// Note, this method assumes a single key will be container in the pgpkey arg,
+// furthermore that it is in armored format.
+func PGPSignFile(input string, output string, pgpkey string) error {
+ // Parse the keyring and make sure we only have a single private key in it
+ keys, err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(pgpkey))
+ if err != nil {
+ return err
+ }
+ if len(keys) != 1 {
+ return fmt.Errorf("key count mismatch: have %d, want %d", len(keys), 1)
+ }
+ // Create the input and output streams for signing
+ in, err := os.Open(input)
+ if err != nil {
+ return err
+ }
+ defer in.Close()
+
+ out, err := os.Create(output)
+ if err != nil {
+ return err
+ }
+ defer out.Close()
+
+ // Generate the signature and return
+ return openpgp.ArmoredDetachSignText(out, keys[0], in, nil)
+}