export_keying_material to its own test
@@ -7,7 +7,7 @@ use std::{
sync::Arc,
};
-use futures::{channel::oneshot, future, StreamExt};
+use futures::{future, StreamExt};
use tokio::{
runtime::{Builder, Runtime},
time::{Duration, Instant},
@@ -98,16 +98,11 @@ fn local_addr() {
}
#[test]
-fn read_after_close_and_export_keying_material() {
+fn read_after_close() {
let _guard = subscribe();
let mut runtime = rt_basic();
let (endpoint, mut incoming) = runtime.enter(endpoint);
const MSG: &[u8] = b"goodbye!";
-
- // compare key material
- let (c_send, mut c_recv) = oneshot::channel();
- let (s_send, mut s_recv) = oneshot::channel();
-
runtime.spawn(async move {
let new_conn = incoming
.next()
@@ -116,12 +111,6 @@ fn read_after_close_and_export_keying_material() {
.await
.expect("connection");
let mut s = new_conn.connection.open_uni().await.unwrap();
- let mut buf = [0u8; 64];
- new_conn
- .connection
- .export_keying_material(&mut buf, b"asdf", b"qwer")
- .unwrap();
- s_send.send(buf).map_err(|_| ()).unwrap();
s.write_all(MSG).await.unwrap();
s.finish().await.unwrap();
});
@@ -132,12 +121,6 @@ fn read_after_close_and_export_keying_material() {
.await
.expect("connect");
tokio::time::delay_until(Instant::now() + Duration::from_millis(100)).await;
- let mut buf = [0u8; 64];
- new_conn
- .connection
- .export_keying_material(&mut buf, b"asdf", b"qwer")
- .unwrap();
- c_send.send(buf).map_err(|_| ()).unwrap();
let stream = new_conn
.uni_streams
.next()
@@ -150,11 +133,37 @@ fn read_after_close_and_export_keying_material() {
.expect("read_to_end");
assert_eq!(msg, MSG);
});
+}
- // prior block_on call guarantees that try_recv's will succeed here
- let c_buf = c_recv.try_recv().unwrap().unwrap();
- let s_buf = s_recv.try_recv().unwrap().unwrap();
- assert_eq!(&c_buf[..], &s_buf[..]);
+#[test]
+fn export_keying_material() {
+ let _guard = subscribe();
+ let mut runtime = rt_basic();
+ let (endpoint, mut incoming) = runtime.enter(endpoint);
+ runtime.block_on(async move {
+ let outgoing_conn = endpoint
+ .connect(&endpoint.local_addr().unwrap(), "localhost")
+ .unwrap()
+ .await
+ .expect("connect");
+ let incoming_conn = incoming
+ .next()
+ .await
+ .expect("endpoint")
+ .await
+ .expect("connection");
+ let mut i_buf = [0u8; 64];
+ incoming_conn
+ .connection
+ .export_keying_material(&mut i_buf, b"asdf", b"qwer")
+ .unwrap();
+ let mut o_buf = [0u8; 64];
+ outgoing_conn
+ .connection
+ .export_keying_material(&mut o_buf, b"asdf", b"qwer")
+ .unwrap();
+ assert_eq!(&i_buf[..], &o_buf[..]);
+ });
}
#[tokio::test]
