2015-11-27 00:03:10 +01:00
|
|
|
package pathfs_frontend
|
|
|
|
|
2015-11-27 23:34:55 +01:00
|
|
|
// This file forwards file encryption operations to cryptfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rfjakob/gocryptfs/cryptfs"
|
|
|
|
)
|
2015-11-27 00:03:10 +01:00
|
|
|
|
|
|
|
func (fs *FS) encryptPath(plainPath string) (string, error) {
|
2015-11-27 23:34:55 +01:00
|
|
|
if !fs.dirIV {
|
|
|
|
return fs.CryptFS.TranslatePathZeroIV(plainPath, cryptfs.OpEncrypt)
|
|
|
|
}
|
2015-11-27 21:48:58 +01:00
|
|
|
fs.dirIVLock.RLock()
|
|
|
|
defer fs.dirIVLock.RUnlock()
|
2015-11-27 00:03:10 +01:00
|
|
|
return fs.CryptFS.EncryptPathDirIV(plainPath, fs.backingDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) decryptPath(cipherPath string) (string, error) {
|
2015-11-27 23:34:55 +01:00
|
|
|
if !fs.dirIV {
|
|
|
|
return fs.CryptFS.TranslatePathZeroIV(cipherPath, cryptfs.OpDecrypt)
|
|
|
|
}
|
2015-11-27 21:48:58 +01:00
|
|
|
fs.dirIVLock.RLock()
|
|
|
|
defer fs.dirIVLock.RUnlock()
|
2015-11-27 00:03:10 +01:00
|
|
|
return fs.CryptFS.DecryptPathDirIV(cipherPath, fs.backingDir)
|
|
|
|
}
|