File tree 2 files changed +35
-0
lines changed
bindings/rust/s2n-tls/src
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -947,6 +947,14 @@ impl Connection {
947
947
} )
948
948
}
949
949
950
+ pub fn application_protocol ( & self ) -> Option < & [ u8 ] > {
951
+ let protocol = unsafe { s2n_get_application_protocol ( self . connection . as_ptr ( ) ) } ;
952
+ if protocol. is_null ( ) {
953
+ return None ;
954
+ }
955
+ Some ( unsafe { CStr :: from_ptr ( protocol) . to_bytes ( ) } )
956
+ }
957
+
950
958
/// Provides access to the TLS-Exporter functionality.
951
959
///
952
960
/// See https://datatracker.ietf.org/doc/html/rfc5705 and https://www.rfc-editor.org/rfc/rfc8446.
Original file line number Diff line number Diff line change @@ -998,4 +998,31 @@ mod tests {
998
998
999
999
Ok ( ( ) )
1000
1000
}
1001
+
1002
+ #[ test]
1003
+ fn no_application_protocol ( ) -> Result < ( ) , Error > {
1004
+ let config = config_builder ( & security:: DEFAULT ) ?. build ( ) ?;
1005
+ let mut pair = tls_pair ( config) ;
1006
+ assert ! ( poll_tls_pair_result( & mut pair) . is_ok( ) ) ;
1007
+ assert ! ( pair. server. 0 . connection. application_protocol( ) . is_none( ) ) ;
1008
+ Ok ( ( ) )
1009
+ }
1010
+
1011
+ #[ test]
1012
+ fn application_protocol ( ) -> Result < ( ) , Error > {
1013
+ let config = config_builder ( & security:: DEFAULT ) ?. build ( ) ?;
1014
+ let mut pair = tls_pair ( config) ;
1015
+ pair. server
1016
+ . 0
1017
+ . connection
1018
+ . set_application_protocol_preference ( [ "http/1.1" , "h2" ] ) ?;
1019
+ pair. client
1020
+ . 0
1021
+ . connection
1022
+ . append_application_protocol_preference ( b"h2" ) ?;
1023
+ assert ! ( poll_tls_pair_result( & mut pair) . is_ok( ) ) ;
1024
+ let protocol = pair. server . 0 . connection . application_protocol ( ) . unwrap ( ) ;
1025
+ assert_eq ! ( protocol, b"h2" ) ;
1026
+ Ok ( ( ) )
1027
+ }
1001
1028
}
You can’t perform that action at this time.
0 commit comments