MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / DetectPolicyType

Function DetectPolicyType

pkg/policies/engine/detect.go:31–43  ·  view source on GitHub ↗

DetectPolicyType determines the policy type from source bytes WASM files start with magic bytes: 0x00 0x61 0x73 0x6d (\0asm) as documented at https://webassembly.github.io/spec/core/binary/modules.html#binary-module

(source []byte)

Source from the content-addressed store, hash-verified

29// WASM files start with magic bytes: 0x00 0x61 0x73 0x6d (\0asm)
30// as documented at https://webassembly.github.io/spec/core/binary/modules.html#binary-module
31func DetectPolicyType(source []byte) PolicyType {
32 // WASM files start with magic bytes: 0x00 0x61 0x73 0x6d (\0asm)
33 if len(source) >= 4 &&
34 source[0] == 0x00 &&
35 source[1] == 0x61 &&
36 source[2] == 0x73 &&
37 source[3] == 0x6d {
38 return PolicyTypeWASM
39 }
40
41 // Default to Rego (text-based)
42 return PolicyTypeRego
43}

Callers 6

executeScriptMethod · 0.92
decodeIfBase64WasmFunction · 0.92
processFileMethod · 0.92
TestDetectPolicyTypeFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestDetectPolicyTypeFunction · 0.68