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

View File

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

View File

@ -57,7 +57,7 @@ func TestCiphertextRange(t *testing.T) {
skipBytes := blocks[0].Skip
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 {
t.Errorf("alignedOffset=%d is not aligned", alignedOffset)

View File

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

View File

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

View File

@ -1,10 +1,10 @@
package integration_tests
import (
"flag"
"bytes"
"crypto/md5"
"encoding/hex"
"flag"
"fmt"
"io/ioutil"
"os"
@ -33,7 +33,6 @@ func TestMain(m *testing.M) {
os.Exit(r)
}
if testing.Verbose() {
fmt.Printf("***** Testing with native Go crypto\n")
}
@ -278,7 +277,7 @@ func TestFiltered(t *testing.T) {
filteredFile := plainDir + "gocryptfs.conf"
file, err := os.Create(filteredFile)
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 {
t.Error(err)
}
@ -286,7 +285,7 @@ func TestFiltered(t *testing.T) {
err = os.Remove(filteredFile)
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 {
t.Error(err)
}

View File

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

25
main.go
View File

@ -64,11 +64,10 @@ func usageText() {
}
type argContainer struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames, quiet bool
masterkey, mountpoint, cipherdir string
cpuprofile *string
notifypid int
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames, quiet bool
masterkey, mountpoint, cipherdir, cpuprofile string
notifypid int
}
var flagSet *flag.FlagSet
@ -88,13 +87,13 @@ func main() {
flagSet.BoolVar(&args.passwd, "passwd", false, "Change password")
flagSet.BoolVar(&args.foreground, "f", false, "Stay in the foreground")
flagSet.BoolVar(&args.version, "version", false, "Print version and exit")
flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false,
"Do not encrypt file names - can only be used together with -init")
flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false, "Do not encrypt "+
"file names - can only be used together with -init")
flagSet.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages")
flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
args.cpuprofile = flagSet.String("cpuprofile", "", "Write cpu profile to specified file")
flagSet.IntVar(&args.notifypid, "notifypid", 0,
"Send USR1 to the specified process after successful mount - used internally for daemonization")
flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file")
flagSet.IntVar(&args.notifypid, "notifypid", 0, "Send USR1 to the specified process after "+
"successful mount - used internally for daemonization")
flagSet.Parse(os.Args[1:])
if args.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 {
daemonize() // does not return
}
if *args.cpuprofile != "" {
f, err := os.Create(*args.cpuprofile)
if args.cpuprofile != "" {
f, err := os.Create(args.cpuprofile)
if err != nil {
fmt.Println(err)
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)
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) {
cryptfs.Debug.Printf("Open(%s)\n", path)
if fs.CryptFS.IsFiltered(path){
if fs.CryptFS.IsFiltered(path) {
return nil, fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(path){
if fs.CryptFS.IsFiltered(path) {
return nil, fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(path){
if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(path){
if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(name){
if fs.CryptFS.IsFiltered(name) {
return fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(path){
if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(path){
if fs.CryptFS.IsFiltered(path) {
return fuse.EPERM
}
return fs.FileSystem.Mkdir(fs.EncryptPath(path), mode, context)
}
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
}
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) {
if fs.CryptFS.IsFiltered(linkName){
if fs.CryptFS.IsFiltered(linkName) {
return fuse.EPERM
}
// 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) {
if fs.CryptFS.IsFiltered(newPath){
if fs.CryptFS.IsFiltered(newPath) {
return fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(newName){
if fs.CryptFS.IsFiltered(newName) {
return fuse.EPERM
}
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) {
if fs.CryptFS.IsFiltered(name){
if fs.CryptFS.IsFiltered(name) {
return fuse.EPERM
}
return fs.FileSystem.Access(fs.EncryptPath(name), mode, context)