rust: bssl-tls: Session attachment should only be possible in builder

Signed-off-by: Xiangfei Ding <xfding@google.com>
Change-Id: Idaf6edb154cded0fab3764d0aef1578c6a6a6964
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/101410
Reviewed-by: David Benjamin <davidben@google.com>
Reviewed-by: Rudolf Polzer <rpolzer@google.com>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/rust/bssl-tls/src/connection.rs b/rust/bssl-tls/src/connection.rs
index df7ae7a..13b14cd 100644
--- a/rust/bssl-tls/src/connection.rs
+++ b/rust/bssl-tls/src/connection.rs
@@ -116,7 +116,10 @@
 
     /// Disable session creation.
     pub fn disable_session(&mut self) -> &mut Self {
-        self.as_in_handshake().disable_session();
+        unsafe {
+            // Safety: the validity of the handle `ptr` is witnessed by `self`.
+            bssl_sys::SSL_set_mode(self.ptr(), ConnectionMode::MODE_NO_SESSION_CREATION.bits());
+        }
         self
     }
 
@@ -133,7 +136,10 @@
 
     /// Set the session for resumption.
     pub fn with_session(&mut self, session: &TlsSession) -> &mut Self {
-        self.as_in_handshake().set_session(session);
+        unsafe {
+            // Safety: self.ptr and session.0 are valid.
+            bssl_sys::SSL_set_session(self.ptr(), session.ptr());
+        }
         self
     }
 
diff --git a/rust/bssl-tls/src/connection/credentials.rs b/rust/bssl-tls/src/connection/credentials.rs
index eb07f03..18b0305 100644
--- a/rust/bssl-tls/src/connection/credentials.rs
+++ b/rust/bssl-tls/src/connection/credentials.rs
@@ -476,30 +476,6 @@
     }
 }
 
-/// # Sessions
-impl<R, M> TlsConnectionInHandshake<'_, R, M> {
-    /// Disable session creation.
-    pub fn disable_session(&mut self) -> &mut Self {
-        unsafe {
-            // Safety: the validity of the handle `ptr` is witnessed by `self`.
-            bssl_sys::SSL_set_mode(
-                self.ptr(),
-                super::ConnectionMode::MODE_NO_SESSION_CREATION.bits(),
-            );
-        }
-        self
-    }
-
-    /// Set the session for resumption.
-    pub fn set_session(&mut self, session: &crate::sessions::TlsSession) -> &mut Self {
-        unsafe {
-            // Safety: self.ptr and session.0 are valid.
-            bssl_sys::SSL_set_session(self.ptr(), session.ptr());
-        }
-        self
-    }
-}
-
 /// # Raw Public Key
 impl<R, M> TlsConnectionInHandshake<'_, R, M> {
     /// Set acceptable peer certificate types