summaryrefslogtreecommitdiff
path: root/internal/configfile/feature_flags.go
blob: 90b8c227e854d2f1d328f00f02209ba4f5396f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package configfile

type flagIota int

const (
	FlagPlaintextNames flagIota = iota
	FlagDirIV
	FlagEMENames
	FlagGCMIV128
	FlagLongNames
	FlagGCMSIV
)

// knownFlags stores the known feature flags and their string representation
var knownFlags map[flagIota]string = map[flagIota]string{
	FlagPlaintextNames: "PlaintextNames",
	FlagDirIV:          "DirIV",
	FlagEMENames:       "EMENames",
	FlagGCMIV128:       "GCMIV128",
	FlagLongNames:      "LongNames",
	FlagGCMSIV:         "GCMSIV",
}

// Filesystems that do not have these feature flags set are deprecated.
var requiredFlagsNormal []flagIota = []flagIota{
	FlagDirIV,
	FlagEMENames,
	FlagGCMIV128,
}

// Filesystems without filename encryption obviously don't have or need the
// filename related feature flags.
var requiredFlagsPlaintextNames []flagIota = []flagIota{
	FlagGCMIV128,
}

// isFeatureFlagKnown verifies that we understand a feature flag
func (cf *ConfFile) isFeatureFlagKnown(flag string) bool {
	for _, knownFlag := range knownFlags {
		if knownFlag == flag {
			return true
		}
	}
	return false
}

// isFeatureFlagSet - is the feature flag "flagWant" enabled?
func (cf *ConfFile) IsFeatureFlagSet(flagWant flagIota) bool {
	flagString := knownFlags[flagWant]
	for _, flag := range cf.FeatureFlags {
		if flag == flagString {
			return true
		}
	}
	return false
}