Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
clippy fix
  • Loading branch information
fplust committed May 27, 2022
1 parent 5a852e5 commit 4135fbb
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 102 deletions.
14 changes: 7 additions & 7 deletions src/codec/rle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn process_plane(input: &mut dyn Read, width: u32, height: u32, output: &mut [u8
replen = code & 0xf;
collen = (code >> 4) & 0xf;
revcode = (replen << 4) | collen;
if (revcode <= 47) && (revcode >= 16) {
if (16..=47).contains(&revcode) {
replen = revcode;
collen = 0;
}
Expand All @@ -57,20 +57,20 @@ fn process_plane(input: &mut dyn Read, width: u32, height: u32, output: &mut [u8
replen = code & 0xf;
collen = (code >> 4) & 0xf;
revcode = (replen << 4) | collen;
if (revcode <= 47) && (revcode >= 16) {
if (16..=47).contains(&revcode) {
replen = revcode;
collen = 0;
}
while collen > 0 {
x = input.read_u8()?;
if x & 1 != 0{
x = x >> 1;
x = x + 1;
x >>= 1;
x += 1;
color = -(x as i32) as i8;
}
else
{
x = x >> 1;
x >>= 1;
color = x as i8;
}
x = (output[(last_line + (indexw * 4)) as usize] as i32 + color as i32) as u8;
Expand Down Expand Up @@ -227,7 +227,7 @@ pub fn rle_16_decompress(input: &[u8], width: usize, mut height: usize, output:

while count > 0 {
if x >= width {
if height <= 0 {
if height == 0 {
return Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidData, "error during decompress")))
}
x = 0;
Expand Down Expand Up @@ -331,7 +331,7 @@ pub fn rle_16_decompress(input: &[u8], width: usize, mut height: usize, output:


pub fn rgb565torgb32(input: &[u16], width: usize, height: usize) -> Vec<u8> {
let mut result_32_bpp = vec![0 as u8; width as usize * height as usize * 4];
let mut result_32_bpp = vec![0_u8; width as usize * height as usize * 4];
for i in 0..height {
for j in 0..width {
let index = (i * width + j) as usize;
Expand Down
14 changes: 7 additions & 7 deletions src/core/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ pub fn ts_general_capability_set(extra_flags: Option<u16>) -> Capability {
"updateCapabilityFlag" => Check::new(U16::LE(0)),
"remoteUnshareFlag" => Check::new(U16::LE(0)),
"generalCompressionLevel" => Check::new(U16::LE(0)),
"refreshRectSupport" => 0 as u8,
"suppressOutputSupport" => 0 as u8
"refreshRectSupport" => 0_u8,
"suppressOutputSupport" => 0_u8
]
}
}
Expand Down Expand Up @@ -219,8 +219,8 @@ pub fn ts_bitmap_capability_set(preferred_bits_per_pixel: Option<u16>, desktop_w
"pad2octets" => U16::LE(0),
"desktopResizeFlag" => U16::LE(0),
"bitmapCompressionFlag" => Check::new(U16::LE(0x0001)),
"highColorFlags" => Check::new(0 as u8),
"drawingFlags" => 0 as u8,
"highColorFlags" => Check::new(0_u8),
"drawingFlags" => 0_u8,
"multipleRectangleSupport" => Check::new(U16::LE(0x0001)),
"pad2octetsB" => U16::LE(0)
]
Expand Down Expand Up @@ -253,15 +253,15 @@ pub fn ts_order_capability_set(order_flags: Option<u16>) -> Capability {
Capability {
cap_type: CapabilitySetType::CapstypeOrder,
message: component![
"terminalDescriptor" => vec![0 as u8; 16],
"terminalDescriptor" => vec![0_u8; 16],
"pad4octetsA" => U32::LE(0),
"desktopSaveXGranularity" => U16::LE(1),
"desktopSaveYGranularity" => U16::LE(20),
"pad2octetsA" => U16::LE(0),
"maximumOrderLevel" => U16::LE(1),
"numberFonts" => U16::LE(0),
"orderFlags" => U16::LE(order_flags.unwrap_or(OrderFlag::NEGOTIATEORDERSUPPORT as u16)),
"orderSupport" => vec![0 as u8; 32],
"orderSupport" => vec![0_u8; 32],
"textFlags" => U16::LE(0),
"orderSupportExFlags" => U16::LE(0),
"pad4octetsB" => U32::LE(0),
Expand Down Expand Up @@ -375,7 +375,7 @@ pub fn ts_input_capability_set(input_flags: Option<u16>, keyboard_layout: Option
"keyboardType" => U32::LE(KeyboardType::Ibm101102Keys as u32),
"keyboardSubType" => U32::LE(0),
"keyboardFunctionKey" => U32::LE(12),
"imeFileName" => vec![0 as u8; 64]
"imeFileName" => vec![0_u8; 64]
]
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,10 @@ impl Connector {
self.use_nla = use_nla;
self
}
}

impl Default for Connector {
fn default() -> Self {
Self::new()
}
}
6 changes: 3 additions & 3 deletions src/core/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl BitmapEvent {
// 32 bpp is straight forward
Ok(
if self.is_compress {
let mut result = vec![0 as u8; self.width as usize * self.height as usize * 4];
let mut result = vec![0_u8; self.width as usize * self.height as usize * 4];
rle_32_decompress(&self.data, self.width as u32, self.height as u32, &mut result)?;
result
} else {
Expand All @@ -78,11 +78,11 @@ impl BitmapEvent {
16 => {
// 16 bpp is more consumer
let result_16bpp = if self.is_compress {
let mut result = vec![0 as u16; self.width as usize * self.height as usize * 2];
let mut result = vec![0_u16; self.width as usize * self.height as usize * 2];
rle_16_decompress(&self.data, self.width as usize, self.height as usize, &mut result)?;
result
} else {
let mut result = vec![0 as u16; self.width as usize * self.height as usize];
let mut result = vec![0_u16; self.width as usize * self.height as usize];
for i in 0..self.height {
for j in 0..self.width {
let src = (((self.height - i - 1) * self.width + j) * 2) as usize;
Expand Down
14 changes: 7 additions & 7 deletions src/core/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ pub fn client_core_data(parameter: Option<ClientData>) -> Component {
"sasSequence" => U16::LE(Sequence::RnsUdSasDel as u16),
"kbdLayout" => U32::LE(client_parameter.layout as u32),
"clientBuild" => U32::LE(3790),
"clientName" => client_name.to_string().to_unicode(),
"clientName" => client_name.to_unicode(),
"keyboardType" => U32::LE(KeyboardType::Ibm101102Keys as u32),
"keyboardSubType" => U32::LE(0),
"keyboardFnKeys" => U32::LE(12),
"imeFileName" => vec![0 as u8; 64],
"imeFileName" => vec![0_u8; 64],
"postBeta2ColorDepth" => U16::LE(ColorDepth::RnsUdColor8BPP as u16),
"clientProductId" => U16::LE(1),
"serialNumber" => U32::LE(0),
Expand All @@ -240,8 +240,8 @@ pub fn client_core_data(parameter: Option<ClientData>) -> Component {
),
"earlyCapabilityFlags" => U16::LE(CapabilityFlag::RnsUdCsSupportErrinfoPDU as u16),
"clientDigProductId" => vec![0; 64],
"connectionType" => 0 as u8,
"pad1octet" => 0 as u8,
"connectionType" => 0_u8,
"pad1octet" => 0_u8,
"serverSelectedProtocol" => U32::LE(client_parameter.server_selected_protocol)
]
}
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn server_security_data() -> Component {
}

/// Actually we have no more classic channel
pub fn channel_def(name: &String, options: u32) -> Component {
pub fn channel_def(name: &str, options: u32) -> Component {
component![
"name"=> name.as_bytes().to_vec(),
"options" => U32::LE(options)
Expand Down Expand Up @@ -352,7 +352,7 @@ pub fn read_conference_create_response(cc_response: &mut dyn Read) -> RdpResult<
break;
}

let mut buffer = vec![0 as u8; (cast!(DataType::U16, header["length"])? - header.length() as u16) as usize];
let mut buffer = vec![0_u8; (cast!(DataType::U16, header["length"])? - header.length() as u16) as usize];
sub.read_exact(&mut buffer)?;

match MessageType::from(cast!(DataType::U16, header["type"])?) {
Expand All @@ -377,7 +377,7 @@ pub fn read_conference_create_response(cc_response: &mut dyn Read) -> RdpResult<

// All section are important
Ok(ServerData{
channel_ids: cast!(DataType::Trame, result[&MessageType::ScNet]["channelIdArray"])?.into_iter().map(|x| cast!(DataType::U16, x).unwrap()).collect(),
channel_ids: cast!(DataType::Trame, result[&MessageType::ScNet]["channelIdArray"])?.iter().map(|x| cast!(DataType::U16, x).unwrap()).collect(),
rdp_version: Version::from(cast!(DataType::U32, result[&MessageType::ScCore]["rdpVersion"])?)
})
}
32 changes: 16 additions & 16 deletions src/core/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ fn ts_demand_active_pdu() -> PDU {
///
/// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/4e9722c3-ad83-43f5-af5a-529f73d88b48
fn ts_confirm_active_pdu(share_id: Option<u32>, source: Option<Vec<u8>>, capabilities_set: Option<Array<Component>>) -> PDU {
let default_capabilities_set = capabilities_set.unwrap_or(Array::new(|| capability_set(None)));
let default_source = source.unwrap_or(vec![]);
let default_capabilities_set = capabilities_set.unwrap_or_else(|| Array::new(|| capability_set(None)));
let default_source = source.unwrap_or_default();
PDU {
pdu_type: PDUType::PdutypeConfirmactivepdu,
message: component![
Expand Down Expand Up @@ -113,16 +113,16 @@ fn ts_deactivate_all_pdu() -> PDU {

/// All Data PDU share the same layout
fn share_data_header(share_id: Option<u32>, pdu_type_2: Option<PDUType2>, message: Option<Vec<u8>>) -> PDU {
let default_message = message.unwrap_or(vec![]);
let default_message = message.unwrap_or_default();
PDU {
pdu_type: PDUType::PdutypeDatapdu,
message: component![
"shareId" => U32::LE(share_id.unwrap_or(0)),
"pad1" => 0 as u8,
"streamId" => 1 as u8,
"pad1" => 0_u8,
"streamId" => 1_u8,
"uncompressedLength" => DynOption::new(U16::LE(default_message.length() as u16 + 18), | size | MessageOption::Size("payload".to_string(), size.inner() as usize - 18)),
"pduType2" => pdu_type_2.unwrap_or(PDUType2::Pdutype2ArcStatusPdu) as u8,
"compressedType" => 0 as u8,
"compressedType" => 0_u8,
"compressedLength" => U16::LE(0),
"payload" => default_message
]
Expand All @@ -133,7 +133,7 @@ fn share_data_header(share_id: Option<u32>, pdu_type_2: Option<PDUType2>, messag
/// This is the main PDU payload format
/// It use the share control header to dispatch between all PDU
fn share_control_header(pdu_type: Option<PDUType>, pdu_source: Option<u16>, message: Option<Vec<u8>>) -> Component {
let default_message = message.unwrap_or(vec![]);
let default_message = message.unwrap_or_default();
component![
"totalLength" => DynOption::new(U16::LE(default_message.length() as u16 + 6), |total| MessageOption::Size("pduMessage".to_string(), total.inner() as usize - 6)),
"pduType" => U16::LE(pdu_type.unwrap_or(PDUType::PdutypeDemandactivepdu) as u16),
Expand Down Expand Up @@ -277,7 +277,7 @@ fn ts_font_map_pdu() -> DataPDU {

/// Send input event as slow path
fn ts_input_pdu_data(events: Option<Array<Component>>) -> DataPDU {
let default_events = events.unwrap_or(Array::new(|| ts_input_event(None, None)));
let default_events = events.unwrap_or_else(|| Array::new(|| ts_input_event(None, None)));
DataPDU {
pdu_type: PDUType2::Pdutype2Input,
message: component![
Expand All @@ -293,7 +293,7 @@ fn ts_input_event(message_type: Option<InputEventType>, data: Option<Vec<u8>>) -
component![
"eventTime" => U32::LE(0),
"messageType" => U16::LE(message_type.unwrap_or(InputEventType::InputEventMouse) as u16),
"slowPathInputData" => data.unwrap_or(vec![])
"slowPathInputData" => data.unwrap_or_default()
]
}

Expand Down Expand Up @@ -371,15 +371,15 @@ pub fn ts_keyboard_event(flags: Option<u16>, key_code: Option<u16>) -> TSInputEv
/// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/a1c4caa8-00ed-45bb-a06e-5177473766d3
fn ts_fp_update() -> Component {
component![
"updateHeader" => DynOption::new(0 as u8, |header| {
if (header >> 4) & 0x2 as u8 == 0 as u8 {
"updateHeader" => DynOption::new(0_u8, |header| {
if (header >> 4) & 0x2_u8 == 0_u8 {
MessageOption::SkipField("compressionFlags".to_string())
}
else {
MessageOption::None
}
}),
"compressionFlags" => 0 as u8,
"compressionFlags" => 0_u8,
"size" => DynOption::new(U16::LE(0), | size | MessageOption::Size("updateData".to_string(), size.inner() as usize)),
"updateData" => Vec::<u8>::new()
]
Expand Down Expand Up @@ -469,7 +469,7 @@ fn ts_fp_update_bitmap() -> FastPathUpdate {
message: component![
"header" => Check::new(U16::LE(FastPathUpdateType::FastpathUpdatetypeBitmap as u16)),
"numberRectangles" => U16::LE(0),
"rectangles" => Array::new(|| ts_bitmap_data())
"rectangles" => Array::new(ts_bitmap_data)
]
}
}
Expand All @@ -489,7 +489,7 @@ fn ts_colorpointerattribute() -> FastPathUpdate {
"lengthXorMask" => DynOption::new(U16::LE(0), |length| MessageOption::Size("xorMaskData".to_string(), length.inner() as usize)),
"xorMaskData" => Vec::<u8>::new(),
"andMaskData" => Vec::<u8>::new(),
"pad" => Some(0 as u8)
"pad" => Some(0_u8)
]
}
}
Expand Down Expand Up @@ -602,7 +602,7 @@ impl Client {
self.share_id = Some(cast!(DataType::U32, pdu.message["shareId"])?);
return Ok(true)
}
return Ok(false)
Ok(false)
}

/// Read server synchronize pdu
Expand Down Expand Up @@ -696,7 +696,7 @@ impl Client {
fn read_fast_path<T>(&mut self, stream: &mut dyn Read, mut callback: T) -> RdpResult<()>
where T: FnMut(RdpEvent) {
// it could be have one or more fast path payload
let mut fp_messages = Array::new(|| ts_fp_update());
let mut fp_messages = Array::new(ts_fp_update);
fp_messages.read(stream)?;

for fp_message in fp_messages.inner().iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum StateTransition {
/// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/73170ca2-5f82-4a2d-9d1b-b439f3d8dadc
fn preamble() -> Component {
component![
"bMsgtype" => 0 as u8,
"bMsgtype" => 0_u8,
"flag" => Check::new(Preambule::PreambleVersion30 as u8),
"wMsgSize" => DynOption::new(U16::LE(0), |size| MessageOption::Size("message".to_string(), size.inner() as usize - 4)),
"message" => Vec::<u8>::new()
Expand Down
20 changes: 10 additions & 10 deletions src/core/mcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ fn domain_parameters(max_channel_ids: u32, maw_user_ids: u32, max_token_ids: u32
/// http://www.itu.int/rec/T-REC-T.125-199802-I/en page 25
fn connect_initial(user_data: Option<OctetString>) -> ImplicitTag<Sequence> {
ImplicitTag::new(Tag::application(101), sequence![
"callingDomainSelector" => vec![1 as u8] as OctetString,
"calledDomainSelector" => vec![1 as u8] as OctetString,
"callingDomainSelector" => vec![1_u8] as OctetString,
"calledDomainSelector" => vec![1_u8] as OctetString,
"upwardFlag" => true,
"targetParameters" => domain_parameters(34, 2, 0, 1, 0, 1, 0xffff, 2),
"minimumParameters" => domain_parameters(1, 1, 1, 1, 0, 1, 0x420, 2),
"maximumParameters" => domain_parameters(0xffff, 0xfc17, 0xffff, 1, 0, 1, 0xffff, 2),
"userData" => user_data.unwrap_or(Vec::new())
"userData" => user_data.unwrap_or_default()
])
}

Expand All @@ -62,7 +62,7 @@ sequence![
"result" => 0 as Enumerate,
"calledConnectId" => 0 as Integer,
"domainParameters" => domain_parameters(22, 3, 0, 1, 0, 1,0xfff8, 2),
"userData" => user_data.unwrap_or(Vec::new())
"userData" => user_data.unwrap_or_default()
])
}

Expand All @@ -75,7 +75,7 @@ fn mcs_pdu_header(pdu: Option<DomainMCSPDU>, options: Option<u8>) -> u8 {
/// Client -- attach_user_request -> Server
/// Client <- attach_user_confirm -- Server
fn read_attach_user_confirm(buffer: &mut dyn Read) -> RdpResult<u16> {
let mut confirm = trame![0 as u8, Vec::<u8>::new()];
let mut confirm = trame![0_u8, Vec::<u8>::new()];
confirm.read(buffer)?;
if cast!(DataType::U8, confirm[0])? >> 2 != mcs_pdu_header(Some(DomainMCSPDU::AttachUserConfirm), None) >> 2 {
return Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidData, "MCS: unexpected header on recv_attach_user_confirm")));
Expand All @@ -85,7 +85,7 @@ fn read_attach_user_confirm(buffer: &mut dyn Read) -> RdpResult<u16> {
if per::read_enumerates(&mut request)? != 0 {
return Err(Error::RdpError(RdpError::new(RdpErrorKind::RejectedByServer, "MCS: recv_attach_user_confirm user rejected by server")));
}
Ok(per::read_integer_16(1001, &mut request)?)
per::read_integer_16(1001, &mut request)
}

/// Create a session for the current user
Expand Down Expand Up @@ -133,7 +133,7 @@ fn channel_join_request(user_id: Option<u16>, channel_id: Option<u16>) -> RdpRes
/// Client -- channel_join_request -> Server
/// Client <- channel_join_confirm -- Server
fn read_channel_join_confirm(user_id: u16, channel_id: u16, buffer: &mut dyn Read) -> RdpResult<bool> {
let mut confirm = trame![0 as u8, Vec::<u8>::new()];
let mut confirm = trame![0_u8, Vec::<u8>::new()];
confirm.read(buffer)?;
if cast!(DataType::U8, confirm[0])? >> 2 != mcs_pdu_header(Some(DomainMCSPDU::ChannelJoinConfirm), None) >> 2 {
return Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidData, "MCS: unexpected header on read_channel_join_confirm")));
Expand Down Expand Up @@ -257,13 +257,13 @@ impl<S: Read + Write> Client<S> {
/// mcs.connect(800, 600, KeyboardLayout::French).unwrap();
/// mcs.write("global".to_string(), trame![U16::LE(0)])
/// ```
pub fn write<T: 'static>(&mut self, channel_name: &String, message: T) -> RdpResult<()>
pub fn write<T: 'static>(&mut self, channel_name: &str, message: T) -> RdpResult<()>
where T: Message {
self.x224.write(trame![
mcs_pdu_header(Some(DomainMCSPDU::SendDataRequest), None),
U16::BE(self.user_id.unwrap() - 1001),
U16::BE(self.channel_ids[channel_name]),
0x70 as u8,
0x70_u8,
per::write_length(message.length() as u16)?,
message
])
Expand Down Expand Up @@ -301,7 +301,7 @@ impl<S: Read + Write> Client<S> {
per::read_integer_16(1001, &mut payload)?;

let channel_id = per::read_integer_16(0, &mut payload)?;
let channel = self.channel_ids.iter().find(|x| *x.1 == channel_id).ok_or(Error::RdpError(RdpError::new(RdpErrorKind::Unknown, "MCS: unknown channel")))?;
let channel = self.channel_ids.iter().find(|x| *x.1 == channel_id).ok_or_else(|| Error::RdpError(RdpError::new(RdpErrorKind::Unknown, "MCS: unknown channel")))?;

per::read_enumerates(&mut payload)?;
per::read_length(&mut payload)?;
Expand Down
Loading

0 comments on commit 4135fbb

Please sign in to comment.