umm this doesn't work

This commit is contained in:
Joseph Birr-Pixton 2023-12-04 17:35:13 +00:00
parent 0cca8222ed
commit 3e224c714e
1 changed files with 6 additions and 12 deletions

View File

@ -85,27 +85,21 @@ impl cipher::MessageEncrypter for Tls13Cipher {
&mut self, &mut self,
m: cipher::BorrowedPlainMessage, m: cipher::BorrowedPlainMessage,
seq: u64, seq: u64,
) -> Result<cipher::OpaqueMessage, rustls::Error> { ) -> Result<cipher::OutgoingOpaqueMessage, rustls::Error> {
let total_len = self.encrypted_payload_len(m.payload.len()); let total_len = self.encrypted_payload_len(m.payload.len());
// construct a TLSInnerPlaintext // construct a TLSInnerPlaintext
let mut payload = Vec::with_capacity(total_len); let mut out = cipher::OutgoingOpaqueMessage::new(ContentType::ApplicationData, ProtocolVersion::TLSv1_2, total_len);
payload.extend_from_slice(m.payload); out.extend_from_slice(m.payload);
payload.push(m.typ.get_u8()); out.extend_from_slice(&[m.typ.get_u8()]);
let nonce = chacha20poly1305::Nonce::from(cipher::Nonce::new(&self.1, seq).0); let nonce = chacha20poly1305::Nonce::from(cipher::Nonce::new(&self.1, seq).0);
let aad = cipher::make_tls13_aad(total_len); let aad = cipher::make_tls13_aad(total_len);
self.0 self.0
.encrypt_in_place(&nonce, &aad, &mut payload) .encrypt_in_place(&nonce, &aad, &mut out)
.map_err(|_| rustls::Error::EncryptError) .map_err(|_| rustls::Error::EncryptError)
.map(|_| { .map(|_| out)
cipher::OpaqueMessage::new(
ContentType::ApplicationData,
ProtocolVersion::TLSv1_2,
payload,
)
})
} }
fn encrypted_payload_len(&self, payload_len: usize) -> usize { fn encrypted_payload_len(&self, payload_len: usize) -> usize {