Skip to content

Commit

Permalink
Remove unused trait BorrowedPlainMessage
Browse files Browse the repository at this point in the history
There are no uses of this trait inside the crate, so remove it
and transfer the used parts into the `OutboundMessage` inherent impl.
  • Loading branch information
ctz committed Feb 19, 2024
1 parent 40a56fc commit cf61961
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 67 deletions.
3 changes: 1 addition & 2 deletions rustls/src/common_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::msgs::enums::{AlertLevel, KeyUpdateRequest};
use crate::msgs::fragmenter::MessageFragmenter;
use crate::msgs::handshake::CertificateChain;
use crate::msgs::message::{
BorrowedPlainMessage, Message, MessagePayload, OpaqueMessage, OutboundChunks, OutboundMessage,
PlainMessage,
Message, MessagePayload, OpaqueMessage, OutboundChunks, OutboundMessage, PlainMessage,
};
use crate::quic;
use crate::record_layer;
Expand Down
4 changes: 1 addition & 3 deletions rustls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ pub mod internal {
};
}
pub mod message {
pub use crate::msgs::message::{
BorrowedPlainMessage, Message, MessagePayload, OpaqueMessage, PlainMessage,
};
pub use crate::msgs::message::{Message, MessagePayload, OpaqueMessage, PlainMessage};
}
pub mod persist {
pub use crate::msgs::persist::ServerSessionValue;
Expand Down
2 changes: 1 addition & 1 deletion rustls/src/msgs/deframer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ mod tests {
use std::io;

use crate::crypto::cipher::PlainMessage;
use crate::msgs::message::{BorrowedPlainMessage, Message};
use crate::msgs::message::Message;

use super::*;

Expand Down
4 changes: 1 addition & 3 deletions rustls/src/msgs/fragmenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ mod tests {
use crate::enums::ContentType;
use crate::enums::ProtocolVersion;
use crate::msgs::base::Payload;
use crate::msgs::message::{
BorrowedPlainMessage, OutboundChunks, OutboundMessage, PlainMessage,
};
use crate::msgs::message::{OutboundChunks, OutboundMessage, PlainMessage};

fn msg_eq(
m: &OutboundMessage,
Expand Down
72 changes: 14 additions & 58 deletions rustls/src/msgs/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,14 @@ impl InboundMessage<'_> {
pub(crate) fn is_valid_ccs(&self) -> bool {
self.typ == ContentType::ChangeCipherSpec && self.payload == [0x01]
}
}

impl BorrowedPlainMessage for InboundMessage<'_> {
fn payload_to_vec(&self) -> Vec<u8> {
self.payload.to_vec()
}

fn payload_len(&self) -> usize {
self.payload.len()
}

fn typ(&self) -> ContentType {
self.typ
}

fn version(&self) -> ProtocolVersion {
self.version
#[cfg(test)]
pub(crate) fn into_owned(self) -> PlainMessage {
PlainMessage {
version: self.version,
typ: self.typ,
payload: Payload::Owned(self.payload.to_vec()),
}
}
}

Expand All @@ -482,53 +473,18 @@ pub struct OutboundMessage<'a> {
pub payload: OutboundChunks<'a>,
}

impl BorrowedPlainMessage for OutboundMessage<'_> {
fn payload_to_vec(&self) -> Vec<u8> {
self.payload.to_vec()
}

fn payload_len(&self) -> usize {
self.payload.len()
}

fn typ(&self) -> ContentType {
self.typ
impl OutboundMessage<'_> {
pub(crate) fn encoded_len(&self, record_layer: &RecordLayer) -> usize {
OpaqueMessage::HEADER_SIZE as usize + record_layer.encrypted_len(self.payload.len())
}

fn version(&self) -> ProtocolVersion {
self.version
}
}

/// Abstract both inbound and outbound variants of a plaintext message
pub trait BorrowedPlainMessage: Sized {
fn into_owned(self) -> PlainMessage {
PlainMessage {
version: self.version(),
typ: self.typ(),
payload: Payload::Owned(self.payload_to_vec()),
}
}

fn to_unencrypted_opaque(&self) -> OpaqueMessage {
pub(crate) fn to_unencrypted_opaque(&self) -> OpaqueMessage {
OpaqueMessage {
version: self.version(),
typ: self.typ(),
payload: Payload::Owned(self.payload_to_vec()),
version: self.version,
typ: self.typ,
payload: Payload::Owned(self.payload.to_vec()),
}
}

fn encoded_len(&self, record_layer: &RecordLayer) -> usize {
OpaqueMessage::HEADER_SIZE as usize + record_layer.encrypted_len(self.payload_len())
}

fn payload_to_vec(&self) -> Vec<u8>;

fn payload_len(&self) -> usize;

fn typ(&self) -> ContentType;

fn version(&self) -> ProtocolVersion;
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit cf61961

Please sign in to comment.