pub struct RoomCrypto { /* private fields */ }Expand description
Per-room Megolm crypto: one outbound session (ours) + many inbound (others’).
Implementations§
Source§impl RoomCrypto
impl RoomCrypto
Sourcepub fn new_for_room(
db: Db,
room_id: String,
our_fingerprint: String,
persist_key: [u8; 32],
) -> Result<Self>
pub fn new_for_room( db: Db, room_id: String, our_fingerprint: String, persist_key: [u8; 32], ) -> Result<Self>
Create a fresh outbound session and persist it. persist_key is
the 32-byte key the at-rest session pickles are encrypted under.
Sourcepub fn load(
db: Db,
room_id: String,
our_fingerprint: String,
persist_key: [u8; 32],
) -> Result<Option<Self>>
pub fn load( db: Db, room_id: String, our_fingerprint: String, persist_key: [u8; 32], ) -> Result<Option<Self>>
Load any persisted sessions for the room. Returns None when no
usable outbound session is stored (we haven’t joined or created it,
or the only outbound pickle is unreadable).
Resilient by design: a single session that fails to decode or decrypt is logged and skipped rather than aborting the whole room load. One corrupt row should not lock the user out.
Sourcepub fn encrypt(&mut self, plaintext: &[u8]) -> Result<(String, Vec<u8>)>
pub fn encrypt(&mut self, plaintext: &[u8]) -> Result<(String, Vec<u8>)>
Encrypt a plaintext using our outbound session. Returns (session_id, MegolmMessage bytes).
Sourcepub fn decrypt(
&mut self,
sender_fingerprint: &str,
session_id: &str,
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt( &mut self, sender_fingerprint: &str, session_id: &str, ciphertext: &[u8], ) -> Result<Vec<u8>>
Decrypt a message from a specific sender.
Sourcepub fn add_inbound_session(
&mut self,
sender_fingerprint: &str,
session_key_b64: &str,
) -> Result<()>
pub fn add_inbound_session( &mut self, sender_fingerprint: &str, session_key_b64: &str, ) -> Result<()>
Add an inbound session from another member. session_key_b64 is the
base64-encoded Megolm SessionKey they shared with us.
Sourcepub fn our_session_key_b64(&self) -> String
pub fn our_session_key_b64(&self) -> String
Get our outbound session key for sharing with new members (base64).
pub fn our_session_id(&self) -> String
pub fn our_fingerprint(&self) -> &str
pub fn room_id(&self) -> &str
Auto Trait Implementations§
impl Freeze for RoomCrypto
impl RefUnwindSafe for RoomCrypto
impl Send for RoomCrypto
impl Sync for RoomCrypto
impl Unpin for RoomCrypto
impl UnsafeUnpin for RoomCrypto
impl UnwindSafe for RoomCrypto
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 more