aboutsummaryrefslogtreecommitdiff
path: root/pathfs_frontend/names.go
blob: 122b3ddd539080189838b666128997b013c08d29 (plain)
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
package pathfs_frontend

// This file forwards file encryption operations to cryptfs

import (
	"github.com/rfjakob/gocryptfs/cryptfs"
)

func (fs *FS) encryptPath(plainPath string) (string, error) {
	if !fs.dirIV {
		return fs.CryptFS.TranslatePathZeroIV(plainPath, cryptfs.OpEncrypt)
	}
	fs.dirIVLock.RLock()
	defer fs.dirIVLock.RUnlock()
	return fs.CryptFS.EncryptPathDirIV(plainPath, fs.backingDir)
}

func (fs *FS) decryptPath(cipherPath string) (string, error) {
	if !fs.dirIV {
		return fs.CryptFS.TranslatePathZeroIV(cipherPath, cryptfs.OpDecrypt)
	}
	fs.dirIVLock.RLock()
	defer fs.dirIVLock.RUnlock()
	return fs.CryptFS.DecryptPathDirIV(cipherPath, fs.backingDir)
}