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
impl Account
sourcepub fn with_device_id(user_id: &UserId, device_id: &DeviceId) -> Self
pub fn with_device_id(user_id: &UserId, device_id: &DeviceId) -> Self
Create a fresh new account, this will generate the identity key-pair.
sourcepub fn new(user_id: &UserId) -> Self
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.
sourcepub fn new_dehydrated(user_id: &UserId) -> Self
pub fn new_dehydrated(user_id: &UserId) -> Self
Create a new random Olm Account for a dehydrated device
sourcepub fn static_data(&self) -> &StaticAccountData
pub fn static_data(&self) -> &StaticAccountData
Get the immutable data for this account.
sourcepub fn update_uploaded_key_count(&mut self, new_count: u64)
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.
sourcepub fn uploaded_key_count(&self) -> u64
pub fn uploaded_key_count(&self) -> u64
Get the currently known uploaded key count.
Has the account been shared with the server.
Mark the account as shared.
Messages shouldn’t be encrypted with the session before it has been shared.
sourcepub fn one_time_keys(&self) -> HashMap<KeyId, Curve25519PublicKey>
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.
sourcepub fn generate_one_time_keys(
&mut self,
count: usize,
) -> OneTimeKeyGenerationResult
pub fn generate_one_time_keys( &mut self, count: usize, ) -> OneTimeKeyGenerationResult
Generate count number of one-time keys.
sourcepub fn max_one_time_keys(&self) -> usize
pub fn max_one_time_keys(&self) -> usize
Get the maximum number of one-time keys the account can hold.
sourcepub fn generate_one_time_keys_if_needed(&mut self) -> Option<u64>
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.
sourcepub fn keys_for_upload(
&self,
) -> (Option<DeviceKeys>, BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>, BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>)
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.
sourcepub fn mark_keys_as_published(&mut self)
pub fn mark_keys_as_published(&mut self)
Mark the current set of one-time keys as being published.
sourcepub fn sign(&self, string: &str) -> Ed25519Signature
pub fn sign(&self, string: &str) -> Ed25519Signature
Sign the given string using the accounts signing key.
Returns the signature as a base64 encoded string.
sourcepub fn pickle(&self) -> PickledAccount
pub fn pickle(&self) -> PickledAccount
Get a serializable version of the Account
so it can be persisted.
sourcepub fn from_pickle(pickle: PickledAccount) -> Result<Self, PickleError>
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.
sourcepub fn device_keys(&self) -> DeviceKeys
pub fn device_keys(&self) -> DeviceKeys
Sign the device keys of the account and return them so they can be uploaded.
sourcepub async fn bootstrap_cross_signing(
&self,
) -> (PrivateCrossSigningIdentity, UploadSigningKeysRequest, SignatureUploadRequest)
pub async fn bootstrap_cross_signing( &self, ) -> (PrivateCrossSigningIdentity, UploadSigningKeysRequest, SignatureUploadRequest)
Bootstrap Cross-Signing
sourcepub fn sign_cross_signing_key(
&self,
cross_signing_key: &mut CrossSigningKey,
) -> Result<(), SignatureError>
pub fn sign_cross_signing_key( &self, cross_signing_key: &mut CrossSigningKey, ) -> Result<(), SignatureError>
Sign the given CrossSigning Key in place
sourcepub fn sign_master_key(
&self,
master_key: &MasterPubkey,
) -> Result<SignatureUploadRequest, SignatureError>
pub fn sign_master_key( &self, master_key: &MasterPubkey, ) -> Result<SignatureUploadRequest, SignatureError>
Sign the given Master Key
sourcepub fn sign_json(&self, json: Value) -> Result<Ed25519Signature, SignatureError>
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.
sourcepub fn signed_one_time_keys(
&self,
) -> BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>
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
.
sourcepub fn signed_fallback_keys(
&self,
) -> BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>
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.
sourcepub fn create_outbound_session_helper(
&self,
config: SessionConfig,
identity_key: Curve25519PublicKey,
one_time_key: Curve25519PublicKey,
fallback_used: bool,
our_device_keys: DeviceKeys,
) -> Session
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 ownDeviceKeys
, including cross-signing signatures if applicable, for embedding in encrypted messages.
sourcepub fn create_outbound_session(
&self,
device: &DeviceData,
key_map: &BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>,
our_device_keys: DeviceKeys,
) -> Result<Session, SessionCreationError>
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 ownDeviceKeys
, including cross-signing signatures if applicable, for embedding in encrypted messages.
sourcepub fn create_inbound_session(
&mut self,
their_identity_key: Curve25519PublicKey,
our_device_keys: DeviceKeys,
message: &PreKeyMessage,
) -> Result<InboundCreationResult, SessionCreationError>
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 ownDeviceKeys
, 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.
Methods from Deref<Target = StaticAccountData>§
sourcepub async fn create_group_session_pair(
&self,
room_id: &RoomId,
settings: EncryptionSettings,
own_sender_data: SenderData,
) -> Result<(OutboundGroupSession, InboundGroupSession), MegolmSessionCreationError>
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.
sourcepub fn signing_key_id(&self) -> OwnedDeviceKeyId
pub fn signing_key_id(&self) -> OwnedDeviceKeyId
Get the key ID of our Ed25519 signing key.
sourcepub fn has_signed_raw(
&self,
signatures: &Signatures,
canonical_json: &str,
) -> Result<(), SignatureError>
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.
sourcepub fn unsigned_device_keys(&self) -> DeviceKeys
pub fn unsigned_device_keys(&self) -> DeviceKeys
Generate the unsigned DeviceKeys
from this StaticAccountData
.
sourcepub fn identity_keys(&self) -> IdentityKeys
pub fn identity_keys(&self) -> IdentityKeys
Get the public parts of the identity keys for the account.
sourcepub fn creation_local_time(&self) -> MilliSecondsSinceUnixEpoch
pub fn creation_local_time(&self) -> MilliSecondsSinceUnixEpoch
Get the local timestamp creation of the account in secs since epoch.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Account
impl RefUnwindSafe for Account
impl Send for Account
impl Sync for Account
impl Unpin for Account
impl UnwindSafe for Account
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
§impl<T> CompatExt for T
impl<T> CompatExt for T
source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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