crypto: More SAS content to to-device request logic.

master
Damir Jelić 2020-07-29 13:23:03 +02:00
parent 117ebeaf4b
commit 4634efc092
2 changed files with 18 additions and 8 deletions

View File

@ -231,13 +231,13 @@ mod test {
let mut event = wrap_any_to_device_content( let mut event = wrap_any_to_device_content(
alice.user_id(), alice.user_id(),
AnyToDeviceEventContent::KeyVerificationMac(alice.confirm().unwrap()), get_content_from_request(&alice.confirm().unwrap()),
); );
bob.receive_event(&mut event); bob.receive_event(&mut event);
let mut event = wrap_any_to_device_content( let mut event = wrap_any_to_device_content(
bob.user_id(), bob.user_id(),
AnyToDeviceEventContent::KeyVerificationMac(bob.confirm().unwrap()), get_content_from_request(&bob.confirm().unwrap()),
); );
alice.receive_event(&mut event); alice.receive_event(&mut event);

View File

@ -153,12 +153,16 @@ impl Sas {
/// Does nothing if we're not in a state where we can confirm the short auth /// Does nothing if we're not in a state where we can confirm the short auth
/// string, otherwise returns a `MacEventContent` that needs to be sent to /// string, otherwise returns a `MacEventContent` that needs to be sent to
/// the server. /// the server.
pub fn confirm(&self) -> Option<MacEventContent> { pub fn confirm(&self) -> Option<ToDeviceRequest> {
let mut guard = self.inner.lock().unwrap(); let mut guard = self.inner.lock().unwrap();
let sas: InnerSas = (*guard).clone(); let sas: InnerSas = (*guard).clone();
let (sas, content) = sas.confirm(); let (sas, content) = sas.confirm();
*guard = sas; *guard = sas;
content
content.map(|c| {
let content = AnyToDeviceEventContent::KeyVerificationMac(c);
self.content_to_request(content)
})
} }
/// Are we in a state where we can show the short auth string. /// Are we in a state where we can show the short auth string.
@ -1210,11 +1214,17 @@ mod test {
assert_eq!(alice.emoji().unwrap(), bob.emoji().unwrap()); assert_eq!(alice.emoji().unwrap(), bob.emoji().unwrap());
assert_eq!(alice.decimals().unwrap(), bob.decimals().unwrap()); assert_eq!(alice.decimals().unwrap(), bob.decimals().unwrap());
let event = wrap_to_device_event(alice.user_id(), alice.confirm().unwrap()); let mut event = wrap_any_to_device_content(
bob.receive_event(&mut AnyToDeviceEvent::KeyVerificationMac(event)); alice.user_id(),
get_content_from_request(&alice.confirm().unwrap()),
);
bob.receive_event(&mut event);
let event = wrap_to_device_event(bob.user_id(), bob.confirm().unwrap()); let mut event = wrap_any_to_device_content(
alice.receive_event(&mut AnyToDeviceEvent::KeyVerificationMac(event)); bob.user_id(),
get_content_from_request(&bob.confirm().unwrap()),
);
alice.receive_event(&mut event);
assert!(alice assert!(alice
.verified_devices() .verified_devices()