Run go fmt and go vet

This commit is contained in:
Jakob Unterwurzacher 2015-11-14 17:16:17 +01:00
parent f9c21e91aa
commit 61aacb5c1b
9 changed files with 49 additions and 47 deletions

View File

@ -10,7 +10,7 @@ import "os"
const ( const (
// The dot "." is not used in base64url (RFC4648), hence // The dot "." is not used in base64url (RFC4648), hence
// we can never clash with an encrypted file. // we can never clash with an encrypted file.
ConfDefaultName = "gocryptfs.conf" ConfDefaultName = "gocryptfs.conf"
FlagPlaintextNames = "PlaintextNames" FlagPlaintextNames = "PlaintextNames"
) )
@ -79,12 +79,12 @@ func LoadConfFile(filename string, password string) ([]byte, *ConfFile, error) {
} }
// Verify that we know all feature flags // Verify that we know all feature flags
for _, flag := range(cf.FeatureFlags) { for _, flag := range cf.FeatureFlags {
switch(flag) { switch flag {
case FlagPlaintextNames: case FlagPlaintextNames:
continue continue
default: default:
return nil, nil, fmt.Errorf("Unsupported feature flag %s\n", flag) return nil, nil, fmt.Errorf("Unsupported feature flag %s\n", flag)
} }
} }
@ -151,7 +151,7 @@ func (cf *ConfFile) WriteFile() error {
// isFeatureFlagSet - is the feature flag "flagWant" enabled? // isFeatureFlagSet - is the feature flag "flagWant" enabled?
func (cf *ConfFile) isFeatureFlagSet(flagWant string) bool { func (cf *ConfFile) isFeatureFlagSet(flagWant string) bool {
for _, flag := range(cf.FeatureFlags) { for _, flag := range cf.FeatureFlags {
if flag == flagWant { if flag == flagWant {
return true return true
} }

View File

@ -26,13 +26,13 @@ func TestLoadV2(t *testing.T) {
} }
elapsed := time.Since(t1) elapsed := time.Since(t1)
if elapsed < 100 *time.Millisecond { if elapsed < 100*time.Millisecond {
t.Errorf("scrypt calculation runs too fast: %d ms", elapsed / time.Millisecond) t.Errorf("scrypt calculation runs too fast: %d ms", elapsed/time.Millisecond)
} }
} }
func TestLoadV2PwdError(t *testing.T) { func TestLoadV2PwdError(t *testing.T) {
if ! testing.Verbose() { if !testing.Verbose() {
Warn.Disable() Warn.Disable()
} }
_, _, err := LoadConfFile("config_test/v2.conf", "wrongpassword") _, _, err := LoadConfFile("config_test/v2.conf", "wrongpassword")

View File

@ -57,7 +57,7 @@ func TestCiphertextRange(t *testing.T) {
skipBytes := blocks[0].Skip skipBytes := blocks[0].Skip
if alignedLength < r.length { if alignedLength < r.length {
t.Errorf("alignedLength=%s is smaller than length=%d", alignedLength, r.length) t.Errorf("alignedLength=%d is smaller than length=%d", alignedLength, r.length)
} }
if (alignedOffset-HEADER_LEN)%f.cipherBS != 0 { if (alignedOffset-HEADER_LEN)%f.cipherBS != 0 {
t.Errorf("alignedOffset=%d is not aligned", alignedOffset) t.Errorf("alignedOffset=%d is not aligned", alignedOffset)

View File

@ -47,7 +47,9 @@ func (l *logChannel) Md5sum(buf []byte) string {
// Debug messages // Debug messages
var Debug = logChannel{false} var Debug = logChannel{false}
// Informational message e.g. startup information // Informational message e.g. startup information
var Info = logChannel{true} var Info = logChannel{true}
// A warning, meaning nothing serious by itself but might indicate problems // A warning, meaning nothing serious by itself but might indicate problems
var Warn = logChannel{true} var Warn = logChannel{true}

View File

@ -1,17 +1,19 @@
package integration_tests package integration_tests
import ( import (
"os"
"os/exec"
"fmt"
"io/ioutil"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"fmt"
"io/ioutil"
"os"
"os/exec"
"testing" "testing"
) )
const tmpDir = "/tmp/gocryptfs_main_test/" const tmpDir = "/tmp/gocryptfs_main_test/"
// Mountpoint // Mountpoint
// Note: the code assumes that both have a trailing slash!
const plainDir = tmpDir + "plain/" const plainDir = tmpDir + "plain/"
const cipherDir = tmpDir + "cipher/" const cipherDir = tmpDir + "cipher/"

View File

@ -1,10 +1,10 @@
package integration_tests package integration_tests
import ( import (
"flag"
"bytes" "bytes"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -33,7 +33,6 @@ func TestMain(m *testing.M) {
os.Exit(r) os.Exit(r)
} }
if testing.Verbose() { if testing.Verbose() {
fmt.Printf("***** Testing with native Go crypto\n") fmt.Printf("***** Testing with native Go crypto\n")
} }
@ -278,7 +277,7 @@ func TestFiltered(t *testing.T) {
filteredFile := plainDir + "gocryptfs.conf" filteredFile := plainDir + "gocryptfs.conf"
file, err := os.Create(filteredFile) file, err := os.Create(filteredFile)
if plaintextNames == true && err == nil { if plaintextNames == true && err == nil {
fmt.Errorf("should have failed but didn't") t.Errorf("should have failed but didn't")
} else if plaintextNames == false && err != nil { } else if plaintextNames == false && err != nil {
t.Error(err) t.Error(err)
} }
@ -286,7 +285,7 @@ func TestFiltered(t *testing.T) {
err = os.Remove(filteredFile) err = os.Remove(filteredFile)
if plaintextNames == true && err == nil { if plaintextNames == true && err == nil {
fmt.Errorf("should have failed but didn't") t.Errorf("should have failed but didn't")
} else if plaintextNames == false && err != nil { } else if plaintextNames == false && err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -1,10 +1,10 @@
package integration_tests package integration_tests
import ( import (
"io/ioutil"
"os"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os"
"testing" "testing"
) )

25
main.go
View File

@ -64,11 +64,10 @@ func usageText() {
} }
type argContainer struct { type argContainer struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version, debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames, quiet bool plaintextnames, quiet bool
masterkey, mountpoint, cipherdir string masterkey, mountpoint, cipherdir, cpuprofile string
cpuprofile *string notifypid int
notifypid int
} }
var flagSet *flag.FlagSet var flagSet *flag.FlagSet
@ -88,13 +87,13 @@ func main() {
flagSet.BoolVar(&args.passwd, "passwd", false, "Change password") flagSet.BoolVar(&args.passwd, "passwd", false, "Change password")
flagSet.BoolVar(&args.foreground, "f", false, "Stay in the foreground") flagSet.BoolVar(&args.foreground, "f", false, "Stay in the foreground")
flagSet.BoolVar(&args.version, "version", false, "Print version and exit") flagSet.BoolVar(&args.version, "version", false, "Print version and exit")
flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false, flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false, "Do not encrypt "+
"Do not encrypt file names - can only be used together with -init") "file names - can only be used together with -init")
flagSet.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages") flagSet.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages")
flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key") flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
args.cpuprofile = flagSet.String("cpuprofile", "", "Write cpu profile to specified file") flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file")
flagSet.IntVar(&args.notifypid, "notifypid", 0, flagSet.IntVar(&args.notifypid, "notifypid", 0, "Send USR1 to the specified process after "+
"Send USR1 to the specified process after successful mount - used internally for daemonization") "successful mount - used internally for daemonization")
flagSet.Parse(os.Args[1:]) flagSet.Parse(os.Args[1:])
if args.version { if args.version {
fmt.Printf("%s %s; on-disk format %d\n", PROGRAM_NAME, GitVersion, cryptfs.HEADER_CURRENT_VERSION) fmt.Printf("%s %s; on-disk format %d\n", PROGRAM_NAME, GitVersion, cryptfs.HEADER_CURRENT_VERSION)
@ -106,13 +105,13 @@ func main() {
if !args.foreground { if !args.foreground {
daemonize() // does not return daemonize() // does not return
} }
if *args.cpuprofile != "" { if args.cpuprofile != "" {
f, err := os.Create(*args.cpuprofile) f, err := os.Create(args.cpuprofile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
} }
cryptfs.Info.Printf("Writing CPU profile to %s\n", *args.cpuprofile) cryptfs.Info.Printf("Writing CPU profile to %s\n", args.cpuprofile)
pprof.StartCPUProfile(f) pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }

View File

@ -90,7 +90,7 @@ func (fs *FS) mangleOpenFlags(flags uint32) (newFlags int, writeOnly bool) {
func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) { func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
cryptfs.Debug.Printf("Open(%s)\n", path) cryptfs.Debug.Printf("Open(%s)\n", path)
if fs.CryptFS.IsFiltered(path){ if fs.CryptFS.IsFiltered(path) {
return nil, fuse.EPERM return nil, fuse.EPERM
} }
iflags, writeOnly := fs.mangleOpenFlags(flags) iflags, writeOnly := fs.mangleOpenFlags(flags)
@ -103,7 +103,7 @@ func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile n
} }
func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) { func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) {
if fs.CryptFS.IsFiltered(path){ if fs.CryptFS.IsFiltered(path) {
return nil, fuse.EPERM return nil, fuse.EPERM
} }
iflags, writeOnly := fs.mangleOpenFlags(flags) iflags, writeOnly := fs.mangleOpenFlags(flags)
@ -115,21 +115,21 @@ func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Conte
} }
func (fs *FS) Chmod(path string, mode uint32, context *fuse.Context) (code fuse.Status) { func (fs *FS) Chmod(path string, mode uint32, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(path){ if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Chmod(fs.EncryptPath(path), mode, context) return fs.FileSystem.Chmod(fs.EncryptPath(path), mode, context)
} }
func (fs *FS) Chown(path string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) { func (fs *FS) Chown(path string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(path){ if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Chown(fs.EncryptPath(path), uid, gid, context) return fs.FileSystem.Chown(fs.EncryptPath(path), uid, gid, context)
} }
func (fs *FS) Mknod(name string, mode uint32, dev uint32, context *fuse.Context) (code fuse.Status) { func (fs *FS) Mknod(name string, mode uint32, dev uint32, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(name){ if fs.CryptFS.IsFiltered(name) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Mknod(fs.EncryptPath(name), mode, dev, context) return fs.FileSystem.Mknod(fs.EncryptPath(name), mode, dev, context)
@ -141,7 +141,7 @@ func (fs *FS) Truncate(path string, offset uint64, context *fuse.Context) (code
} }
func (fs *FS) Utimens(path string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) { func (fs *FS) Utimens(path string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(path){ if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Utimens(fs.EncryptPath(path), Atime, Mtime, context) return fs.FileSystem.Utimens(fs.EncryptPath(path), Atime, Mtime, context)
@ -161,14 +161,14 @@ func (fs *FS) Readlink(name string, context *fuse.Context) (out string, status f
} }
func (fs *FS) Mkdir(path string, mode uint32, context *fuse.Context) (code fuse.Status) { func (fs *FS) Mkdir(path string, mode uint32, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(path){ if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Mkdir(fs.EncryptPath(path), mode, context) return fs.FileSystem.Mkdir(fs.EncryptPath(path), mode, context)
} }
func (fs *FS) Unlink(name string, context *fuse.Context) (code fuse.Status) { func (fs *FS) Unlink(name string, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(name){ if fs.CryptFS.IsFiltered(name) {
return fuse.EPERM return fuse.EPERM
} }
cName := fs.EncryptPath(name) cName := fs.EncryptPath(name)
@ -184,7 +184,7 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
} }
func (fs *FS) Symlink(pointedTo string, linkName string, context *fuse.Context) (code fuse.Status) { func (fs *FS) Symlink(pointedTo string, linkName string, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(linkName){ if fs.CryptFS.IsFiltered(linkName) {
return fuse.EPERM return fuse.EPERM
} }
// TODO symlink encryption // TODO symlink encryption
@ -193,21 +193,21 @@ func (fs *FS) Symlink(pointedTo string, linkName string, context *fuse.Context)
} }
func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (code fuse.Status) { func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(newPath){ if fs.CryptFS.IsFiltered(newPath) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Rename(fs.EncryptPath(oldPath), fs.EncryptPath(newPath), context) return fs.FileSystem.Rename(fs.EncryptPath(oldPath), fs.EncryptPath(newPath), context)
} }
func (fs *FS) Link(orig string, newName string, context *fuse.Context) (code fuse.Status) { func (fs *FS) Link(orig string, newName string, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(newName){ if fs.CryptFS.IsFiltered(newName) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Link(fs.EncryptPath(orig), fs.EncryptPath(newName), context) return fs.FileSystem.Link(fs.EncryptPath(orig), fs.EncryptPath(newName), context)
} }
func (fs *FS) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) { func (fs *FS) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
if fs.CryptFS.IsFiltered(name){ if fs.CryptFS.IsFiltered(name) {
return fuse.EPERM return fuse.EPERM
} }
return fs.FileSystem.Access(fs.EncryptPath(name), mode, context) return fs.FileSystem.Access(fs.EncryptPath(name), mode, context)