MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / store_wasm_binary

Function store_wasm_binary

nodedb/src/control/planner/wasm/store.rs:15–51  ·  view source on GitHub ↗

Store a WASM binary in the system catalog, returning its content hash. Content-addressed: if the same binary is uploaded twice, it's stored once. The hash is used as the key for deduplication and cache lookup.

(
    catalog: &crate::control::security::catalog::types::SystemCatalog,
    wasm_bytes: &[u8],
    max_size: usize,
)

Source from the content-addressed store, hash-verified

13/// Content-addressed: if the same binary is uploaded twice, it's stored once.
14/// The hash is used as the key for deduplication and cache lookup.
15pub fn store_wasm_binary(
16 catalog: &crate::control::security::catalog::types::SystemCatalog,
17 wasm_bytes: &[u8],
18 max_size: usize,
19) -> crate::Result<String> {
20 if wasm_bytes.is_empty() {
21 return Err(crate::Error::BadRequest {
22 detail: "WASM binary is empty".into(),
23 });
24 }
25 if wasm_bytes.len() > max_size {
26 return Err(crate::Error::BadRequest {
27 detail: format!(
28 "WASM binary exceeds maximum size ({} bytes > {max_size} bytes)",
29 wasm_bytes.len()
30 ),
31 });
32 }
33
34 // Validate WASM magic number: \0asm
35 if wasm_bytes.len() < 4 || &wasm_bytes[..4] != b"\0asm" {
36 return Err(crate::Error::BadRequest {
37 detail: "invalid WASM binary: missing \\0asm magic header".into(),
38 });
39 }
40
41 let hash = sha256_hex(wasm_bytes);
42 let key = format!("wasm_module:{hash}");
43
44 catalog
45 .put_raw(key.as_bytes(), wasm_bytes)
46 .map_err(|e| crate::Error::Internal {
47 detail: format!("failed to store WASM binary: {e}"),
48 })?;
49
50 Ok(hash)
51}
52
53/// Load a WASM binary from the system catalog by its content hash.
54pub fn load_wasm_binary(

Callers 3

create_wasm_functionFunction · 0.85
create_wasm_aggregateFunction · 0.85
upload_wasmFunction · 0.85

Calls 5

sha256_hexFunction · 0.70
is_emptyMethod · 0.45
lenMethod · 0.45
put_rawMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected