aboutsummaryrefslogtreecommitdiff
path: root/gpg
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2017-09-26 21:33:50 +0200
committerLaria Carolin Chabowski <laria@laria.me>2017-10-03 15:01:38 +0200
commitb48f1f2c372d1fa7bca155c449c590d852a03511 (patch)
tree29d468067d6381fdb3a810c9f05dde8daccc06df /gpg
parentb2742dc28d1ff9001cd784455bbdf9cf29539c30 (diff)
downloadpetrific-b48f1f2c372d1fa7bca155c449c590d852a03511.tar.gz
petrific-b48f1f2c372d1fa7bca155c449c590d852a03511.tar.bz2
petrific-b48f1f2c372d1fa7bca155c449c590d852a03511.zip
Add cloudstorage support
For now Openstack Swift is supported. But it should be pretty easy to implement other Swift / S3 like object storages.
Diffstat (limited to 'gpg')
-rw-r--r--gpg/gpg.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/gpg/gpg.go b/gpg/gpg.go
index 4639ae2..1ab71ec 100644
--- a/gpg/gpg.go
+++ b/gpg/gpg.go
@@ -12,10 +12,7 @@ type Signer struct {
Key string
}
-// Sign signs a message b with the key s.Key
-func (s Signer) Sign(b []byte) ([]byte, error) {
- cmd := exec.Command("gpg", "--clearsign", "-u", s.Key)
-
+func filter(cmd *exec.Cmd, b []byte) ([]byte, error) {
cmd.Stdin = bytes.NewReader(b)
var out bytes.Buffer
cmd.Stdout = &out
@@ -24,6 +21,12 @@ func (s Signer) Sign(b []byte) ([]byte, error) {
return out.Bytes(), err
}
+// Sign signs a message b with the key s.Key
+func (s Signer) Sign(b []byte) ([]byte, error) {
+ cmd := exec.Command("gpg", "--clearsign", "-u", s.Key)
+ return filter(cmd, b)
+}
+
// Verifyer implements objects.Verifyer using gpg
type Verifyer struct{}
@@ -33,3 +36,24 @@ func (Verifyer) Verify(b []byte) error {
cmd.Stdin = bytes.NewReader(b)
return cmd.Run()
}
+
+type Encrypter struct {
+ Key string
+}
+
+func (e Encrypter) Encrypt(b []byte) ([]byte, error) {
+ cmd := exec.Command("gpg", "--encrypt", "--recipient", e.Key)
+ return filter(cmd, b)
+}
+
+type Decrypter struct{}
+
+func (Decrypter) Decrypt(b []byte) ([]byte, error) {
+ cmd := exec.Command("gpg", "--decrypt")
+ return filter(cmd, b)
+}
+
+type Crypter struct {
+ Encrypter
+ Decrypter
+}