aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/seccomp/presets_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'container/seccomp/presets_test.go')
-rw-r--r--container/seccomp/presets_test.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/container/seccomp/presets_test.go b/container/seccomp/presets_test.go
index b86d49ba..d24ca97f 100644
--- a/container/seccomp/presets_test.go
+++ b/container/seccomp/presets_test.go
@@ -2,29 +2,31 @@ package seccomp_test
import (
"crypto/sha512"
- "encoding/hex"
+ "encoding/base64"
+ "fmt"
"hakurei.app/container/seccomp"
"hakurei.app/container/std"
)
type (
+ // bpfPreset represents a preset to validate.
bpfPreset = struct {
seccomp.ExportFlag
std.FilterPreset
}
- bpfLookup map[bpfPreset][sha512.Size]byte
+
+ // bpfLookup are bpf presets and their corresponding filter checksum.
+ bpfLookup = map[bpfPreset][sha512.Size384]byte
)
-func toHash(s string) [sha512.Size]byte {
- if len(s) != sha512.Size*2 {
- panic("bad sha512 string length")
- }
- if v, err := hex.DecodeString(s); err != nil {
- panic(err.Error())
- } else if len(v) != sha512.Size {
- panic("unreachable")
+// mustParse parses [base64.StdEncoding] representations of a sha512 checksum.
+func mustParse(s string) [sha512.Size384]byte {
+ if v, err := base64.StdEncoding.DecodeString(s); err != nil {
+ panic(err)
+ } else if len(v) != sha512.Size384 {
+ panic(fmt.Sprintf("bad checksum of %d bytes", len(v)))
} else {
- return ([sha512.Size]byte)(v)
+ return ([sha512.Size384]byte)(v)
}
}