33
44#![ allow( clippy:: missing_safety_doc) ] // TODO add safety docs
55
6+ #[ cfg( feature = "unstable-renegotiate" ) ]
7+ use crate :: renegotiate:: RenegotiateState ;
68use crate :: {
79 callbacks:: * ,
810 cert_chain:: CertificateChain ,
@@ -580,23 +582,33 @@ impl Connection {
580582 /// [negotiate](`Self::poll_negotiate`) has succeeded.
581583 ///
582584 /// Returns the number of bytes written, and may indicate a partial write.
585+ #[ cfg( not( feature = "unstable-renegotiate" ) ) ]
583586 pub fn poll_send ( & mut self , buf : & [ u8 ] ) -> Poll < Result < usize , Error > > {
584587 let mut blocked = s2n_blocked_status:: NOT_BLOCKED ;
585588 let buf_len: isize = buf. len ( ) . try_into ( ) . map_err ( |_| Error :: INVALID_INPUT ) ?;
586589 let buf_ptr = buf. as_ptr ( ) as * const :: libc:: c_void ;
587590 unsafe { s2n_send ( self . connection . as_ptr ( ) , buf_ptr, buf_len, & mut blocked) . into_poll ( ) }
588591 }
589592
593+ #[ cfg( not( feature = "unstable-renegotiate" ) ) ]
594+ pub ( crate ) fn poll_recv_raw (
595+ & mut self ,
596+ buf_ptr : * mut :: libc:: c_void ,
597+ buf_len : isize ,
598+ ) -> Poll < Result < usize , Error > > {
599+ let mut blocked = s2n_blocked_status:: NOT_BLOCKED ;
600+ unsafe { s2n_recv ( self . connection . as_ptr ( ) , buf_ptr, buf_len, & mut blocked) . into_poll ( ) }
601+ }
602+
590603 /// Reads and decrypts data from a connection where
591604 /// [negotiate](`Self::poll_negotiate`) has succeeded.
592605 ///
593606 /// Returns the number of bytes read, and may indicate a partial read.
594607 /// 0 bytes returned indicates EOF due to connection closure.
595608 pub fn poll_recv ( & mut self , buf : & mut [ u8 ] ) -> Poll < Result < usize , Error > > {
596- let mut blocked = s2n_blocked_status:: NOT_BLOCKED ;
597609 let buf_len: isize = buf. len ( ) . try_into ( ) . map_err ( |_| Error :: INVALID_INPUT ) ?;
598610 let buf_ptr = buf. as_ptr ( ) as * mut :: libc:: c_void ;
599- unsafe { s2n_recv ( self . connection . as_ptr ( ) , buf_ptr, buf_len, & mut blocked ) . into_poll ( ) }
611+ self . poll_recv_raw ( buf_ptr, buf_len)
600612 }
601613
602614 /// Reads and decrypts data from a connection where
@@ -614,7 +626,6 @@ impl Connection {
614626 & mut self ,
615627 buf : & mut [ MaybeUninit < u8 > ] ,
616628 ) -> Poll < Result < usize , Error > > {
617- let mut blocked = s2n_blocked_status:: NOT_BLOCKED ;
618629 let buf_len: isize = buf. len ( ) . try_into ( ) . map_err ( |_| Error :: INVALID_INPUT ) ?;
619630 let buf_ptr = buf. as_ptr ( ) as * mut :: libc:: c_void ;
620631
@@ -623,7 +634,7 @@ impl Connection {
623634 // 2. if s2n_recv returns `+n`, it guarantees that the first
624635 // `n` bytes of `buf` have been initialized, which allows this
625636 // function to return `Ok(n)`
626- unsafe { s2n_recv ( self . connection . as_ptr ( ) , buf_ptr, buf_len, & mut blocked ) . into_poll ( ) }
637+ self . poll_recv_raw ( buf_ptr, buf_len)
627638 }
628639
629640 /// Attempts to flush any data previously buffered by a call to [send](`Self::poll_send`).
@@ -1168,6 +1179,16 @@ impl Connection {
11681179 Some ( app_context) => app_context. downcast_mut :: < T > ( ) ,
11691180 }
11701181 }
1182+
1183+ #[ cfg( feature = "unstable-renegotiate" ) ]
1184+ pub ( crate ) fn renegotiate_state_mut ( & mut self ) -> & mut RenegotiateState {
1185+ & mut self . context_mut ( ) . renegotiate_state
1186+ }
1187+
1188+ #[ cfg( feature = "unstable-renegotiate" ) ]
1189+ pub ( crate ) fn renegotiate_state ( & self ) -> & RenegotiateState {
1190+ & self . context ( ) . renegotiate_state
1191+ }
11711192}
11721193
11731194struct Context {
@@ -1177,6 +1198,8 @@ struct Context {
11771198 verify_host_callback : Option < Box < dyn VerifyHostNameCallback > > ,
11781199 connection_initialized : bool ,
11791200 app_context : Option < Box < dyn Any + Send + Sync > > ,
1201+ #[ cfg( feature = "unstable-renegotiate" ) ]
1202+ pub ( crate ) renegotiate_state : RenegotiateState ,
11801203}
11811204
11821205impl Context {
@@ -1188,6 +1211,8 @@ impl Context {
11881211 verify_host_callback : None ,
11891212 connection_initialized : false ,
11901213 app_context : None ,
1214+ #[ cfg( feature = "unstable-renegotiate" ) ]
1215+ renegotiate_state : RenegotiateState :: default ( ) ,
11911216 }
11921217 }
11931218}
0 commit comments