refactor(sbom): add intermediate representation for BOM (#6240)

Signed-off-by: knqyf263 <knqyf263@gmail.com>
Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com>
This commit is contained in:
Teppei Fukuda
2024-03-12 10:56:10 +04:00
committed by GitHub
parent fb8c516ded
commit 8fcef352b3
148 changed files with 4959 additions and 6190 deletions

View File

@@ -6,12 +6,11 @@ package wasm
// TinyGo can build this package, but Go cannot.
import (
"encoding/json"
"fmt"
"reflect"
"unsafe"
"github.com/mailru/easyjson"
"github.com/aquasecurity/trivy/pkg/module/api"
"github.com/aquasecurity/trivy/pkg/module/serialize"
)
@@ -40,20 +39,16 @@ func Error(message string) {
_error(ptr, size)
}
//go:wasm-module env
//export debug
//go:wasmimport env debug
func _debug(ptr uint32, size uint32)
//go:wasm-module env
//export info
//go:wasmimport env info
func _info(ptr uint32, size uint32)
//go:wasm-module env
//export warn
//go:wasmimport env warn
func _warn(ptr uint32, size uint32)
//go:wasm-module env
//export error
//go:wasmimport env error
func _error(ptr uint32, size uint32)
var module api.Module
@@ -134,8 +129,8 @@ func _post_scan(ptr, size uint32) uint64 {
return marshal(results)
}
func marshal(v easyjson.Marshaler) uint64 {
b, err := easyjson.Marshal(v)
func marshal(v any) uint64 {
b, err := json.Marshal(v)
if err != nil {
Error(fmt.Sprintf("marshal error: %s", err))
return 0
@@ -145,14 +140,14 @@ func marshal(v easyjson.Marshaler) uint64 {
return (uint64(p) << uint64(32)) | uint64(len(b))
}
func unmarshal(ptr, size uint32, v easyjson.Unmarshaler) error {
func unmarshal(ptr, size uint32, v any) error {
var b []byte
s := (*reflect.SliceHeader)(unsafe.Pointer(&b))
s.Len = uintptr(size)
s.Cap = uintptr(size)
s.Data = uintptr(ptr)
if err := easyjson.Unmarshal(b, v); err != nil {
if err := json.Unmarshal(b, v); err != nil {
return fmt.Errorf("unmarshal error: %s", err)
}