Skip to main content

Module event_id

Module event_id 

Source
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Β§

FoldHasher
Streaming state for RandomState.
RandomState
BuildHasher for event-ID-keyed maps and sets.

ConstantsΒ§

ALPHABET_LEN πŸ”’
ALPHABET_STANDARD πŸ”’
ALPHABET_URL_SAFE πŸ”’
ENCODED_LEN πŸ”’
INVALID πŸ”’
SEXTETS_LEN πŸ”’

StaticsΒ§

SEED πŸ”’
SEXTETS πŸ”’

FunctionsΒ§

decode
Decode an event ID into the sha256 it encodes. None unless 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.