1+ use std:: future:: Future ;
2+ use std:: pin:: Pin ;
13use std:: time:: SystemTime ;
24
35use rand:: Rng ;
46use rustls:: pki_types:: CertificateDer ;
7+ use tokio:: time:: sleep;
58use util:: conn:: conn_pipe:: * ;
69use util:: KeyingMaterialExporter ;
710
@@ -79,24 +82,27 @@ async fn pipe_conn(
7982 Ok ( ( client, sever) )
8083}
8184
82- fn psk_callback_client ( hint : & [ u8 ] ) -> Result < Vec < u8 > > {
85+ fn psk_callback_client ( hint : & [ u8 ] ) -> Pin < Box < dyn Future < Output = Result < Vec < u8 > > > + Send > > {
8386 trace ! (
8487 "Server's hint: {}" ,
8588 String :: from_utf8( hint. to_vec( ) ) . unwrap( )
8689 ) ;
87- Ok ( vec ! [ 0xAB , 0xC1 , 0x23 ] )
90+ Box :: pin ( async move { Ok ( vec ! [ 0xAB , 0xC1 , 0x23 ] ) } )
8891}
8992
90- fn psk_callback_server ( hint : & [ u8 ] ) -> Result < Vec < u8 > > {
93+ fn psk_callback_server ( hint : & [ u8 ] ) -> Pin < Box < dyn Future < Output = Result < Vec < u8 > > > + Send > > {
9194 trace ! (
9295 "Client's hint: {}" ,
9396 String :: from_utf8( hint. to_vec( ) ) . unwrap( )
9497 ) ;
95- Ok ( vec ! [ 0xAB , 0xC1 , 0x23 ] )
98+ Box :: pin ( async move {
99+ sleep ( Duration :: from_millis ( 1 ) ) . await ; // Now it's possible to await in the psk callback
100+ Ok ( vec ! [ 0xAB , 0xC1 , 0x23 ] )
101+ } )
96102}
97103
98- fn psk_callback_hint_fail ( _hint : & [ u8 ] ) -> Result < Vec < u8 > > {
99- Err ( Error :: Other ( ERR_PSK_REJECTED . to_owned ( ) ) )
104+ fn psk_callback_hint_fail ( _hint : & [ u8 ] ) -> Pin < Box < dyn Future < Output = Result < Vec < u8 > > > + Send > > {
105+ Box :: pin ( async move { Err ( Error :: Other ( ERR_PSK_REJECTED . to_owned ( ) ) ) } )
100106}
101107
102108async fn create_test_client (
@@ -1617,7 +1623,7 @@ async fn test_cipher_suite_configuration() -> Result<()> {
16171623 assert ! ( cipher_suite. is_some( ) , "{name} expected some, but got none" ) ;
16181624 if let Some ( cs) = & * cipher_suite {
16191625 assert_eq ! ( cs. id( ) , want_cs,
1620- "test_cipher_suite_configuration: Server Selected Bad Cipher Suite '{}': expected({}) actual({})" ,
1626+ "test_cipher_suite_configuration: Server Selected Bad Cipher Suite '{}': expected({}) actual({})" ,
16211627 name, want_cs, cs. id( ) ) ;
16221628 }
16231629 }
@@ -1630,8 +1636,8 @@ async fn test_cipher_suite_configuration() -> Result<()> {
16301636 Ok ( ( ) )
16311637}
16321638
1633- fn psk_callback ( _b : & [ u8 ] ) -> Result < Vec < u8 > > {
1634- Ok ( vec ! [ 0x00 , 0x01 , 0x02 ] )
1639+ fn psk_callback ( _b : & [ u8 ] ) -> Pin < Box < dyn Future < Output = Result < Vec < u8 > > > + Send > > {
1640+ Box :: pin ( async move { Ok ( vec ! [ 0x00 , 0x01 , 0x02 ] ) } )
16351641}
16361642
16371643#[ tokio:: test]
0 commit comments