Expand description
Binary codec and fast hashing for event IDs.
Since room v3 an event ID is the eventβs sha256 reference hash: $ followed
by 43 characters of unpadded base64 (standard alphabet in v3, URL-safe in
v4+), so the 32 hash bytes and the ID convert losslessly in both directions.
TODO: Move this into Ruma and generalize for other identifiers.
Re-exportsΒ§
use std::hash::BuildHasher;πuse std::hash::Hasher;πuse std::ops::BitOr;πuse std::sync::LazyLock;πuse base64::Engine;πuse base64::engine::general_purpose::URL_SAFE_NO_PAD;πuse rand::random;πuse ruma::EventId;πuse ruma::OwnedEventId;πuse tuwunel_core::utils::math::u64_from_usize_saturating;π
StructsΒ§
- Fold
Hasher - Streaming state for
RandomState. - Random
State BuildHasherfor event-ID-keyed maps and sets.
ConstantsΒ§
- ALPHABET_
LEN π - ALPHABET_
STANDARD π - ALPHABET_
URL_ πSAFE - ENCODED_
LEN π - INVALID π
- SEXTETS_
LEN π
StaticsΒ§
FunctionsΒ§
- decode
- Decode an event ID into the sha256 it encodes.
Noneunless the ID has the v3+ shape with canonical unpadded base64 in either alphabet. - decode_
bytes π - decode_
encoded π - encode
- Encode a sha256 into the URL-safe (room v4+) form of the event ID. A v3 (standard-alphabet) ID does not round-trip through this form.
- fold π
- fold_
bytes π - folded_
multiply π - hash_
bytes π - sextets π
Type AliasesΒ§
- Sha256
- The sha256 reference hash encoded by a v3+ event ID. Fixed-size output of a SHA-256 digest operation.