matrix_sdk_crypto::olm

Struct Account

Source
pub struct Account { /* private fields */ }
Expand description

Account holding identity keys for which sessions can be created.

An account is the central identity for encrypted communication between two devices.

Implementations§

Source§

impl Account

Source

pub fn with_device_id(user_id: &UserId, device_id: &DeviceId) -> Self

Create a fresh new account, this will generate the identity key-pair.

Source

pub fn new(user_id: &UserId) -> Self

Create a new random Olm Account, the long-term Curve25519 identity key encoded as base64 will be used for the device ID.

Source

pub fn new_dehydrated(user_id: &UserId) -> Self

Create a new random Olm Account for a dehydrated device

Source

pub fn static_data(&self) -> &StaticAccountData

Get the immutable data for this account.

Source

pub fn update_uploaded_key_count(&mut self, new_count: u64)

Update the uploaded key count.

§Arguments
  • new_count - The new count that was reported by the server.
Source

pub fn uploaded_key_count(&self) -> u64

Get the currently known uploaded key count.

Source

pub fn shared(&self) -> bool

Has the account been shared with the server.

Source

pub fn mark_as_shared(&mut self)

Mark the account as shared.

Messages shouldn’t be encrypted with the session before it has been shared.

Source

pub fn one_time_keys(&self) -> HashMap<KeyId, Curve25519PublicKey>

Get the one-time keys of the account.

This can be empty, keys need to be generated first.

Source

pub fn generate_one_time_keys( &mut self, count: usize, ) -> OneTimeKeyGenerationResult

Generate count number of one-time keys.

Source

pub fn max_one_time_keys(&self) -> usize

Get the maximum number of one-time keys the account can hold.

Source

pub fn generate_one_time_keys_if_needed(&mut self) -> Option<u64>

Generate new one-time keys that need to be uploaded to the server.

Returns None if no keys need to be uploaded, otherwise the number of newly generated one-time keys. May return 0 if some one-time keys are already generated but weren’t uploaded.

Generally Some means that keys should be uploaded, while None means that keys should not be uploaded.

Source

pub fn keys_for_upload( &self, ) -> (Option<DeviceKeys>, BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>, BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>)

Get a tuple of device, one-time, and fallback keys that need to be uploaded.

If no keys need to be uploaded the DeviceKeys will be None and the one-time and fallback keys maps will be empty.

Source

pub fn mark_keys_as_published(&mut self)

Mark the current set of one-time keys as being published.

Source

pub fn sign(&self, string: &str) -> Ed25519Signature

Sign the given string using the accounts signing key.

Returns the signature as a base64 encoded string.

Source

pub fn pickle(&self) -> PickledAccount

Get a serializable version of the Account so it can be persisted.

Source

pub fn from_pickle(pickle: PickledAccount) -> Result<Self, PickleError>

Restore an account from a previously pickled one.

§Arguments
  • pickle - The pickled version of the Account.

  • pickle_mode - The mode that was used to pickle the account, either an unencrypted mode or an encrypted using passphrase.

Source

pub fn device_keys(&self) -> DeviceKeys

Sign the device keys of the account and return them so they can be uploaded.

Source

pub async fn bootstrap_cross_signing( &self, ) -> (PrivateCrossSigningIdentity, UploadSigningKeysRequest, SignatureUploadRequest)

Bootstrap Cross-Signing

Source

pub fn sign_cross_signing_key( &self, cross_signing_key: &mut CrossSigningKey, ) -> Result<(), SignatureError>

Sign the given CrossSigning Key in place

Source

pub fn sign_master_key( &self, master_key: &MasterPubkey, ) -> Result<SignatureUploadRequest, SignatureError>

Sign the given Master Key

Source

pub fn sign_json(&self, json: Value) -> Result<Ed25519Signature, SignatureError>

Convert a JSON value to the canonical representation and sign the JSON string.

§Arguments
  • json - The value that should be converted into a canonical JSON string.
Source

pub fn signed_one_time_keys( &self, ) -> BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>

Sign and prepare one-time keys to be uploaded.

If no one-time keys need to be uploaded, returns an empty BTreeMap.

Source

pub fn signed_fallback_keys( &self, ) -> BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>

