pub struct EffectInjector { /* private fields */ }Expand description
Controlled effect injector for timing tests.
Provides a safe, configurable way to inject timing effects with built-in safety limits and common patterns.
§Example
use tacet::helpers::effect::EffectInjector;
let injector = EffectInjector::new();
// In a timing test:
TimingOracle::for_attacker(AttackerModel::AdjacentNetwork)
.test(inputs, |&should_delay| {
injector.conditional_delay(should_delay, 200);
});Implementations§
Source§impl EffectInjector
impl EffectInjector
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new effect injector with default safety limit (100μs).
Important: Call init_effect_injection() before creating the first
EffectInjector to ensure calibration doesn’t interfere with timing measurements.
Sourcepub fn with_max_ns(max_ns: u64) -> Self
pub fn with_max_ns(max_ns: u64) -> Self
Create an effect injector with a custom maximum delay.
§Arguments
max_ns- Maximum delay in nanoseconds
Sourcepub fn delay_ns(&self, ns: u64)
pub fn delay_ns(&self, ns: u64)
Inject a fixed delay.
The delay is clamped to this injector’s maximum.
Sourcepub fn conditional_delay(&self, condition: bool, delay_ns: u64)
pub fn conditional_delay(&self, condition: bool, delay_ns: u64)
Inject a conditional delay (common pattern for timing tests).
If condition is true, delays by delay_ns.
If false, no delay is applied.
This is the standard pattern for baseline vs sample timing tests:
- Baseline: condition=false (no delay)
- Sample: condition=true (delay applied)
Sourcepub fn proportional_delay(&self, value: u64, ns_per_unit: f64)
pub fn proportional_delay(&self, value: u64, ns_per_unit: f64)
Inject a delay proportional to a value.
Useful for simulating data-dependent timing where larger values take longer to process.
§Arguments
value- The value to scale byns_per_unit- Nanoseconds of delay per unit of value
Sourcepub fn hamming_weight_delay(&self, data: &[u8], ns_per_bit: f64)
pub fn hamming_weight_delay(&self, data: &[u8], ns_per_bit: f64)
Inject a delay based on Hamming weight (number of 1 bits).
Simulates timing leaks where processing time depends on the number of set bits in the data.
§Arguments
data- Byte slice to compute Hamming weight fromns_per_bit- Nanoseconds of delay per set bit
Trait Implementations§
Source§impl Clone for EffectInjector
impl Clone for EffectInjector
Source§fn clone(&self) -> EffectInjector
fn clone(&self) -> EffectInjector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EffectInjector
impl Debug for EffectInjector
Auto Trait Implementations§
impl Freeze for EffectInjector
impl RefUnwindSafe for EffectInjector
impl Send for EffectInjector
impl Sync for EffectInjector
impl Unpin for EffectInjector
impl UnwindSafe for EffectInjector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.