-
Notifications
You must be signed in to change notification settings - Fork 2
/
synocrypto.go
76 lines (58 loc) · 2.24 KB
/
synocrypto.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
74
75
76
package synocrypto
import (
"io"
"github.com/maxlaverse/synocrypto/pkg/log"
)
// SetLogger allows to collect additional information through the `log.Logger` interface.
func SetLogger(l log.Logger) {
log.SetLogger(l)
}
// Decrypter is a generic interface for decryption
type Decrypter interface {
Decrypt(f io.Reader, w io.Writer) error
Metadata(f io.Reader) (map[string]interface{}, error)
}
// DecrypterOptions holds the options that can be used for decryption
type DecrypterOptions struct {
// Password used in the setup of Cloud Sync encryption task.
Password string
// PrivateKey automatically exported setting up a Cloud Sync encryption task for the first
// time. It's usually named 'private.pem' in the exported key file.
PrivateKey []byte
// UseExternalLz4Decompressor enables decrompression using an external `lz4` command that must
// be installed separately.
UseExternalLz4Decompressor bool
// IgnoreChecksumMismatch prints
IgnoreChecksumMismatch bool
}
// NewDecrypter returns a new decrypter
func NewDecrypter(opts DecrypterOptions) Decrypter {
return &decrypter{options: opts}
}
// Encrypter is a generic interface for encryption
type Encrypter interface {
Encrypt(f io.Reader, w io.Writer) error
}
type EncrypterOptions struct {
// Password used in the setup of Cloud Sync encryption task.
Password string
// PrivateKey automatically exported setting up a Cloud Sync encryption task for the first
// time. It's usually named 'private.pem' in the exported key file.
PrivateKey []byte
// UseExternalLz4Decompressor enables crompression using an external `lz4` command that must
// be installed separately.
UseExternalLz4Compressor bool
// Filename is the name for the file to be added in the metadata
Filename string
// DisableCompression allows to disable compression. This is not supported by DMS
// which tries to decompress the data anyway and fails.
DisableCompression bool
// DisableDigestGeneration allows to disable the md5 checksum computation.
DisableDigestGeneration bool
// DisableIntegrityCheck disables the check that what was encrypted can be decrypted.
DisableIntegrityCheck bool
}
// NewEncrypter returns a new encrypter
func NewEncrypter(opts EncrypterOptions) Encrypter {
return &encrypter{options: opts}
}