configfile: reduce function name stutter
configfile.LoadConfFile() -> configfile.Load() configfile.CreateConfFile() -> configfile.Create()
This commit is contained in:
parent
8e5ca7299a
commit
91de77943f
@ -61,7 +61,7 @@ func main() {
|
||||
func dumpMasterKey(fn string) {
|
||||
tlog.Info.Enabled = false
|
||||
pw := readpassword.Once("", "")
|
||||
masterkey, _, err := configfile.LoadConfFile(fn, pw)
|
||||
masterkey, _, err := configfile.Load(fn, pw)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
exitcodes.Exit(err)
|
||||
|
@ -79,7 +79,7 @@ func initDir(args *argContainer) {
|
||||
readpassword.CheckTrailingGarbage()
|
||||
}
|
||||
creator := tlog.ProgramName + " " + GitVersion
|
||||
err = configfile.CreateConfFile(args.config, password, args.plaintextnames,
|
||||
err = configfile.Create(args.config, password, args.plaintextnames,
|
||||
args.scryptn, creator, args.aessiv, args.devrandom, args.trezor)
|
||||
if err != nil {
|
||||
tlog.Fatal.Println(err)
|
||||
|
@ -64,10 +64,10 @@ func randBytesDevRandom(n int) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
// CreateConfFile - create a new config with a random key encrypted with
|
||||
// Create - create a new config with a random key encrypted with
|
||||
// "password" and write it to "filename".
|
||||
// Uses scrypt with cost parameter logN.
|
||||
func CreateConfFile(filename string, password []byte, plaintextNames bool,
|
||||
func Create(filename string, password []byte, plaintextNames bool,
|
||||
logN int, creator string, aessiv bool, devrandom bool, trezor bool) error {
|
||||
var cf ConfFile
|
||||
cf.filename = filename
|
||||
@ -112,13 +112,13 @@ func CreateConfFile(filename string, password []byte, plaintextNames bool,
|
||||
return cf.WriteFile()
|
||||
}
|
||||
|
||||
// LoadConfFile - read config file from disk and decrypt the
|
||||
// Load - read config file from disk and decrypt the
|
||||
// contained key using "password".
|
||||
// Returns the decrypted key and the ConfFile object
|
||||
//
|
||||
// If "password" is empty, the config file is read
|
||||
// but the key is not decrypted (returns nil in its place).
|
||||
func LoadConfFile(filename string, password []byte) ([]byte, *ConfFile, error) {
|
||||
func Load(filename string, password []byte) ([]byte, *ConfFile, error) {
|
||||
var cf ConfFile
|
||||
cf.filename = filename
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
var testPw = []byte("test")
|
||||
|
||||
func TestLoadV1(t *testing.T) {
|
||||
_, _, err := LoadConfFile("config_test/v1.conf", testPw)
|
||||
_, _, err := Load("config_test/v1.conf", testPw)
|
||||
if err == nil {
|
||||
t.Errorf("Outdated v1 config file must fail to load but it didn't")
|
||||
} else if testing.Verbose() {
|
||||
@ -24,7 +24,7 @@ func TestLoadV1(t *testing.T) {
|
||||
func TestLoadV2(t *testing.T) {
|
||||
t1 := time.Now()
|
||||
|
||||
_, _, err := LoadConfFile("config_test/v2.conf", testPw)
|
||||
_, _, err := Load("config_test/v2.conf", testPw)
|
||||
if err != nil {
|
||||
t.Errorf("Could not load v2 config file: %v", err)
|
||||
}
|
||||
@ -39,21 +39,21 @@ func TestLoadV2PwdError(t *testing.T) {
|
||||
if !testing.Verbose() {
|
||||
tlog.Warn.Enabled = false
|
||||
}
|
||||
_, _, err := LoadConfFile("config_test/v2.conf", []byte("wrongpassword"))
|
||||
_, _, err := Load("config_test/v2.conf", []byte("wrongpassword"))
|
||||
if err == nil {
|
||||
t.Errorf("Loading with wrong password must fail but it didn't")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadV2Feature(t *testing.T) {
|
||||
_, _, err := LoadConfFile("config_test/PlaintextNames.conf", testPw)
|
||||
_, _, err := Load("config_test/PlaintextNames.conf", testPw)
|
||||
if err != nil {
|
||||
t.Errorf("Could not load v2 PlaintextNames config file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadV2StrangeFeature(t *testing.T) {
|
||||
_, _, err := LoadConfFile("config_test/StrangeFeature.conf", testPw)
|
||||
_, _, err := Load("config_test/StrangeFeature.conf", testPw)
|
||||
if err == nil {
|
||||
t.Errorf("Loading unknown feature must fail but it didn't")
|
||||
} else if testing.Verbose() {
|
||||
@ -62,11 +62,11 @@ func TestLoadV2StrangeFeature(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateConfDefault(t *testing.T) {
|
||||
err := CreateConfFile("config_test/tmp.conf", testPw, false, 10, "test", false, false, false)
|
||||
err := Create("config_test/tmp.conf", testPw, false, 10, "test", false, false, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, c, err := LoadConfFile("config_test/tmp.conf", testPw)
|
||||
_, c, err := Load("config_test/tmp.conf", testPw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -83,18 +83,18 @@ func TestCreateConfDefault(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateConfDevRandom(t *testing.T) {
|
||||
err := CreateConfFile("config_test/tmp.conf", testPw, false, 10, "test", false, true, false)
|
||||
err := Create("config_test/tmp.conf", testPw, false, 10, "test", false, true, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateConfPlaintextnames(t *testing.T) {
|
||||
err := CreateConfFile("config_test/tmp.conf", testPw, true, 10, "test", false, false, false)
|
||||
err := Create("config_test/tmp.conf", testPw, true, 10, "test", false, false, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, c, err := LoadConfFile("config_test/tmp.conf", testPw)
|
||||
_, c, err := Load("config_test/tmp.conf", testPw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -111,11 +111,11 @@ func TestCreateConfPlaintextnames(t *testing.T) {
|
||||
|
||||
// Reverse mode uses AESSIV
|
||||
func TestCreateConfFileAESSIV(t *testing.T) {
|
||||
err := CreateConfFile("config_test/tmp.conf", testPw, false, 10, "test", true, false, false)
|
||||
err := Create("config_test/tmp.conf", testPw, false, 10, "test", true, false, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, c, err := LoadConfFile("config_test/tmp.conf", testPw)
|
||||
_, c, err := Load("config_test/tmp.conf", testPw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -35,7 +35,7 @@ var raceDetector bool
|
||||
func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.ConfFile, err error) {
|
||||
// First check if the file can be read at all, and find out if a Trezor should
|
||||
// be used instead of a password.
|
||||
_, cf1, err := configfile.LoadConfFile(args.config, nil)
|
||||
_, cf1, err := configfile.Load(args.config, nil)
|
||||
if err != nil {
|
||||
tlog.Fatal.Printf("Cannot open config file: %v", err)
|
||||
return nil, nil, err
|
||||
@ -55,7 +55,7 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf
|
||||
pw = readpassword.Once(args.extpass, "")
|
||||
}
|
||||
tlog.Info.Println("Decrypting master key")
|
||||
masterkey, confFile, err = configfile.LoadConfFile(args.config, pw)
|
||||
masterkey, confFile, err = configfile.Load(args.config, pw)
|
||||
for i := range pw {
|
||||
pw[i] = 0
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func TestMain(m *testing.M) {
|
||||
// Test -init flag
|
||||
func TestInit(t *testing.T) {
|
||||
dir := test_helpers.InitFS(t)
|
||||
_, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfDefaultName, testPw)
|
||||
_, c, err := configfile.Load(dir+"/"+configfile.ConfDefaultName, testPw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -51,7 +51,7 @@ func TestInitDevRandom(t *testing.T) {
|
||||
// Test -init with -aessiv
|
||||
func TestInitAessiv(t *testing.T) {
|
||||
dir := test_helpers.InitFS(t, "-aessiv")
|
||||
_, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfDefaultName, testPw)
|
||||
_, c, err := configfile.Load(dir+"/"+configfile.ConfDefaultName, testPw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -63,7 +63,7 @@ func TestInitAessiv(t *testing.T) {
|
||||
// Test -init with -reverse
|
||||
func TestInitReverse(t *testing.T) {
|
||||
dir := test_helpers.InitFS(t, "-reverse")
|
||||
_, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfReverseName, testPw)
|
||||
_, c, err := configfile.Load(dir+"/"+configfile.ConfReverseName, testPw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
// Only the PlaintextNames feature flag should be set
|
||||
func TestFlags(t *testing.T) {
|
||||
_, cf, err := configfile.LoadConfFile(cDir+"/gocryptfs.conf", testPw)
|
||||
_, cf, err := configfile.Load(cDir+"/gocryptfs.conf", testPw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func TestInitTrezor(t *testing.T) {
|
||||
// vvvvvvvvvvvvv disable -extpass
|
||||
dir := test_helpers.InitFS(t, "-trezor", "-extpass", "")
|
||||
// The freshly created config file should have the Trezor feature flag set.
|
||||
_, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfDefaultName, nil)
|
||||
_, c, err := configfile.Load(dir+"/"+configfile.ConfDefaultName, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user