v2api: implement ctlsocksrv.Interface
This commit is contained in:
parent
57d572dbc1
commit
7eae35e2d3
@ -13,17 +13,17 @@ import (
|
|||||||
"github.com/rfjakob/gocryptfs/internal/tlog"
|
"github.com/rfjakob/gocryptfs/internal/tlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ ctlsocksrv.Interface = &FS{} // Verify that interface is implemented.
|
var _ ctlsocksrv.Interface = &RootNode{} // Verify that interface is implemented.
|
||||||
|
|
||||||
// EncryptPath implements ctlsock.Backend
|
// EncryptPath implements ctlsock.Backend
|
||||||
//
|
//
|
||||||
// Symlink-safe through openBackingDir().
|
// Symlink-safe through openBackingDir().
|
||||||
func (fs *FS) EncryptPath(plainPath string) (string, error) {
|
func (rn *RootNode) EncryptPath(plainPath string) (string, error) {
|
||||||
if plainPath == "" {
|
if plainPath == "" {
|
||||||
// Empty string gets encrypted as empty string
|
// Empty string gets encrypted as empty string
|
||||||
return plainPath, nil
|
return plainPath, nil
|
||||||
}
|
}
|
||||||
if fs.args.PlaintextNames {
|
if rn.args.PlaintextNames {
|
||||||
return plainPath, nil
|
return plainPath, nil
|
||||||
}
|
}
|
||||||
// Encrypt path level by level using openBackingDir. Pretty inefficient,
|
// Encrypt path level by level using openBackingDir. Pretty inefficient,
|
||||||
@ -33,7 +33,7 @@ func (fs *FS) EncryptPath(plainPath string) (string, error) {
|
|||||||
cPath := ""
|
cPath := ""
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
wd = filepath.Join(wd, part)
|
wd = filepath.Join(wd, part)
|
||||||
dirfd, cName, err := fs.openBackingDir(wd)
|
dirfd, cName, err := rn.openBackingDir(wd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -48,20 +48,20 @@ func (fs *FS) EncryptPath(plainPath string) (string, error) {
|
|||||||
//
|
//
|
||||||
// DecryptPath is symlink-safe because openBackingDir() and decryptPathAt()
|
// DecryptPath is symlink-safe because openBackingDir() and decryptPathAt()
|
||||||
// are symlink-safe.
|
// are symlink-safe.
|
||||||
func (fs *FS) DecryptPath(cipherPath string) (plainPath string, err error) {
|
func (rn *RootNode) DecryptPath(cipherPath string) (plainPath string, err error) {
|
||||||
dirfd, _, err := fs.openBackingDir("")
|
dirfd, _, err := rn.openBackingDir("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer syscall.Close(dirfd)
|
defer syscall.Close(dirfd)
|
||||||
return fs.decryptPathAt(dirfd, cipherPath)
|
return rn.decryptPathAt(dirfd, cipherPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// decryptPathAt decrypts a ciphertext path relative to dirfd.
|
// decryptPathAt decrypts a ciphertext path relative to dirfd.
|
||||||
//
|
//
|
||||||
// Symlink-safe through ReadDirIVAt() and ReadLongNameAt().
|
// Symlink-safe through ReadDirIVAt() and ReadLongNameAt().
|
||||||
func (fs *FS) decryptPathAt(dirfd int, cipherPath string) (plainPath string, err error) {
|
func (rn *RootNode) decryptPathAt(dirfd int, cipherPath string) (plainPath string, err error) {
|
||||||
if fs.args.PlaintextNames || cipherPath == "" {
|
if rn.args.PlaintextNames || cipherPath == "" {
|
||||||
return cipherPath, nil
|
return cipherPath, nil
|
||||||
}
|
}
|
||||||
parts := strings.Split(cipherPath, "/")
|
parts := strings.Split(cipherPath, "/")
|
||||||
@ -80,7 +80,7 @@ func (fs *FS) decryptPathAt(dirfd int, cipherPath string) (plainPath string, err
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name, err := fs.nameTransform.DecryptName(longPart, dirIV)
|
name, err := rn.nameTransform.DecryptName(longPart, dirIV)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("DecryptName: %v\n", err)
|
fmt.Printf("DecryptName: %v\n", err)
|
||||||
return "", err
|
return "", err
|
||||||
|
Loading…
Reference in New Issue
Block a user