pub struct Validator { /* private fields */ }
Expand description

Validator for a WebAssembly binary module or component.

This structure encapsulates state necessary to validate a WebAssembly binary. This implements validation as defined by the core specification. A Validator is designed, like Parser, to accept incremental input over time. Additionally a Validator is also designed for parallel validation of functions as they are received.

It’s expected that you’ll be using a Parser in tandem with a Validator. As each Payload is received from a Parser you’ll pass it into a Validator to test the validity of the payload. Note that all payloads received from a Parser are expected to be passed to a Validator. For example if you receive Payload::TypeSection you’ll call Validator::type_section to validate this.

The design of Validator is intended that you’ll interleave, in your own application’s processing, calls to validation. Each variant, after it’s received, will be validated and then your application would proceed as usual. At all times, however, you’ll have access to the Validator and the validation context up to that point. This enables applications to check the types of functions and learn how many globals there are, for example.

Implementations

Creates a new Validator ready to validate a WebAssembly module or component.

The new validator will receive payloads parsed from Parser, and expects the first payload received to be the version header from the parser.

Creates a new Validator which has the specified set of wasm features activated for validation.

This function is the same as Validator::new except it also allows you to customize the active wasm features in use for validation. This can allow enabling experimental proposals or also turning off on-by-default wasm proposals.

Returns the wasm features used for this validator.

Validates an entire in-memory module or component with this validator.

This function will internally create a Parser to parse the bytes provided. The entire module or component specified by bytes will be parsed and validated.

Upon success, the type information for the top-level module or component will be returned.

Gets the types known by the validator so far within the module/component level modules/components up from the module/component currently being parsed.

For instance, calling validator.types(0) will get the types of the module/component currently being parsed, and validator.types(1) will get the types of the component containing that module/component.

Returns None if there is no module/component that many levels up.

Convenience function to validate a single Payload.

This function is intended to be used as a convenience. It will internally perform any validation necessary to validate the Payload provided. The convenience part is that you’re likely already going to be matching on Payload in your application, at which point it’s more appropriate to call the individual methods on Validator per-variant in Payload, such as Validator::type_section.

This function returns a ValidPayload variant on success, indicating one of a few possible actions that need to be taken after a payload is validated. For example function contents are not validated here, they’re returned through ValidPayload for validation by the caller.

Validates Payload::Version.

Validates Payload::ImportSection.

This method should only be called when parsing a module.

Validates Payload::FunctionSection.

This method should only be called when parsing a module.

Validates Payload::TableSection.

This method should only be called when parsing a module.

Validates Payload::MemorySection.

This method should only be called when parsing a module.

Validates Payload::TagSection.

This method should only be called when parsing a module.

Validates Payload::GlobalSection.

This method should only be called when parsing a module.

Validates Payload::ExportSection.

This method should only be called when parsing a module.

Validates Payload::StartSection.

This method should only be called when parsing a module.

Validates Payload::ElementSection.

This method should only be called when parsing a module.

Validates Payload::DataCountSection.

This method should only be called when parsing a module.

Validates Payload::CodeSectionStart.

This method should only be called when parsing a module.

source

pub fn code_section_entry(
    &mut self,
    body: &FunctionBody<'_>
) -> Result<FuncToValidate<ValidatorResources>>

Validates Payload::CodeSectionEntry.

This function will prepare a FuncToValidate which can be used to create a FuncValidator to validate the function. The function body provided will not be parsed or validated by this function.

Note that the returned FuncToValidate is “connected” to this Validator in that it uses the internal context of this validator for validating the function. The FuncToValidate can be sent to another thread, for example, to offload actual processing of functions elsewhere.

This method should only be called when parsing a module.

Validates Payload::DataSection.

This method should only be called when parsing a module.

Validates Payload::ModuleSection.

This method should only be called when parsing a component.

Validates Payload::InstanceSection.

This method should only be called when parsing a component.

Validates Payload::CoreTypeSection.

This method should only be called when parsing a component.

Validates Payload::ComponentSection.

This method should only be called when parsing a component.

Validates Payload::ComponentInstanceSection.

This method should only be called when parsing a component.

Validates Payload::ComponentAliasSection.

This method should only be called when parsing a component.

Validates Payload::ComponentTypeSection.

This method should only be called when parsing a component.

Validates Payload::ComponentCanonicalSection.

This method should only be called when parsing a component.

Validates Payload::ComponentStartSection.

This method should only be called when parsing a component.

Validates Payload::ComponentImportSection.

This method should only be called when parsing a component.

Validates Payload::ComponentExportSection.

This method should only be called when parsing a component.

Validates Payload::UnknownSection.

Currently always returns an error.

Validates Payload::End.

Returns the types known to the validator for the module or component.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.