Encode TLS handshake data into the write buffer, resizing if needed.
(state: &mut unbuffered::EncodeTlsData<'_, Data>, write_buf: &mut BytesMut)
| 500 | |
| 501 | /// Encode TLS handshake data into the write buffer, resizing if needed. |
| 502 | fn encode_tls_data<Data>(state: &mut unbuffered::EncodeTlsData<'_, Data>, write_buf: &mut BytesMut) -> io::Result<()> { |
| 503 | // SAFETY: EncodeTlsData::encode copies a single chunk contiguously from index 0. |
| 504 | // On Ok(n), exactly n bytes are written. On InsufficientSize or AlreadyEncoded, |
| 505 | // the size check happens before any write so the slice is untouched. |
| 506 | while let Err(e) = unsafe { SpareCapBuf::new(write_buf).with_mut_slice(|slice| state.encode(slice)) } { |
| 507 | match e { |
| 508 | unbuffered::EncodeError::InsufficientSize(unbuffered::InsufficientSizeError { required_size }) => { |
| 509 | write_buf.reserve(required_size); |
| 510 | } |
| 511 | e => return Err(io::Error::new(io::ErrorKind::InvalidData, e.to_string())), |
| 512 | } |
| 513 | } |
| 514 | Ok(()) |
| 515 | } |
| 516 | |
| 517 | /// Encrypt plaintext into the write buffer, resizing if needed. |
| 518 | fn encrypt_to_buf<Data>( |
no test coverage detected