pub struct Hashed<T: Translator> { /* private fields */ }Expand description
Collision-resistant wrapper for any Translator.
Hashes the full key with a per-instance secret seed before delegating to the inner translator. This makes translated-key collisions unpredictable to an adversary who does not know the seed, similar to how std::collections::HashMap uses std::collections::hash_map::RandomState to prevent HashDoS attacks. It can also be used to ensure uniform distribution of skewed keyspaces when used by non-hashing structures such as crate::index.
§No Ordering
Hashing destroys lexicographic key ordering. Do not use Hashed with ordered indices when callers rely on translated-key adjacency matching original-key adjacency (e.g., exclusion proofs in the ordered QMDB). Hashed is safe for unordered indices and partitioned unordered indices.
§no_std Support
Hashed::new and Default are available only with this crate’s std feature. They use
ahash::RandomState::new, which requires OS-provided randomness (the runtime-rng feature of
ahash, enabled by std here). In no_std environments, use Hashed::from_seed with an
externally-sourced random seed instead.
§No Stability Guarantees
ahash::RandomState is used as the underlying hasher. While ahash is robust, its exact
algorithm might change across versions. As a result, transformed outputs are not stable across
Rust versions or platforms. Treat this translator as an in-memory collision-hardening mechanism,
not as a stable/persisted encoding.
§Examples
use commonware_storage::translator::{Hashed, TwoCap, Translator};
// Random seed (production use, requires `std`):
let t = Hashed::new(TwoCap);
let _k = t.transform(b"hello");
// Deterministic seed (testing within the same toolchain/runtime):
let t = Hashed::from_seed(42, TwoCap);
assert_eq!(t.transform(b"hello"), t.transform(b"hello"));Implementations§
Trait Implementations§
Source§impl<T: Translator> BuildHasher for Hashed<T>
impl<T: Translator> BuildHasher for Hashed<T>
Source§type Hasher = <T as BuildHasher>::Hasher
type Hasher = <T as BuildHasher>::Hasher
Source§fn build_hasher(&self) -> Self::Hasher
fn build_hasher(&self) -> Self::Hasher
Auto Trait Implementations§
impl<T> Freeze for Hashed<T>where
T: Freeze,
impl<T> RefUnwindSafe for Hashed<T>where
T: RefUnwindSafe,
impl<T> Send for Hashed<T>
impl<T> Sync for Hashed<T>
impl<T> Unpin for Hashed<T>where
T: Unpin,
impl<T> UnsafeUnpin for Hashed<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Hashed<T>where
T: UnwindSafe,
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 more