forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpg.go
73 lines (59 loc) · 1.78 KB
/
gpg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package mock
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"github.com/blang/semver"
"github.com/justwatchcom/gopass/backend/gpg"
"github.com/pkg/errors"
)
// Mocker is a no-op GPG mock
type Mocker struct{}
// New creates a new GPG mock
func New() *Mocker {
return &Mocker{}
}
// ListPublicKeys does nothing
func (m *Mocker) ListPublicKeys(context.Context) (gpg.KeyList, error) {
return gpg.KeyList{}, nil
}
// FindPublicKeys does nothing
func (m *Mocker) FindPublicKeys(context.Context, ...string) (gpg.KeyList, error) {
return gpg.KeyList{}, nil
}
// ListPrivateKeys does nothing
func (m *Mocker) ListPrivateKeys(context.Context) (gpg.KeyList, error) {
return gpg.KeyList{}, nil
}
// FindPrivateKeys does nothing
func (m *Mocker) FindPrivateKeys(context.Context, ...string) (gpg.KeyList, error) {
return gpg.KeyList{}, nil
}
// GetRecipients does nothing
func (m *Mocker) GetRecipients(context.Context, string) ([]string, error) {
return []string{}, nil
}
// Encrypt writes the input to disk unaltered
func (m *Mocker) Encrypt(ctx context.Context, path string, content []byte, recipients []string) error {
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
return errors.Wrapf(err, "failed to create dir '%s'", path)
}
return ioutil.WriteFile(path, content, 0600)
}
// Decrypt read the file from disk unaltered
func (m *Mocker) Decrypt(ctx context.Context, path string) ([]byte, error) {
return ioutil.ReadFile(path)
}
// ExportPublicKey does nothing
func (m *Mocker) ExportPublicKey(context.Context, string, string) error {
return nil
}
// ImportPublicKey does nothing
func (m *Mocker) ImportPublicKey(context.Context, string) error {
return nil
}
// Version returns dummy version info
func (m *Mocker) Version(context.Context) semver.Version {
return semver.Version{}
}