akern-gkgoat-fork/ableos/src/wasm/mod.rs

51 lines
1008 B
Rust

use alloc::vec::Vec;
/// `NULL a s m` as an array of 4 bytes
pub const WASM_BINARY_MAGIC: [u8; 4] = [0x00, 0x61, 0x73, 0x6d];
/// `1 0 0 0` as an array of 4 bytes
pub const WASM_VERSION: [u8; 4] = [0x01, 0x00, 0x00, 0x00];
/// Validate a wasm header (8 bytes)
pub enum SectionType {
None = 0,
Type = 1,
}
pub struct Section {
stype: SectionType,
section_size: u8,
}
pub struct WasmProgram {
raw_bytes: Vec<u8>,
// version:
}
impl WasmProgram {
pub fn new_from_bytes(bytes: &[u8]) -> Self {
Self {
raw_bytes: bytes.to_vec(),
}
}
pub fn validate_header(self) -> (bool, bool) {
let mut byte_magic_valid = false;
let mut byte_version_valid = false;
if self.raw_bytes[0..4] == WASM_BINARY_MAGIC {
byte_magic_valid = true;
}
if self.raw_bytes[4..8] == WASM_VERSION {
byte_version_valid = true;
}
return (byte_magic_valid, byte_version_valid);
}
}