fidius-host::host Rust¶
PluginHost builder and plugin discovery.
Structs¶
fidius-host::host::PluginHost¶
pub
Host for loading and managing plugins.
Fields¶
| Name | Type | Description |
|---|---|---|
search_paths |
Vec < PathBuf > |
|
load_policy |
LoadPolicy |
|
require_signature |
bool |
|
trusted_keys |
Vec < VerifyingKey > |
|
expected_hash |
Option < u64 > |
|
expected_strategy |
Option < BufferStrategyKind > |
Methods¶
builder pub¶
Create a new builder.
discover pub¶
Discover all valid plugins in the configured search paths.
Scans directories for dylib files, loads each, validates, and returns metadata for all valid plugins found.
Source
pub fn discover(&self) -> Result<Vec<PluginInfo>, LoadError> {
#[cfg(feature = "tracing")]
tracing::info!(search_paths = ?self.search_paths, "discovering plugins");
let mut plugins = Vec::new();
for search_path in &self.search_paths {
if !search_path.is_dir() {
continue;
}
let entries = std::fs::read_dir(search_path)?;
for entry in entries {
let entry = entry?;
let path = entry.path();
if !is_dylib(&path) {
continue;
}
// Verify signature before dlopen to prevent code execution from untrusted dylibs
if self.require_signature
&& signing::verify_signature(&path, &self.trusted_keys).is_err()
{
continue;
}
match loader::load_library(&path) {
Ok(loaded) => {
for plugin in &loaded.plugins {
if let Ok(()) = loader::validate_against_interface(
plugin,
self.expected_hash,
self.expected_strategy,
) {
plugins.push(plugin.info.clone());
}
}
}
Err(_) => {
// Skip invalid dylibs during discovery
continue;
}
}
}
}
Ok(plugins)
}
load pub¶
Load a specific plugin by name.
Searches all configured paths for a dylib containing a plugin with the given name. Returns the loaded plugin ready for calling.
Source
pub fn load(&self, name: &str) -> Result<LoadedPlugin, LoadError> {
#[cfg(feature = "tracing")]
tracing::info!(plugin_name = name, "loading plugin");
for search_path in &self.search_paths {
if !search_path.is_dir() {
continue;
}
let entries = std::fs::read_dir(search_path)?;
for entry in entries {
let entry = entry?;
let path = entry.path();
if !is_dylib(&path) {
continue;
}
// Verify signature if required — always enforced regardless of LoadPolicy
if self.require_signature {
signing::verify_signature(&path, &self.trusted_keys)?;
}
match loader::load_library(&path) {
Ok(loaded) => {
for plugin in loaded.plugins {
if plugin.info.name == name {
loader::validate_against_interface(
&plugin,
self.expected_hash,
self.expected_strategy,
)?;
return Ok(plugin);
}
}
}
Err(_) => continue,
}
}
}
Err(LoadError::PluginNotFound {
name: name.to_string(),
})
}
fidius-host::host::PluginHostBuilder¶
pub
Builder for configuring a PluginHost.
Fields¶
| Name | Type | Description |
|---|---|---|
search_paths |
Vec < PathBuf > |
|
load_policy |
LoadPolicy |
|
require_signature |
bool |
|
trusted_keys |
Vec < VerifyingKey > |
|
expected_hash |
Option < u64 > |
|
expected_strategy |
Option < BufferStrategyKind > |
Methods¶
new private¶
Source
search_path pub¶
Add a directory to search for plugin dylibs.
Source
load_policy pub¶
Set the load policy (Strict or Lenient).
require_signature pub¶
Require plugins to have valid signatures.
Source
trusted_keys pub¶
Set trusted Ed25519 public keys for signature verification.
Source
interface_hash pub¶
Set the expected interface hash for validation.
buffer_strategy pub¶
Set the expected buffer strategy for validation.
Source
build pub¶
Build the PluginHost.
Source
Functions¶
fidius-host::host::is_dylib¶
private
Check if a path has a platform-appropriate dylib extension.