-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpackage.go
44 lines (40 loc) · 1.25 KB
/
package.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
// Package enigma implements the simple encrypted filesystem.
//
// The filesystem is specified a block cipher which is used to
// encrypt the subcipher of the filesystem. The subcipher is
// then used to encrypt the file names and data. The path of
// each file is taken into consideration while generating nonce.
//
// Thanks to the CTR mode, the size of each files is the same
// size as their plain text one, and supports random access.
//
// For nonce generation, a crypto random nonce will be generated
// for encrypting the cipher, while file names will have their
// corresponding nonce generated in a deterministic process. The
// file will be encrypted by their file names, which means each
// file must be re-encrypted when it is renamed.
package enigma
import (
"io/fs"
"github.com/pkg/errors"
)
// cleanPathError is intended for cleaning path errors for
// both file system and file implementations.
func cleansePathError(name string, err error) error {
if err == nil {
return nil
}
var pathError *fs.PathError
if errors.As(err, &pathError) {
pathError.Path = name
}
return err
}
// pathError constructs and create the path error.
func pathError(op, name string, err error) error {
return &fs.PathError{
Op: op,
Path: name,
Err: err,
}
}