diff options
author | Jakob Unterwurzacher | 2016-08-25 00:14:36 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-09-25 16:43:17 +0200 |
commit | 9237b4f53e13075b595131f68edcfb2c831d684e (patch) | |
tree | cba9163085dfb18ca8db4c62ca71c24bd6ff804b /internal/fusefrontend_reverse/rpath.go | |
parent | f6d4d240e6e17f8052cdecd11533a1e24b339985 (diff) |
reverse: add skeleton
Compiles but does not do much else.
Diffstat (limited to 'internal/fusefrontend_reverse/rpath.go')
-rw-r--r-- | internal/fusefrontend_reverse/rpath.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/fusefrontend_reverse/rpath.go b/internal/fusefrontend_reverse/rpath.go new file mode 100644 index 0000000..9377958 --- /dev/null +++ b/internal/fusefrontend_reverse/rpath.go @@ -0,0 +1,56 @@ +package fusefrontend_reverse + +import ( + "path/filepath" + "strings" +) + +func (fs *FS) abs(relPath string, err error) (string, error) { + if err != nil { + return "", err + } + return filepath.Join(fs.args.Cipherdir, relPath), nil +} + +const ( + ENCRYPT = iota + DECRYPT +) + +func (fs *FS) encryptPath(relPath string) (string, error) { + return fs.transformPath(relPath, ENCRYPT) +} + +func (fs *FS) decryptPath(relPath string) (string, error) { + return fs.transformPath(relPath, DECRYPT) +} + +func (fs *FS) transformPath(relPath string, direction int) (string, error) { + if fs.args.PlaintextNames { + return relPath, nil + } + var err error + var transformedParts []string + iv := make([]byte, 16) + parts := strings.Split(relPath, "/") + for _, part := range parts { + var transformedPart string + switch direction { + case ENCRYPT: + transformedPart = fs.nameTransform.EncryptName(part, iv) + case DECRYPT: + transformedPart, err = fs.nameTransform.DecryptName(part, iv) + if err != nil { + return "", err + } + default: + panic("bug: invalid direction value") + } + transformedParts = append(transformedParts, transformedPart) + } + return filepath.Join(transformedParts...), nil +} + +func (fs *FS) isFiltered(relPath string) bool { + return false +} |