From b48f1f2c372d1fa7bca155c449c590d852a03511 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Tue, 26 Sep 2017 21:33:50 +0200 Subject: Add cloudstorage support For now Openstack Swift is supported. But it should be pretty easy to implement other Swift / S3 like object storages. --- gpg/gpg.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'gpg') 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 +} -- cgit v1.2.3-70-g09d2