/
loader.go
50 lines (38 loc) · 923 Bytes
/
loader.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
package age
import (
"context"
"fmt"
"github.com/gopasspw/gopass/internal/backend"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/debug"
)
const (
name = "age"
)
func init() {
backend.CryptoRegistry.Register(backend.Age, name, &loader{})
}
type loader struct{}
func (l loader) New(ctx context.Context) (backend.Crypto, error) {
debug.Log("Using Crypto Backend: %s", name)
return New(ctx)
}
func (l loader) Handles(ctx context.Context, s backend.Storage) error {
if s.Exists(ctx, OldIDFile) || s.Exists(ctx, OldKeyring) {
if err := migrate(ctx, s); err != nil {
out.Errorf(ctx, "Failed to migrate age backend: %s", err)
}
out.OKf(ctx, "Migrated age backend to new format")
return nil
}
if s.Exists(ctx, IDFile) {
return nil
}
return fmt.Errorf("not supported")
}
func (l loader) Priority() int {
return 10
}
func (l loader) String() string {
return name
}