summaryrefslogtreecommitdiff
path: root/internal/configfile
diff options
context:
space:
mode:
Diffstat (limited to 'internal/configfile')
-rw-r--r--internal/configfile/config_file.go9
-rw-r--r--internal/configfile/config_test.go24
-rw-r--r--internal/configfile/feature_flags.go4
3 files changed, 37 insertions, 0 deletions
diff --git a/internal/configfile/config_file.go b/internal/configfile/config_file.go
index 828f034..2d11346 100644
--- a/internal/configfile/config_file.go
+++ b/internal/configfile/config_file.go
@@ -55,6 +55,8 @@ type ConfFile struct {
FeatureFlags []string
// FIDO2 parameters
FIDO2 *FIDO2Params `json:",omitempty"`
+ // LongNameMax corresponds to the -longnamemax flag
+ LongNameMax uint8 `json:",omitempty"`
// Filename is the name of the config file. Not exported to JSON.
filename string
}
@@ -71,6 +73,7 @@ type CreateArgs struct {
Fido2HmacSalt []byte
DeterministicNames bool
XChaCha20Poly1305 bool
+ LongNameMax uint8
}
// Create - create a new config with a random key encrypted with
@@ -97,6 +100,12 @@ func Create(args *CreateArgs) error {
if !args.DeterministicNames {
cf.setFeatureFlag(FlagDirIV)
}
+ // 0 means to *use* the default (which means we don't have to save it), and
+ // 255 *is* the default, which means we don't have to save it either.
+ if args.LongNameMax != 0 && args.LongNameMax != 255 {
+ cf.LongNameMax = args.LongNameMax
+ cf.setFeatureFlag(FlagLongNameMax)
+ }
cf.setFeatureFlag(FlagEMENames)
cf.setFeatureFlag(FlagLongNames)
cf.setFeatureFlag(FlagRaw64)
diff --git a/internal/configfile/config_test.go b/internal/configfile/config_test.go
index b8012d3..3407464 100644
--- a/internal/configfile/config_test.go
+++ b/internal/configfile/config_test.go
@@ -131,6 +131,30 @@ func TestCreateConfFileAESSIV(t *testing.T) {
}
}
+func TestCreateConfLongNameMax(t *testing.T) {
+ args := &CreateArgs{
+ Filename: "config_test/tmp.conf",
+ Password: testPw,
+ LogN: 10,
+ Creator: "test",
+ LongNameMax: 100,
+ }
+ err := Create(args)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, c, err := LoadAndDecrypt("config_test/tmp.conf", testPw)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !c.IsFeatureFlagSet(FlagLongNameMax) {
+ t.Error("FlagLongNameMax should be set but is not")
+ }
+ if c.LongNameMax != args.LongNameMax {
+ t.Errorf("wrong LongNameMax value: want=%d have=%d", args.LongNameMax, c.LongNameMax)
+ }
+}
+
func TestIsFeatureFlagKnown(t *testing.T) {
// Test a few hardcoded values
testKnownFlags := []string{"DirIV", "PlaintextNames", "EMENames", "GCMIV128", "LongNames", "AESSIV"}
diff --git a/internal/configfile/feature_flags.go b/internal/configfile/feature_flags.go
index e28abd6..e45b20c 100644
--- a/internal/configfile/feature_flags.go
+++ b/internal/configfile/feature_flags.go
@@ -16,6 +16,9 @@ const (
FlagGCMIV128
// FlagLongNames allows file names longer than 176 bytes.
FlagLongNames
+ // FlagLongNameMax sets a custom name length limit, names longer than that
+ // will be hashed.
+ FlagLongNameMax
// FlagAESSIV selects an AES-SIV based crypto backend.
FlagAESSIV
// FlagRaw64 enables raw (unpadded) base64 encoding for file names
@@ -40,6 +43,7 @@ var knownFlags = map[flagIota]string{
FlagEMENames: "EMENames",
FlagGCMIV128: "GCMIV128",
FlagLongNames: "LongNames",
+ FlagLongNameMax: "LongNameMax",
FlagAESSIV: "AESSIV",
FlagRaw64: "Raw64",
FlagHKDF: "HKDF",