Sign and prepare fallback keys to be uploaded.

If no fallback keys need to be uploaded returns an empty BTreeMap.

Source

pub fn create_outbound_session_helper( &self, config: SessionConfig, identity_key: Curve25519PublicKey, one_time_key: Curve25519PublicKey, fallback_used: bool, our_device_keys: DeviceKeys, ) -> Session

Create a new session with another account given a one-time key.

Returns the newly created session or a OlmSessionError if creating a session failed.

§Arguments
  • config - The session config that should be used when creating the Session.

  • identity_key - The other account’s identity/curve25519 key.

  • one_time_key - A signed one-time key that the other account created and shared with us.

  • fallback_used - Was the one-time key a fallback key.

  • our_device_keys - Our own DeviceKeys, including cross-signing signatures if applicable, for embedding in encrypted messages.

Source

pub fn create_outbound_session( &self, device: &DeviceData, key_map: &BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>, our_device_keys: DeviceKeys, ) -> Result<Session, SessionCreationError>

Create a new session with another account given a one-time key and a device.

Returns the newly created session or a OlmSessionError if creating a session failed.

§Arguments
  • device - The other account’s device.

  • key_map - A map from the algorithm and device ID to the one-time key that the other account created and shared with us.

  • our_device_keys - Our own DeviceKeys, including cross-signing signatures if applicable, for embedding in encrypted messages.

Source

pub fn create_inbound_session( &mut self, their_identity_key: Curve25519PublicKey, our_device_keys: DeviceKeys, message: &PreKeyMessage, ) -> Result<InboundCreationResult, SessionCreationError>

Create a new session with another account given a pre-key Olm message.

Returns the newly created session or a OlmSessionError if creating a session failed.

§Arguments
  • their_identity_key - The other account’s identity/curve25519 key.

  • our_device_keys - Our own DeviceKeys, including cross-signing signatures if applicable, for embedding in encrypted messages.

  • message - A pre-key Olm message that was sent to us by the other account.

Source

pub fn receive_keys_upload_response( &mut self, response: &Response, ) -> Result<(), OlmError>

Handles a response to a /keys/upload request.

Methods from Deref<Target = StaticAccountData>§

Source

pub async fn create_group_session_pair( &self, room_id: &RoomId, settings: EncryptionSettings, own_sender_data: SenderData, ) -> Result<(OutboundGroupSession, InboundGroupSession), MegolmSessionCreationError>

Create a group session pair.

This session pair can be used to encrypt and decrypt messages meant for a large group of participants.

The outbound session is used to encrypt messages while the inbound one is used to decrypt messages encrypted by the outbound one.

§Arguments
  • room_id - The ID of the room where the group session will be used.

  • settings - Settings determining the algorithm and rotation period of the outbound group session.

Source

pub fn signing_key_id(&self) -> OwnedDeviceKeyId

Get the key ID of our Ed25519 signing key.

Source

pub fn has_signed_raw( &self, signatures: &Signatures, canonical_json: &str, ) -> Result<(), SignatureError>

Check if the given JSON is signed by this Account key.

This method should only be used if an object’s signature needs to be checked multiple times, and you’d like to avoid performing the canonicalization step each time.

Note: Use this method with caution, the canonical_json needs to be correctly canonicalized and make sure that the object you are checking the signature for is allowed to be signed by our own device.

Source

pub fn unsigned_device_keys(&self) -> DeviceKeys

Generate the unsigned DeviceKeys from this StaticAccountData.

Source

pub fn user_id(&self) -> &UserId

Get the user id of the owner of the account.

Source

pub fn device_id(&self) -> &DeviceId

Get the device ID that owns this account.

Source

pub fn identity_keys(&self) -> IdentityKeys

Get the public parts of the identity keys for the account.

Source

pub fn creation_local_time(&self) -> MilliSecondsSinceUnixEpoch

Get the local timestamp creation of the account in secs since epoch.

Trait Implementations§

Source§

impl Debug for Account

Available on non-tarpaulin_include only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Account

Source§

type Target = StaticAccountData

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl PartialEq for Account

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<>
Source§

fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
Available on non-bootstrap only.
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> AsyncTraitDeps for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,