pub struct HushEngine { /* private fields */ }Expand description
The main security enforcement engine
Implementations§
Source§impl HushEngine
impl HushEngine
pub fn builder(policy: Policy) -> HushEngineBuilder
Sourcepub fn with_policy(policy: Policy) -> Self
pub fn with_policy(policy: Policy) -> Self
Create with a specific policy
Sourcepub fn from_ruleset(name: &str) -> Result<Self>
pub fn from_ruleset(name: &str) -> Result<Self>
Create from a named ruleset
Sourcepub fn with_keypair(self, keypair: Keypair) -> Self
pub fn with_keypair(self, keypair: Keypair) -> Self
Set the signing keypair
Sourcepub fn with_generated_keypair(self) -> Self
pub fn with_generated_keypair(self) -> Self
Generate a new signing keypair
Sourcepub fn with_extra_guard<G>(self, guard: G) -> Selfwhere
G: Guard + 'static,
pub fn with_extra_guard<G>(self, guard: G) -> Selfwhere
G: Guard + 'static,
Append an additional guard (evaluated after all built-in guards).
Note: when fail_fast is enabled, guards after the first violation (including extras)
will not run.
Sourcepub fn with_extra_guard_box(self, guard: Box<dyn Guard>) -> Self
pub fn with_extra_guard_box(self, guard: Box<dyn Guard>) -> Self
Append an additional guard (evaluated after all built-in guards).
Note: when fail_fast is enabled, guards after the first violation (including extras)
will not run.
Sourcepub fn add_extra_guard<G>(&mut self, guard: G) -> &mut Selfwhere
G: Guard + 'static,
pub fn add_extra_guard<G>(&mut self, guard: G) -> &mut Selfwhere
G: Guard + 'static,
Append an additional guard (evaluated after all built-in guards).
Note: when fail_fast is enabled, guards after the first violation (including extras)
will not run.
Sourcepub fn add_extra_guard_box(&mut self, guard: Box<dyn Guard>) -> &mut Self
pub fn add_extra_guard_box(&mut self, guard: Box<dyn Guard>) -> &mut Self
Append an additional guard (evaluated after all built-in guards).
Note: when fail_fast is enabled, guards after the first violation (including extras)
will not run.
Sourcepub fn policy_hash(&self) -> Result<Hash>
pub fn policy_hash(&self) -> Result<Hash>
Get the policy hash (derived from the policy YAML).
Note: this does not include any runtime extra_guards.
Sourcepub fn policy_yaml(&self) -> Result<String>
pub fn policy_yaml(&self) -> Result<String>
Get the active policy YAML.
Sourcepub async fn check_file_access(
&self,
path: &str,
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_file_access( &self, path: &str, context: &GuardContext, ) -> Result<GuardResult>
Check a file access action
Sourcepub async fn check_file_write(
&self,
path: &str,
content: &[u8],
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_file_write( &self, path: &str, content: &[u8], context: &GuardContext, ) -> Result<GuardResult>
Check a file write action
Sourcepub async fn check_egress(
&self,
host: &str,
port: u16,
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_egress( &self, host: &str, port: u16, context: &GuardContext, ) -> Result<GuardResult>
Check a network egress action
Sourcepub async fn check_shell(
&self,
command: &str,
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_shell( &self, command: &str, context: &GuardContext, ) -> Result<GuardResult>
Check a shell command action
Sourcepub async fn check_mcp_tool(
&self,
tool: &str,
args: &Value,
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_mcp_tool( &self, tool: &str, args: &Value, context: &GuardContext, ) -> Result<GuardResult>
Check an MCP tool invocation
Sourcepub async fn check_untrusted_text(
&self,
source: Option<&str>,
text: &str,
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_untrusted_text( &self, source: Option<&str>, text: &str, context: &GuardContext, ) -> Result<GuardResult>
Check untrusted text (e.g. fetched web content) for prompt-injection signals.
This uses GuardAction::Custom("untrusted_text", ...) and is evaluated by PromptInjectionGuard.
Sourcepub async fn check_patch(
&self,
path: &str,
diff: &str,
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_patch( &self, path: &str, diff: &str, context: &GuardContext, ) -> Result<GuardResult>
Check a patch action
Sourcepub async fn check_action(
&self,
action: &GuardAction<'_>,
context: &GuardContext,
) -> Result<GuardResult>
pub async fn check_action( &self, action: &GuardAction<'_>, context: &GuardContext, ) -> Result<GuardResult>
Check any action against all applicable guards
Sourcepub async fn check_action_report(
&self,
action: &GuardAction<'_>,
context: &GuardContext,
) -> Result<GuardReport>
pub async fn check_action_report( &self, action: &GuardAction<'_>, context: &GuardContext, ) -> Result<GuardReport>
Check any action and return per-guard evidence plus the aggregated verdict.
Sourcepub async fn check_action_report_with_posture(
&self,
action: &GuardAction<'_>,
context: &GuardContext,
posture_state: &mut Option<PostureRuntimeState>,
) -> Result<PostureAwareReport>
pub async fn check_action_report_with_posture( &self, action: &GuardAction<'_>, context: &GuardContext, posture_state: &mut Option<PostureRuntimeState>, ) -> Result<PostureAwareReport>
Check an action and update posture runtime state (if posture is configured).
Sourcepub async fn create_receipt(&self, content_hash: Hash) -> Result<Receipt>
pub async fn create_receipt(&self, content_hash: Hash) -> Result<Receipt>
Create a receipt for the current session
Sourcepub async fn create_signed_receipt(
&self,
content_hash: Hash,
) -> Result<SignedReceipt>
pub async fn create_signed_receipt( &self, content_hash: Hash, ) -> Result<SignedReceipt>
Create and sign a receipt
Sourcepub async fn stats(&self) -> EngineStats
pub async fn stats(&self) -> EngineStats
Get session statistics