Struct matrix_sdk_crypto::olm::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

source§

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

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

impl Deref for Account

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

§

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>).
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§

impl<T> Instrument for T

source§

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

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

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<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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

source§

impl<T> WithSubscriber for T

source§

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
source§

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> SendOutsideWasm for T
where T: Send,

source§

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