Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Jun 14, 2024
1 parent ec324a7 commit 4719bd6
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion rtc-dtls/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl ConfigBuilder {
server_name = remote_addr.ip().to_string();
} else {
warn!("conn.remote_addr is empty, please set explicitly server_name in Config! Use default \"localhost\" as server_name now");
server_name = "localhost".to_owned();
"localhost".clone_into(&mut server_name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rtc-dtls/src/flight/flight0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Flight for Flight0 {
}
}
Extension::ServerName(e) => {
state.server_name = e.server_name.clone(); // remote server name
state.server_name.clone_from(&e.server_name); // remote server name
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion rtc-dtls/src/flight/flight1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Flight for Flight1 {
));
}

state.cookie = h.cookie.clone();
state.cookie.clone_from(&h.cookie);
state.handshake_recv_sequence = seq;
Ok(Box::new(Flight3 {}))
} else {
Expand Down
6 changes: 3 additions & 3 deletions rtc-dtls/src/flight/flight3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Flight for Flight3 {
));
}

state.cookie = h.cookie.clone();
state.cookie.clone_from(&h.cookie);
state.handshake_recv_sequence = seq;
return Ok(Box::new(Flight3 {}) as Box<dyn Flight>);
}
Expand Down Expand Up @@ -292,7 +292,7 @@ impl Flight for Flight3 {
))
}
};
state.peer_certificates = h.certificate.clone();
state.peer_certificates.clone_from(&h.certificate);
}

if let Some(message) = msgs.get(&HandshakeType::ServerKeyExchange) {
Expand Down Expand Up @@ -420,7 +420,7 @@ pub(crate) fn handle_server_key_exchange(
}
};

