Fix golint warnings

$ golint ./... | grep -v underscore | grep -v ALL_CAPS
internal/fusefrontend_reverse/rfs.go:52:36: exported func NewFS returns unexported type *fusefrontend_reverse.reverseFS, which can be annoying to use
internal/nametransform/raw64_go1.5.go:10:2: exported const HaveRaw64 should have comment (or a comment on this block) or be unexported
This commit is contained in:
Jakob Unterwurzacher 2016-11-10 00:38:01 +01:00
parent 75ebb28a62
commit e7f57695a6
7 changed files with 33 additions and 30 deletions

View File

@ -6,14 +6,14 @@ import (
"github.com/rfjakob/gocryptfs/internal/ctlsock" "github.com/rfjakob/gocryptfs/internal/ctlsock"
) )
var _ ctlsock.Interface = &reverseFS{} // Verify that interface is implemented. var _ ctlsock.Interface = &ReverseFS{} // Verify that interface is implemented.
// EncryptPath implements ctlsock.Backend // EncryptPath implements ctlsock.Backend
func (rfs *reverseFS) EncryptPath(plainPath string) (string, error) { func (rfs *ReverseFS) EncryptPath(plainPath string) (string, error) {
return "", errors.New("Not implemented") return "", errors.New("Not implemented")
} }
// DecryptPath implements ctlsock.Backend // DecryptPath implements ctlsock.Backend
func (rfs *reverseFS) DecryptPath(plainPath string) (string, error) { func (rfs *ReverseFS) DecryptPath(plainPath string) (string, error) {
return rfs.decryptPath(plainPath) return rfs.decryptPath(plainPath)
} }

View File

@ -39,7 +39,7 @@ func initLongnameCache() {
} }
// findLongnameParent converts "gocryptfs.longname.XYZ" to the plaintext name // findLongnameParent converts "gocryptfs.longname.XYZ" to the plaintext name
func (rfs *reverseFS) findLongnameParent(dir string, dirIV []byte, longname string) (plaintextName string, err error) { func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname string) (plaintextName string, err error) {
longnameCacheLock.Lock() longnameCacheLock.Lock()
hit := longnameParentCache[longname] hit := longnameParentCache[longname]
longnameCacheLock.Unlock() longnameCacheLock.Unlock()
@ -78,7 +78,7 @@ func (rfs *reverseFS) findLongnameParent(dir string, dirIV []byte, longname stri
return hit, nil return hit, nil
} }
func (rfs *reverseFS) newNameFile(relPath string) (nodefs.File, fuse.Status) { func (rfs *ReverseFS) newNameFile(relPath string) (nodefs.File, fuse.Status) {
dotName := filepath.Base(relPath) // gocryptfs.longname.XYZ.name dotName := filepath.Base(relPath) // gocryptfs.longname.XYZ.name
longname := dotName[:len(dotName)-len(nametransform.LongNameSuffix)] // gocryptfs.longname.XYZ longname := dotName[:len(dotName)-len(nametransform.LongNameSuffix)] // gocryptfs.longname.XYZ
@ -94,5 +94,5 @@ func (rfs *reverseFS) newNameFile(relPath string) (nodefs.File, fuse.Status) {
} }
content := []byte(rfs.nameTransform.EncryptName(e, dirIV)) content := []byte(rfs.nameTransform.EncryptName(e, dirIV))
parentFile := filepath.Join(rfs.args.Cipherdir, pDir) parentFile := filepath.Join(rfs.args.Cipherdir, pDir)
return rfs.NewVirtualFile(content, parentFile) return rfs.newVirtualFile(content, parentFile)
} }

View File

