Skip to content

Commit 02c61cd

Browse files
committed
EncryptionInfo: copy inner content from wrapped structure
Soon, we're going to have two different types of `EncryptionInfo` depending on what the underlying AlgorithmInfo was. As preparation for that, we need to copy the inner fields at construction time.
1 parent c8fa6da commit 02c61cd

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

src/responses.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -166,29 +166,29 @@ impl DecryptedRoomEvent {
166166
/// unless the `verification_state` is as well trusted.
167167
#[wasm_bindgen(getter)]
168168
pub fn sender(&self) -> Option<identifiers::UserId> {
169-
Some(self.encryption_info.as_ref()?.sender())
169+
Some(self.encryption_info.as_ref()?.sender.clone())
170170
}
171171

172172
/// The device ID of the device that sent us the event, note this
173173
/// is untrusted data unless `verification_state` is as well
174174
/// trusted.
175175
#[wasm_bindgen(getter, js_name = "senderDevice")]
176176
pub fn sender_device(&self) -> Option<identifiers::DeviceId> {
177-
self.encryption_info.as_ref()?.sender_device()
177+
self.encryption_info.as_ref()?.sender_device.clone()
178178
}
179179

180180
/// The Curve25519 key of the device that created the megolm
181181
/// decryption key originally.
182182
#[wasm_bindgen(getter, js_name = "senderCurve25519Key")]
183183
pub fn sender_curve25519_key(&self) -> Option<JsString> {
184-
self.encryption_info.as_ref()?.sender_curve25519_key()
184+
Some(self.encryption_info.as_ref()?.sender_curve25519_key_base64.as_str().into())
185185
}
186186

187187
/// The signing Ed25519 key that have created the megolm key that
188188
/// was used to decrypt this session.
189189
#[wasm_bindgen(getter, js_name = "senderClaimedEd25519Key")]
190190
pub fn sender_claimed_ed25519_key(&self) -> Option<JsString> {
191-
self.encryption_info.as_ref()?.sender_claimed_ed25519_key()
191+
Some(self.encryption_info.as_ref()?.sender_claimed_ed25519_key.as_ref()?.as_str().into())
192192
}
193193

194194
/// Returns an empty array
@@ -227,46 +227,35 @@ impl From<matrix_sdk_common::deserialized_responses::TimelineEvent> for Decrypte
227227
#[wasm_bindgen()]
228228
#[derive(Debug)]
229229
pub struct EncryptionInfo {
230-
inner: Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>,
231-
}
230+
/// The user ID of the sender of the event.
231+
///
232+
/// Note this is untrusted data unless {@link shieldState} shows that the
233+
/// sender is verified.
234+
#[wasm_bindgen(getter_with_clone)]
235+
pub sender: identifiers::UserId,
232236

233-
#[wasm_bindgen()]
234-
impl EncryptionInfo {
235-
/// The user ID of the event sender. Note this is untrusted data
236-
/// unless `verification_state` is also trusted.
237-
#[wasm_bindgen(getter)]
238-
pub fn sender(&self) -> identifiers::UserId {
239-
identifiers::UserId::from(self.inner.sender.clone())
240-
}
237+
/// The device ID of the device that sent us the event.
238+
///
239+
/// Note this is untrusted data unless {@link shieldState} shows that the
240+
/// sender is verified.
241+
#[wasm_bindgen(getter_with_clone, js_name = "senderDevice")]
242+
pub sender_device: Option<identifiers::DeviceId>,
241243

242-
/// The device ID of the device that sent us the event. Note this
243-
/// is untrusted data unless `verification_state` is also
244-
/// trusted.
245-
#[wasm_bindgen(getter, js_name = "senderDevice")]
246-
pub fn sender_device(&self) -> Option<identifiers::DeviceId> {
247-
Some(self.inner.sender_device.as_ref()?.clone().into())
248-
}
249-
250-
/// The Curve25519 key of the device that created the megolm
251-
/// decryption key originally.
252-
#[wasm_bindgen(getter, js_name = "senderCurve25519Key")]
253-
pub fn sender_curve25519_key(&self) -> Option<JsString> {
254-
Some(match &self.inner.algorithm_info {
255-
AlgorithmInfo::MegolmV1AesSha2 { curve25519_key, .. } => curve25519_key.clone().into(),
256-
})
257-
}
244+
/// The base64-encoded public Curve25519 key of the device that created the
245+
/// megolm decryption key originally.
246+
#[wasm_bindgen(getter_with_clone, js_name = "senderCurve25519Key")]
247+
pub sender_curve25519_key_base64: String,
258248

259249
/// The signing Ed25519 key that created the megolm key that
260250
/// was used to decrypt this session.
261-
#[wasm_bindgen(getter, js_name = "senderClaimedEd25519Key")]
262-
pub fn sender_claimed_ed25519_key(&self) -> Option<JsString> {
263-
match &self.inner.algorithm_info {
264-
AlgorithmInfo::MegolmV1AesSha2 { sender_claimed_keys, .. } => {
265-
sender_claimed_keys.get(&ruma::DeviceKeyAlgorithm::Ed25519).cloned().map(Into::into)
266-
}
267-
}
268-
}
251+
#[wasm_bindgen(getter_with_clone, js_name = "senderClaimedEd25519Key")]
252+
pub sender_claimed_ed25519_key: Option<String>,
253+
254+
verification_state: matrix_sdk_common::deserialized_responses::VerificationState,
255+
}
269256

257+
#[wasm_bindgen()]
258+
impl EncryptionInfo {
270259
/// The verification state of the device that sent us the event.
271260
/// Note this is the state of the device at the time of
272261
/// decryption. It may change in the future if a device gets
@@ -280,7 +269,7 @@ impl EncryptionInfo {
280269
/// (both get a red shield in strict mode).
281270
#[wasm_bindgen(js_name = "shieldState")]
282271
pub fn shield_state(&self, strict: bool) -> encryption::ShieldState {
283-
let verification_state = &self.inner.verification_state;
272+
let verification_state = &self.verification_state;
284273

285274
if strict {
286275
verification_state.to_shield_state_strict()
@@ -293,6 +282,17 @@ impl EncryptionInfo {
293282

294283
impl From<Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>> for EncryptionInfo {
295284
fn from(value: Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>) -> Self {
296-
Self { inner: value }
285+
match &value.algorithm_info {
286+
AlgorithmInfo::MegolmV1AesSha2 { curve25519_key, sender_claimed_keys, .. } => Self {
287+
sender: value.sender.clone().into(),
288+
sender_device: value.sender_device.clone().map(Into::into),
289+
sender_curve25519_key_base64: curve25519_key.clone(),
290+
sender_claimed_ed25519_key: sender_claimed_keys
291+
.get(&ruma::DeviceKeyAlgorithm::Ed25519)
292+
.cloned()
293+
.into(),
294+
verification_state: value.verification_state.clone(),
295+
},
296+
}
297297
}
298298
}

0 commit comments

Comments
 (0)