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, so Hashed does not implement OrderedTranslator and cannot back an ordered index or the ordered QMDB. It is safe for unordered indices and partitioned unordered indices.
An ordered index over Hashed does not compile:
use commonware_storage::{
index::{Ordered, ordered::Index},
translator::{Hashed, TwoCap},
};
fn ordered<I: Ordered>() {}
ordered::<Index<Hashed<TwoCap>, u64>>();§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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