crypto: Don't require the account to be passed when encrypting.

master
Damir Jelić 2020-07-21 12:46:06 +02:00
parent e50cf39a17
commit c3f00c96f8
2 changed files with 7 additions and 13 deletions

View File

@ -804,9 +804,7 @@ impl OlmMachine {
event_type: EventType, event_type: EventType,
content: Value, content: Value,
) -> OlmResult<EncryptedEventContent> { ) -> OlmResult<EncryptedEventContent> {
let message = session let message = session.encrypt(recipient_device, event_type, content).await;
.encrypt(self.account.clone(), recipient_device, event_type, content)
.await;
self.store.save_sessions(&[session]).await?; self.store.save_sessions(&[session]).await?;
message message

View File

@ -27,7 +27,7 @@ pub use olm_rs::{
utility::OlmUtility, utility::OlmUtility,
}; };
use super::{Account, IdentityKeys}; use super::IdentityKeys;
use crate::error::{EventError, OlmResult}; use crate::error::{EventError, OlmResult};
use crate::Device; use crate::Device;
@ -98,7 +98,6 @@ impl Session {
/// content. /// content.
pub async fn encrypt( pub async fn encrypt(
&mut self, &mut self,
account: Account,
recipient_device: &Device, recipient_device: &Device,
event_type: EventType, event_type: EventType,
content: Value, content: Value,
@ -106,15 +105,12 @@ impl Session {
let recipient_signing_key = recipient_device let recipient_signing_key = recipient_device
.get_key(KeyAlgorithm::Ed25519) .get_key(KeyAlgorithm::Ed25519)
.ok_or(EventError::MissingSigningKey)?; .ok_or(EventError::MissingSigningKey)?;
let recipient_sender_key = recipient_device
.get_key(KeyAlgorithm::Curve25519)
.ok_or(EventError::MissingSigningKey)?;
let payload = json!({ let payload = json!({
"sender": account.user_id.to_string(), "sender": self.user_id.as_str(),
"sender_device": account.device_id.as_ref(), "sender_device": self.device_id.as_ref(),
"keys": { "keys": {
"ed25519": account.identity_keys().ed25519(), "ed25519": self.our_identity_keys.ed25519(),
}, },
"recipient": recipient_device.user_id(), "recipient": recipient_device.user_id(),
"recipient_keys": { "recipient_keys": {
@ -133,12 +129,12 @@ impl Session {
let ciphertext = CiphertextInfo::new(ciphertext.1, (message_type as u32).into()); let ciphertext = CiphertextInfo::new(ciphertext.1, (message_type as u32).into());
let mut content = BTreeMap::new(); let mut content = BTreeMap::new();
content.insert(recipient_sender_key.to_owned(), ciphertext); content.insert((&*self.sender_key).to_owned(), ciphertext);
Ok(EncryptedEventContent::OlmV1Curve25519AesSha2( Ok(EncryptedEventContent::OlmV1Curve25519AesSha2(
OlmV1Curve25519AesSha2Content::new( OlmV1Curve25519AesSha2Content::new(
content, content,
account.identity_keys().curve25519().to_owned(), self.our_identity_keys.curve25519().to_string(),
), ),
)) ))
} }