diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-11-22 18:12:06 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-11-22 18:12:06 +0900 |
| commit | f7c725ea5722959145db51847214897bad8e8b01 (patch) | |
| tree | c08cbe634d2e8ee025309bb6b1ae082265b8e03c /container/seccomp/presets_test.go | |
| parent | ee51069e4756492f445069e39cc13715c6b19f0d (diff) | |
container/seccomp: use sha384 for validation
This also replaces hex encoding with base64 for more manageable string
representations, and removes targets with build-only support.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/seccomp/presets_test.go')
| -rw-r--r-- | container/seccomp/presets_test.go | 24 |
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) } } |
