-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
util_ee.go
53 lines (43 loc) · 1.48 KB
/
util_ee.go
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
// +build !oss
/*
* Copyright 2018 Dgraph Labs, Inc. and Contributors
*
* Licensed under the Dgraph Community License (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* https://github.com/dgraph-io/dgraph/blob/master/licenses/DCL.txt
*/
package enc
import (
"github.com/dgraph-io/dgraph/x"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"io/ioutil"
)
const encFile string = "encryption_key_file"
var EeBuild = true
// EncryptionKeyFile exposes the encryption_key_file flag to sub-cmds.
func EncryptionKeyFile(flag *pflag.FlagSet) {
flag.String(encFile, "",
"The file that stores the data encryption key. The key size must be 16, 24, or 32 bytes long. "+
"The key size determines the corresponding block size for AES encryption "+
"(AES-128, AES-192, and AES-256 respectively). Enterprise feature.")
}
// GetEncryptionKeyString returns the configured key
func GetEncryptionKeyFile(c *viper.Viper) string {
return c.GetString(encFile)
}
// ReadEncryptionKeyFile returns the encryption key in the given file.
func ReadEncryptionKeyFile(f string) []byte {
if f == "" {
return nil
}
k, err := ioutil.ReadFile(f)
x.Checkf(err, "Error reading Badger Encryption key file (%v)", f)
// len must be 16,24,32 bytes if given. 0 otherwise. All other lengths are invalid.
klen := len(k)
x.AssertTruef(klen == 16 || klen == 24 || klen == 32,
"Invalid Badger encryption key length = %v", klen)
return k
}