@ -27,7 +27,7 @@ type reverseFile struct {
contentEnc *contentenc.ContentEnc contentEnc *contentenc.ContentEnc
} }
func (rfs *reverseFS) NewFile(relPath string, flags uint32) (nodefs.File, fuse.Status) { func (rfs *ReverseFS) newFile(relPath string, flags uint32) (nodefs.File, fuse.Status) {
absPath, err := rfs.abs(rfs.decryptPath(relPath)) absPath, err := rfs.abs(rfs.decryptPath(relPath))
if err != nil { if err != nil {
return nil, fuse.ToStatus(err) return nil, fuse.ToStatus(err)

View File

@ -25,7 +25,9 @@ const (
DirIVMode = syscall.S_IFREG | 0400 DirIVMode = syscall.S_IFREG | 0400
) )
type reverseFS struct { // ReverseFS implements the pathfs.FileSystem interface and provides an
// encrypted view of a plaintext directory.
type ReverseFS struct {
// Embed pathfs.defaultFileSystem for a ENOSYS implementation of all methods // Embed pathfs.defaultFileSystem for a ENOSYS implementation of all methods
pathfs.FileSystem pathfs.FileSystem
// pathfs.loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go // pathfs.loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
@ -44,12 +46,12 @@ type reverseFS struct {
inoMapLock sync.Mutex inoMapLock sync.Mutex
} }
var _ pathfs.FileSystem = &reverseFS{} var _ pathfs.FileSystem = &ReverseFS{}
// NewFS returns an encrypted FUSE overlay filesystem. // NewFS returns an encrypted FUSE overlay filesystem.
// In this case (reverse mode) the backing directory is plain-text and // In this case (reverse mode) the backing directory is plain-text and
// reverseFS provides an encrypted view. // ReverseFS provides an encrypted view.
func NewFS(args fusefrontend.Args) *reverseFS { func NewFS(args fusefrontend.Args) *ReverseFS {
if args.CryptoBackend != cryptocore.BackendAESSIV { if args.CryptoBackend != cryptocore.BackendAESSIV {
panic("reverse mode must use AES-SIV, everything else is insecure") panic("reverse mode must use AES-SIV, everything else is insecure")
} }
@ -58,7 +60,7 @@ func NewFS(args fusefrontend.Args) *reverseFS {
contentEnc := contentenc.New(cryptoCore, contentenc.DefaultBS) contentEnc := contentenc.New(cryptoCore, contentenc.DefaultBS)
nameTransform := nametransform.New(cryptoCore, args.LongNames, args.Raw64) nameTransform := nametransform.New(cryptoCore, args.LongNames, args.Raw64)
return &reverseFS{ return &ReverseFS{
// pathfs.defaultFileSystem returns ENOSYS for all operations // pathfs.defaultFileSystem returns ENOSYS for all operations
FileSystem: pathfs.NewDefaultFileSystem(), FileSystem: pathfs.NewDefaultFileSystem(),
loopbackfs: pathfs.NewLoopbackFileSystem(args.Cipherdir), loopbackfs: pathfs.NewLoopbackFileSystem(args.Cipherdir),
@ -82,7 +84,7 @@ func relDir(path string) string {
} }
// dirIVAttr handles GetAttr requests for the virtual gocryptfs.diriv files. // dirIVAttr handles GetAttr requests for the virtual gocryptfs.diriv files.
func (rfs *reverseFS) dirIVAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) { func (rfs *ReverseFS) dirIVAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
cDir := relDir(relPath) cDir := relDir(relPath)
dir, err := rfs.decryptPath(cDir) dir, err := rfs.decryptPath(cDir)
if err != nil { if err != nil {
@ -115,7 +117,7 @@ func (rfs *reverseFS) dirIVAttr(relPath string, context *fuse.Context) (*fuse.At
} }
// isDirIV determines if the path points to a gocryptfs.diriv file // isDirIV determines if the path points to a gocryptfs.diriv file
func (rfs *reverseFS) isDirIV(relPath string) bool { func (rfs *ReverseFS) isDirIV(relPath string) bool {
if rfs.args.PlaintextNames { if rfs.args.PlaintextNames {
return false return false
} }
@ -124,7 +126,7 @@ func (rfs *reverseFS) isDirIV(relPath string) bool {
// isNameFile determines if the path points to a gocryptfs.longname.*.name // isNameFile determines if the path points to a gocryptfs.longname.*.name
// file // file
func (rfs *reverseFS) isNameFile(relPath string) bool { func (rfs *ReverseFS) isNameFile(relPath string) bool {
if rfs.args.PlaintextNames { if rfs.args.PlaintextNames {
return false return false
} }
@ -136,7 +138,7 @@ func (rfs *reverseFS) isNameFile(relPath string) bool {
// and the ciphertext path is "gocryptfs.conf". // and the ciphertext path is "gocryptfs.conf".
// "gocryptfs.conf" then maps to ".gocryptfs.reverse.conf" in the plaintext // "gocryptfs.conf" then maps to ".gocryptfs.reverse.conf" in the plaintext
// directory. // directory.
func (rfs *reverseFS) isTranslatedConfig(relPath string) bool { func (rfs *ReverseFS) isTranslatedConfig(relPath string) bool {
if rfs.args.ConfigCustom { if rfs.args.ConfigCustom {
return false return false
} }
@ -146,7 +148,7 @@ func (rfs *reverseFS) isTranslatedConfig(relPath string) bool {
return false return false
} }
func (rfs *reverseFS) inoAwareStat(relPlainPath string) (*fuse.Attr, fuse.Status) { func (rfs *ReverseFS) inoAwareStat(relPlainPath string) (*fuse.Attr, fuse.Status) {
absPath, err := rfs.abs(relPlainPath, nil) absPath, err := rfs.abs(relPlainPath, nil)
if err != nil { if err != nil {
return nil, fuse.ToStatus(err) return nil, fuse.ToStatus(err)
@ -182,7 +184,7 @@ func (rfs *reverseFS) inoAwareStat(relPlainPath string) (*fuse.Attr, fuse.Status
} }
// GetAttr - FUSE call // GetAttr - FUSE call
func (rfs *reverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) { func (rfs *ReverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
if rfs.isTranslatedConfig(relPath) { if rfs.isTranslatedConfig(relPath) {
return rfs.inoAwareStat(configfile.ConfReverseName) return rfs.inoAwareStat(configfile.ConfReverseName)
} }
@ -224,7 +226,7 @@ func (rfs *reverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr
} }
// Access - FUSE call // Access - FUSE call
func (rfs *reverseFS) Access(relPath string, mode uint32, context *fuse.Context) fuse.Status { func (rfs *ReverseFS) Access(relPath string, mode uint32, context *fuse.Context) fuse.Status {
if rfs.isTranslatedConfig(relPath) { if rfs.isTranslatedConfig(relPath) {
return fuse.OK return fuse.OK
} }
@ -239,7 +241,7 @@ func (rfs *reverseFS) Access(relPath string, mode uint32, context *fuse.Context)
} }
// Open - FUSE call // Open - FUSE call
func (rfs *reverseFS) Open(relPath string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) { func (rfs *ReverseFS) Open(relPath string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
if rfs.isTranslatedConfig(relPath) { if rfs.isTranslatedConfig(relPath) {
return rfs.loopbackfs.Open(configfile.ConfReverseName, flags, context) return rfs.loopbackfs.Open(configfile.ConfReverseName, flags, context)
} }
@ -249,10 +251,10 @@ func (rfs *reverseFS) Open(relPath string, flags uint32, context *fuse.Context)
if rfs.isNameFile(relPath) { if rfs.isNameFile(relPath) {
return rfs.newNameFile(relPath) return rfs.newNameFile(relPath)
} }
return rfs.NewFile(relPath, flags) return rfs.newFile(relPath, flags)
} }
func (rfs *reverseFS) openDirPlaintextnames(relPath string, entries []fuse.DirEntry) ([]fuse.DirEntry, fuse.Status) { func (rfs *ReverseFS) openDirPlaintextnames(relPath string, entries []fuse.DirEntry) ([]fuse.DirEntry, fuse.Status) {
if relPath != "" || rfs.args.ConfigCustom { if relPath != "" || rfs.args.ConfigCustom {
return entries, fuse.OK return entries, fuse.OK
} }
@ -278,7 +280,7 @@ func (rfs *reverseFS) openDirPlaintextnames(relPath string, entries []fuse.DirEn
} }
// OpenDir - FUSE readdir call // OpenDir - FUSE readdir call
func (rfs *reverseFS) OpenDir(cipherPath string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) { func (rfs *ReverseFS) OpenDir(cipherPath string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) {
relPath, err := rfs.decryptPath(cipherPath) relPath, err := rfs.decryptPath(cipherPath)
if err != nil { if err != nil {
return nil, fuse.ToStatus(err) return nil, fuse.ToStatus(err)
@ -329,12 +331,12 @@ func (rfs *reverseFS) OpenDir(cipherPath string, context *fuse.Context) ([]fuse.
} }
// StatFs - FUSE call // StatFs - FUSE call
func (rfs *reverseFS) StatFs(name string) *fuse.StatfsOut { func (rfs *ReverseFS) StatFs(name string) *fuse.StatfsOut {
return rfs.loopbackfs.StatFs(name) return rfs.loopbackfs.StatFs(name)
} }
// Readlink - FUSE call // Readlink - FUSE call
func (rfs *reverseFS) Readlink(cipherPath string, context *fuse.Context) (string, fuse.Status) { func (rfs *ReverseFS) Readlink(cipherPath string, context *fuse.Context) (string, fuse.Status) {
absPath, err := rfs.abs(rfs.decryptPath(cipherPath)) absPath, err := rfs.abs(rfs.decryptPath(cipherPath))
if err != nil { if err != nil {
return "", fuse.ToStatus(err) return "", fuse.ToStatus(err)

View File

@ -36,14 +36,14 @@ func derivePathIV(path string, purpose ivPurposeType) []byte {
return hash[:nametransform.DirIVLen] return hash[:nametransform.DirIVLen]
} }
func (rfs *reverseFS) abs(relPath string, err error) (string, error) { func (rfs *ReverseFS) abs(relPath string, err error) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
return filepath.Join(rfs.args.Cipherdir, relPath), nil return filepath.Join(rfs.args.Cipherdir, relPath), nil
} }
func (rfs *reverseFS) decryptPath(relPath string) (string, error) { func (rfs *ReverseFS) decryptPath(relPath string) (string, error) {
if rfs.args.PlaintextNames || relPath == "" { if rfs.args.PlaintextNames || relPath == "" {
return relPath, nil return relPath, nil
} }

View File

@ -8,13 +8,13 @@ import (
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
) )
func (rfs *reverseFS) newDirIVFile(cRelPath string) (nodefs.File, fuse.Status) { func (rfs *ReverseFS) newDirIVFile(cRelPath string) (nodefs.File, fuse.Status) {
cDir := saneDir(cRelPath) cDir := saneDir(cRelPath)
absDir, err := rfs.abs(rfs.decryptPath(cDir)) absDir, err := rfs.abs(rfs.decryptPath(cDir))
if err != nil { if err != nil {
return nil, fuse.ToStatus(err) return nil, fuse.ToStatus(err)
} }
return rfs.NewVirtualFile(derivePathIV(cDir, ivPurposeDirIV), absDir) return rfs.newVirtualFile(derivePathIV(cDir, ivPurposeDirIV), absDir)
} }
type virtualFile struct { type virtualFile struct {
@ -28,7 +28,7 @@ type virtualFile struct {
ino uint64 ino uint64
} }
func (rfs *reverseFS) NewVirtualFile(content []byte, parentFile string) (nodefs.File, fuse.Status) { func (rfs *ReverseFS) newVirtualFile(content []byte, parentFile string) (nodefs.File, fuse.Status) {
return &virtualFile{ return &virtualFile{
File: nodefs.NewDefaultFile(), File: nodefs.NewDefaultFile(),
content: content, content: content,

View File

@ -7,6 +7,7 @@ import (
) )
const ( const (
// HaveRaw64 is true when Go is new enough to have base64.RawURLEncoding
HaveRaw64 = true HaveRaw64 = true
) )