pub struct InputPair<T, F1, F2> { /* private fields */ }Expand description
Pre-generated inputs for timing tests.
Both baseline() and sample() call their respective closures to generate
values. This symmetric design ensures both classes have identical calling patterns.
§Type Parameters
T: The input type (e.g.,[u8; 32],Vec<u8>)F1: The baseline closure typeF2: The sample closure type
§Example
use tacet::helpers::InputPair;
// Both are closures (symmetric)
let inputs = InputPair::new(
|| [0u8; 32], // baseline closure
|| rand::random(), // sample closure
);
// Use in test - both call their closures
let baseline_val = inputs.baseline();
let sample_val = inputs.sample();Implementations§
Source§impl<T, F1, F2> InputPair<T, F1, F2>
impl<T, F1, F2> InputPair<T, F1, F2>
Sourcepub fn new(baseline: F1, sample: F2) -> Self
pub fn new(baseline: F1, sample: F2) -> Self
Create a new input pair with anomaly detection.
Both arguments are closures that generate input values.
§Arguments
baseline: Closure that generates the baseline value (typically constant)sample: Closure that generates varied sample values
§Type Requirements
T: Clonefor internal operationsT: Hashfor anomaly detection (usenew_untrackedfor non-Hash types)
§Example
let inputs = InputPair::new(
|| [0u8; 32], // baseline: returns constant value
|| rand::random::<[u8; 32]>() // sample: generates varied values
);Sourcepub fn new_unchecked(baseline: F1, sample: F2) -> Self
pub fn new_unchecked(baseline: F1, sample: F2) -> Self
Create a new input pair without anomaly detection.
Use this when you intentionally use deterministic inputs (e.g., fixed nonces, pre-generated signatures) and want to suppress the “identical values” warning.
§Example
// Testing with fixed nonces - intentionally deterministic
let nonces = InputPair::new_unchecked(
|| [0x00u8; 12], // Fixed nonce A
|| [0xFFu8; 12], // Fixed nonce B
);Sourcepub fn baseline(&self) -> T
pub fn baseline(&self) -> T
Generate a baseline value by calling the baseline closure.
Returns T by calling the baseline closure each time.
let inputs = InputPair::new(|| [0u8; 32], || rand::random());
let val = inputs.baseline(); // Calls || [0u8; 32]Sourcepub fn sample(&self) -> T
pub fn sample(&self) -> T
Generate a sample value with anomaly tracking.
Calls the sample closure and tracks the hash for anomaly detection
(only the first ANOMALY_DETECTION_WINDOW samples are tracked).
Note: This method includes tracking overhead. For timing-critical code,
use generate_sample() during pre-generation and check anomalies after.
Sourcepub fn generate_sample(&self) -> T
pub fn generate_sample(&self) -> T
Generate a sample value without anomaly tracking.
Use this for pre-generating inputs before measurement. After pre-generation,
call track_value() on each value to enable anomaly detection.
This is used internally by TimingOracle::test() to avoid overhead
during the measurement loop.
Sourcepub fn generate_baseline(&self) -> T
pub fn generate_baseline(&self) -> T
Generate a baseline value without any overhead.
Identical to baseline() but named for symmetry with generate_sample().
Sourcepub fn track_value(&self, value: &T)
pub fn track_value(&self, value: &T)
Track a sample value for anomaly detection.
Call this on pre-generated sample values to enable anomaly detection without adding overhead during measurement.
Sourcepub fn check_anomaly(&self) -> Option<String>
pub fn check_anomaly(&self) -> Option<String>
Check if the sample generator appears to be producing constant values.
Returns a warning message if anomaly detected, None otherwise.
Should be called after measurement completes.
§Detected Anomalies
| Condition | Severity | Message |
|---|---|---|
| All samples identical | Error | Likely captured pre-evaluated value |
| <50% unique samples | Warning | Low entropy, possible mistake |
| Normal entropy | OK | None |
§Example
// After running the test
if let Some(warning) = inputs.check_anomaly() {
eprintln!("[tacet] {}", warning);
}Source§impl<T, F1, F2> InputPair<T, F1, F2>
impl<T, F1, F2> InputPair<T, F1, F2>
Sourcepub fn new_untracked(baseline: F1, sample: F2) -> Self
pub fn new_untracked(baseline: F1, sample: F2) -> Self
Sourcepub fn baseline_untracked(&self) -> T
pub fn baseline_untracked(&self) -> T
Generate a baseline value (untracked version).
Sourcepub fn sample_untracked(&self) -> T
pub fn sample_untracked(&self) -> T
Generate a sample value without tracking (for non-Hash types).
Sourcepub fn check_anomaly_untracked(&self) -> Option<String>
pub fn check_anomaly_untracked(&self) -> Option<String>
Check anomaly - always returns None for untracked InputPairs.
This method exists so code can call check_anomaly() uniformly
without knowing whether tracking is enabled.
Auto Trait Implementations§
impl<T, F1, F2> !Freeze for InputPair<T, F1, F2>
impl<T, F1, F2> !RefUnwindSafe for InputPair<T, F1, F2>
impl<T, F1, F2> Send for InputPair<T, F1, F2>
impl<T, F1, F2> !Sync for InputPair<T, F1, F2>
impl<T, F1, F2> Unpin for InputPair<T, F1, F2>
impl<T, F1, F2> UnsafeUnpin for InputPair<T, F1, F2>where
F1: UnsafeUnpin,
F2: UnsafeUnpin,
impl<T, F1, F2> UnwindSafe for InputPair<T, F1, F2>
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> 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.