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

This commit is contained in:
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(
alice.user_id(),
AnyToDeviceEventContent::KeyVerificationMac(alice.confirm().unwrap()),
get_content_from_request(&alice.confirm().unwrap()),
);
bob.receive_event(&mut event);
let mut event = wrap_any_to_device_content(
bob.user_id(),
AnyToDeviceEventContent::KeyVerificationMac(bob.confirm().unwrap()),
get_content_from_request(&bob.confirm().unwrap()),
);
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
/// string, otherwise returns a `MacEventContent` that needs to be sent to
/// the server.
pub fn confirm(&self) -> Option<MacEventContent> {
pub fn confirm(&self) -> Option<ToDeviceRequest> {
let mut guard = self.inner.lock().unwrap();
let sas: InnerSas = (*guard).clone();
let (sas, content) = sas.confirm();
*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.
@ -1210,11 +1214,17 @@ mod test {
assert_eq!(alice.emoji().unwrap(), bob.emoji().unwrap());
assert_eq!(alice.decimals().unwrap(), bob.decimals().unwrap());
let event = wrap_to_device_event(alice.user_id(), alice.confirm().unwrap());
bob.receive_event(&mut AnyToDeviceEvent::KeyVerificationMac(event));
let mut event = wrap_any_to_device_content(
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());
alice.receive_event(&mut AnyToDeviceEvent::KeyVerificationMac(event));
let mut event = wrap_any_to_device_content(
bob.user_id(),
get_content_from_request(&bob.confirm().unwrap()),
);
alice.receive_event(&mut event);
assert!(alice
.verified_devices()