state.identity_hint = h.identity_hint.clone();
state.identity_hint.clone_from(&h.identity_hint);
state.pre_master_secret = prf_psk_pre_master_secret(&psk);
} else {
let local_keypair = match h.named_curve.generate_keypair() {
Expand Down
6 changes: 4 additions & 2 deletions rtc-dtls/src/flight/flight4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Flight for Flight4 {
}
};

state.peer_certificates = h.certificate.clone();
state.peer_certificates.clone_from(&h.certificate);
debug!(
"[handshake] PeerCertificates4 {}",
state.peer_certificates.len()
Expand Down Expand Up @@ -300,7 +300,9 @@ impl Flight for Flight4 {
}
};

state.identity_hint = client_key_exchange.identity_hint.clone();
state
.identity_hint
.clone_from(&client_key_exchange.identity_hint);
pre_master_secret = prf_psk_pre_master_secret(&psk);
} else if let Some(local_keypair) = &state.local_keypair {
pre_master_secret = match prf_pre_master_secret(
Expand Down
8 changes: 6 additions & 2 deletions rtc-dtls/src/flight/flight5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ impl Flight for Flight5 {
};
if cfg.local_psk_callback.is_none() {
if let Some(local_keypair) = &state.local_keypair {
client_key_exchange.public_key = local_keypair.public_key.clone();
client_key_exchange
.public_key
.clone_from(&local_keypair.public_key);
}
} else if let Some(local_psk_identity_hint) = &cfg.local_psk_identity_hint {
client_key_exchange.identity_hint = local_psk_identity_hint.clone();
client_key_exchange
.identity_hint
.clone_from(local_psk_identity_hint);
}

pkts.push(Packet {
Expand Down
7 changes: 4 additions & 3 deletions rtc-dtls/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,17 @@ impl State {
self.is_client = serialized.is_client;

// Set master secret
self.master_secret = serialized.master_secret.clone();
self.master_secret.clone_from(&serialized.master_secret);

// Set cipher suite
self.cipher_suite = Some(cipher_suite_for_id(serialized.cipher_suite_id.into())?);

self.srtp_protection_profile = serialized.srtp_protection_profile.into();

// Set remote certificate
self.peer_certificates = serialized.peer_certificates.clone();
self.identity_hint = serialized.identity_hint.clone();
self.peer_certificates
.clone_from(&serialized.peer_certificates);
self.identity_hint.clone_from(&serialized.identity_hint);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion rtc-ice/src/candidate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub fn unmarshal_candidate(raw: &str) -> Result<Candidate> {
}

// RelatedAddress
rel_addr = split2[1].to_owned();
split2[1].clone_into(&mut rel_addr);

// RelatedPort
rel_port = split2[3].parse()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl MarshalSize for SliceLossIndication {
impl Marshal for SliceLossIndication {
/// Marshal encodes the SliceLossIndication in binary
fn marshal_to(&self, mut buf: &mut [u8]) -> Result<usize> {
if (self.sli_entries.len() + SLI_LENGTH) as u8 > std::u8::MAX {
if (self.sli_entries.len() + SLI_LENGTH) as u8 > u8::MAX {
return Err(Error::TooManyReports);
}
if buf.remaining_mut() < self.marshal_size() {
Expand Down
12 changes: 6 additions & 6 deletions rtc-rtcp/src/transport_feedbacks/transport_layer_cc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ impl MarshalSize for RecvDelta {
// small delta
if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedSmallDelta
&& delta >= 0
&& delta <= std::u8::MAX as i64
&& delta <= u8::MAX as i64
{
return 1;
}

// big delta
if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedLargeDelta
&& delta >= std::i16::MIN as i64
&& delta <= std::u16::MAX as i64
&& delta >= i16::MIN as i64
&& delta <= u16::MAX as i64
{
return 2;
}
Expand All @@ -345,7 +345,7 @@ impl Marshal for RecvDelta {
// small delta
if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedSmallDelta
&& delta >= 0
&& delta <= std::u8::MAX as i64
&& delta <= u8::MAX as i64
&& buf.remaining_mut() >= 1
{
buf.put_u8(delta as u8);
Expand All @@ -354,8 +354,8 @@ impl Marshal for RecvDelta {

// big delta
if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedLargeDelta
&& delta >= std::i16::MIN as i64
&& delta <= std::u16::MAX as i64
&& delta >= i16::MIN as i64
&& delta <= u16::MAX as i64
&& buf.remaining_mut() >= 2
{
buf.put_u16(delta as u16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl MarshalSize for TransportLayerNack {
impl Marshal for TransportLayerNack {
/// Marshal encodes the packet in binary.
fn marshal_to(&self, mut buf: &mut [u8]) -> Result<usize> {
if self.nacks.len() + TLN_LENGTH > std::u8::MAX as usize {
if self.nacks.len() + TLN_LENGTH > u8::MAX as usize {
return Err(Error::TooManyReports);
}
if buf.remaining_mut() < self.marshal_size() {
Expand Down
6 changes: 1 addition & 5 deletions rtc/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ impl APIBuilder {
} else {
Arc::new(SettingEngine::default())
},
media_engine: if let Some(media_engine) = self.media_engine.take() {
media_engine
} else {
MediaEngine::default()
},
media_engine: self.media_engine.take().unwrap_or_default(),
/*TODO:interceptor_registry: if let Some(interceptor_registry) =
self.interceptor_registry.take()
{
Expand Down
1 change: 1 addition & 0 deletions rtc/src/peer_connection/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl RTCConfiguration {
/// get_ice_servers side-steps the strict parsing mode of the ice package
/// (as defined in https://tools.ietf.org/html/rfc7064) by copying and then
/// stripping any erroneous queries from "stun(s):" URLs before parsing.
#[allow(clippy::assigning_clones)]
pub(crate) fn get_ice_servers(&self) -> Vec<RTCIceServer> {
let mut ice_servers = self.ice_servers.clone();

Expand Down
8 changes: 4 additions & 4 deletions rtc/src/peer_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ impl RTCPeerConnection {
parsed: Some(d),
};

self.last_offer = offer.sdp.clone();
self.last_offer.clone_from(&offer.sdp);

Ok(offer)
}
Expand Down Expand Up @@ -924,7 +924,7 @@ impl RTCPeerConnection {
parsed: Some(d),
};

self.last_answer = answer.sdp.clone();
self.last_answer.clone_from(&answer.sdp);

Ok(answer)
}
Expand Down Expand Up @@ -1199,10 +1199,10 @@ impl RTCPeerConnection {
if desc.sdp.is_empty() {
match desc.sdp_type {
RTCSdpType::Answer | RTCSdpType::Pranswer => {
desc.sdp = self.last_answer.clone();
desc.sdp.clone_from(&self.last_answer);
}
RTCSdpType::Offer => {
desc.sdp = self.last_offer.clone();
desc.sdp.clone_from(&self.last_offer);
}
_ => return Err(Error::ErrPeerConnSDPTypeInvalidValueSetLocalDescription),
}
Expand Down
2 changes: 1 addition & 1 deletion rtc/src/peer_connection/sdp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub(crate) fn get_rids(media: &MediaDescription) -> Vec<SimulcastRid> {
log::warn!("Failed to parse RID: {}", err);
}
} else if attr.key.as_str() == SDP_ATTRIBUTE_SIMULCAST {
simulcast_attr = attr.value.clone();
simulcast_attr.clone_from(&attr.value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions rtc/src/transport/ice_transport/ice_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ impl RTCIceServer {
if self.username.is_empty() || self.credential.is_empty() {
return Err(Error::ErrNoTurnCredentials);
}
url.username = self.username.clone();
url.username.clone_from(&self.username);

match self.credential_type {
RTCIceCredentialType::Password => {
// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.3)
url.password = self.credential.clone();
url.password.clone_from(&self.credential);
}
_ => return Err(Error::ErrTurnCredentials),
};
Expand Down

0 comments on commit 4719bd6

Please sign in to comment.