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