Skip to main content

HushEngine

Struct HushEngine 

Source
pub struct HushEngine { /* private fields */ }
Expand description

The main security enforcement engine

Implementations§

Source§

impl HushEngine

Source

pub fn new() -> Self

Create a new engine with default policy

Source

pub fn builder(policy: Policy) -> HushEngineBuilder

Source

pub fn with_policy(policy: Policy) -> Self

Create with a specific policy

Source

pub fn from_ruleset(name: &str) -> Result<Self>

Create from a named ruleset

Source

pub fn with_keypair(self, keypair: Keypair) -> Self

Set the signing keypair

Source

pub fn with_generated_keypair(self) -> Self

Generate a new signing keypair

Source

pub fn with_extra_guard<G>(self, guard: G) -> Self
where 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.

Source

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.

Source

pub fn add_extra_guard<G>(&mut self, guard: G) -> &mut Self
where 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.

Source

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.

Source

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.

Source

pub fn policy(&self) -> &Policy

Get the active policy.

Source

pub fn policy_yaml(&self) -> Result<String>

Get the active policy YAML.

Source

pub fn keypair(&self) -> Option<&Keypair>

Get the signing keypair, if configured.

Source

pub async fn check_file_access( &self, path: &str, context: &GuardContext, ) -> Result<GuardResult>

Check a file access action

Source

pub async fn check_file_write( &self, path: &str, content: &[u8], context: &GuardContext, ) -> Result<GuardResult>

Check a file write action

Source

pub async fn check_egress( &self, host: &str, port: u16, context: &GuardContext, ) -> Result<GuardResult>

Check a network egress action

Source

pub async fn check_shell( &self, command: &str, context: &GuardContext, ) -> Result<GuardResult>

Check a shell command action

Source

pub async fn check_mcp_tool( &self, tool: &str, args: &Value, context: &GuardContext, ) -> Result<GuardResult>

Check an MCP tool invocation

Source

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.

Source

pub async fn check_patch( &self, path: &str, diff: &str, context: &GuardContext, ) -> Result<GuardResult>

Check a patch action

Source

pub async fn check_action( &self, action: &GuardAction<'_>, context: &GuardContext, ) -> Result<GuardResult>

Check any action against all applicable guards

Source

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.

Source

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).

Source

pub async fn create_receipt(&self, content_hash: Hash) -> Result<Receipt>

Create a receipt for the current session

Source

pub async fn create_signed_receipt( &self, content_hash: Hash, ) -> Result<SignedReceipt>

Create and sign a receipt

Source

pub async fn stats(&self) -> EngineStats

Get session statistics

Source

pub async fn reset(&self)

Reset session state

Trait Implementations§

Source§

impl Default for HushEngine

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more