Replace Arc<Box<DeviceId>> by Arc<DeviceId>

This commit is contained in:
Jonas Platte 2021-06-05 16:31:40 +02:00
parent 0df782e93e
commit eed2b37885
No known key found for this signature in database
GPG key ID: 7D261D771D915378
9 changed files with 27 additions and 27 deletions

View file

@ -55,7 +55,7 @@ use crate::{OlmMachine, ReadOnlyAccount};
#[derive(Clone, Serialize, Deserialize)]
pub struct ReadOnlyDevice {
user_id: Arc<UserId>,
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
algorithms: Arc<[EventEncryptionAlgorithm]>,
keys: Arc<BTreeMap<DeviceKeyId, String>>,
pub(crate) signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>,
@ -301,7 +301,7 @@ impl ReadOnlyDevice {
) -> Self {
Self {
user_id: Arc::new(user_id),
device_id: Arc::new(device_id),
device_id: device_id.into(),
display_name: Arc::new(display_name),
trust_state: Arc::new(Atomic::new(trust_state)),
signatures: Arc::new(signatures),
@ -546,7 +546,7 @@ impl TryFrom<&DeviceKeys> for ReadOnlyDevice {
fn try_from(device_keys: &DeviceKeys) -> Result<Self, Self::Error> {
let device = Self {
user_id: Arc::new(device_keys.user_id.clone()),
device_id: Arc::new(device_keys.device_id.clone()),
device_id: device_keys.device_id.clone().into(),
algorithms: device_keys.algorithms.as_slice().into(),
signatures: Arc::new(device_keys.signatures.clone()),
keys: Arc::new(device_keys.keys.clone()),

View file

@ -23,7 +23,7 @@ use matrix_sdk_common::{
api::r0::keys::get_keys::Response as KeysQueryResponse,
encryption::DeviceKeys,
executor::spawn,
identifiers::{DeviceIdBox, UserId},
identifiers::{DeviceId, DeviceIdBox, UserId},
};
use tracing::{trace, warn};
@ -46,14 +46,14 @@ enum DeviceChange {
#[derive(Debug, Clone)]
pub(crate) struct IdentityManager {
user_id: Arc<UserId>,
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
store: Store,
}
impl IdentityManager {
const MAX_KEY_QUERY_USERS: usize = 250;
pub fn new(user_id: Arc<UserId>, device_id: Arc<DeviceIdBox>, store: Store) -> Self {
pub fn new(user_id: Arc<UserId>, device_id: Arc<DeviceId>, store: Store) -> Self {
IdentityManager { user_id, device_id, store }
}
@ -134,7 +134,7 @@ impl IdentityManager {
async fn update_user_devices(
store: Store,
own_user_id: Arc<UserId>,
own_device_id: Arc<DeviceIdBox>,
own_device_id: Arc<DeviceId>,
user_id: UserId,
device_map: BTreeMap<DeviceIdBox, DeviceKeys>,
) -> StoreResult<DeviceChanges> {
@ -144,7 +144,7 @@ impl IdentityManager {
let tasks = device_map.into_iter().filter_map(|(device_id, device_keys)| {
// We don't need our own device in the device store.
if user_id == *own_user_id && device_id == *own_device_id {
if user_id == *own_user_id && *device_id == *own_device_id {
None
} else if user_id != device_keys.user_id || device_id != device_keys.device_id {
warn!(
@ -431,7 +431,7 @@ pub(crate) mod test {
Arc::new(Box::new(MemoryStore::new())),
verification,
);
IdentityManager::new(user_id, Arc::new(device_id()), store)
IdentityManager::new(user_id, device_id().into(), store)
}
pub(crate) fn other_key_query() -> KeyQueryResponse {

View file

@ -125,7 +125,7 @@ impl WaitQueue {
#[derive(Debug, Clone)]
pub(crate) struct KeyRequestMachine {
user_id: Arc<UserId>,
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
store: Store,
outbound_group_sessions: GroupSessionCache,
outgoing_to_device_requests: Arc<DashMap<Uuid, OutgoingRequest>>,
@ -210,7 +210,7 @@ fn wrap_key_request_content(
impl KeyRequestMachine {
pub fn new(
user_id: Arc<UserId>,
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
store: Store,
outbound_group_sessions: GroupSessionCache,
users_for_key_claim: Arc<DashMap<UserId, DashSet<DeviceIdBox>>>,
@ -854,7 +854,7 @@ mod test {
KeyRequestMachine::new(
user_id,
Arc::new(bob_device_id()),
bob_device_id().into(),
store,
session_cache,
Arc::new(DashMap::new()),
@ -862,7 +862,7 @@ mod test {
}
async fn get_machine() -> KeyRequestMachine {
let user_id = Arc::new(alice_id());
let user_id: Arc<UserId> = alice_id().into();
let account = ReadOnlyAccount::new(&user_id, &alice_device_id());
let device = ReadOnlyDevice::from_account(&account).await;
let store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new()));
@ -874,7 +874,7 @@ mod test {
KeyRequestMachine::new(
user_id,
Arc::new(alice_device_id()),
alice_device_id().into(),
store,
session_cache,
Arc::new(DashMap::new()),

View file

@ -71,7 +71,7 @@ pub struct OlmMachine {
/// The unique user id that owns this account.
user_id: Arc<UserId>,
/// The unique device id of the device that holds this account.
device_id: Arc<Box<DeviceId>>,
device_id: Arc<DeviceId>,
/// Our underlying Olm Account holding our identity keys.
account: Account,
/// The private part of our cross signing identity.
@ -149,7 +149,7 @@ impl OlmMachine {
VerificationMachine::new(account.clone(), user_identity.clone(), store.clone());
let store =
Store::new(user_id.clone(), user_identity.clone(), store, verification_machine.clone());
let device_id: Arc<DeviceIdBox> = Arc::new(device_id);
let device_id: Arc<DeviceId> = device_id.into();
let users_for_key_claim = Arc::new(DashMap::new());
let account = Account { inner: account, store: store.clone() };

View file

@ -431,7 +431,7 @@ impl Account {
#[derive(Clone)]
pub struct ReadOnlyAccount {
pub(crate) user_id: Arc<UserId>,
pub(crate) device_id: Arc<Box<DeviceId>>,
pub(crate) device_id: Arc<DeviceId>,
inner: Arc<Mutex<OlmAccount>>,
pub(crate) identity_keys: Arc<IdentityKeys>,
shared: Arc<AtomicBool>,
@ -502,7 +502,7 @@ impl ReadOnlyAccount {
Self {
user_id: Arc::new(user_id.to_owned()),
device_id: Arc::new(device_id.into()),
device_id: device_id.to_owned().into(),
inner: Arc::new(Mutex::new(account)),
identity_keys: Arc::new(identity_keys),
shared: Arc::new(AtomicBool::new(false)),
@ -676,7 +676,7 @@ impl ReadOnlyAccount {
Ok(Self {
user_id: Arc::new(pickle.user_id),
device_id: Arc::new(pickle.device_id),
device_id: pickle.device_id.into(),
inner: Arc::new(Mutex::new(account)),
identity_keys: Arc::new(identity_keys),
shared: Arc::new(AtomicBool::from(pickle.shared)),
@ -700,7 +700,7 @@ impl ReadOnlyAccount {
DeviceKeys::new(
(*self.user_id).clone(),
(*self.device_id).clone(),
(*self.device_id).to_owned(),
Self::ALGORITHMS.iter().map(|a| (&**a).clone()).collect(),
keys,
BTreeMap::new(),

View file

@ -118,7 +118,7 @@ impl EncryptionSettings {
#[derive(Clone)]
pub struct OutboundGroupSession {
inner: Arc<Mutex<OlmOutboundGroupSession>>,
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
account_identity_keys: Arc<IdentityKeys>,
session_id: Arc<str>,
room_id: Arc<RoomId>,
@ -148,7 +148,7 @@ impl OutboundGroupSession {
/// * `settings` - Settings determining the algorithm and rotation period of
/// the outbound group session.
pub fn new(
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
identity_keys: Arc<IdentityKeys>,
room_id: &RoomId,
settings: EncryptionSettings,
@ -450,7 +450,7 @@ impl OutboundGroupSession {
/// * `pickle_mode` - The mode that was used to pickle the session, either
/// an unencrypted mode or an encrypted using passphrase.
pub fn from_pickle(
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
identity_keys: Arc<IdentityKeys>,
pickle: PickledOutboundGroupSession,
pickling_mode: PicklingMode,

View file

@ -45,7 +45,7 @@ use crate::{
#[derive(Clone)]
pub struct Session {
pub(crate) user_id: Arc<UserId>,
pub(crate) device_id: Arc<Box<DeviceId>>,
pub(crate) device_id: Arc<DeviceId>,
pub(crate) our_identity_keys: Arc<IdentityKeys>,
pub(crate) inner: Arc<Mutex<OlmSession>>,
pub(crate) session_id: Arc<str>,
@ -214,7 +214,7 @@ impl Session {
/// an unencrypted mode or an encrypted using passphrase.
pub fn from_pickle(
user_id: Arc<UserId>,
device_id: Arc<Box<DeviceId>>,
device_id: Arc<DeviceId>,
our_identity_keys: Arc<IdentityKeys>,
pickle: PickledSession,
pickle_mode: PicklingMode,

View file

@ -339,7 +339,7 @@ mod test {
VerificationMachine::new(account.clone(), identity.clone(), store.clone());
let user_id = Arc::new(user_id);
let device_id = Arc::new(device_id);
let device_id = device_id.into();
let store = Store::new(user_id.clone(), identity, store, verification);

View file

@ -117,7 +117,7 @@ impl EncodeKey for (&str, &str, &str) {
#[derive(Clone, Debug)]
pub struct AccountInfo {
user_id: Arc<UserId>,
device_id: Arc<DeviceIdBox>,
device_id: Arc<DeviceId>,
identity_keys: Arc<IdentityKeys>,
}