Update Rust to 1.67.0 (#20821)

Fix lint errors with cargo clippy --fix
This commit is contained in:
Zac Bergquist 2023-01-27 17:34:14 -07:00 committed by GitHub
parent c4eabb48c4
commit 19eae4a738
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 67 deletions

View file

@ -24,7 +24,7 @@ GOLANG_VERSION ?= go1.19.5
NODE_VERSION ?= 16.18.1
# run lint-rust check locally before merging code after you bump this
RUST_VERSION ?= 1.66.1
RUST_VERSION ?= 1.67.0
LIBBPF_VERSION ?= 0.7.0-teleport
LIBPCSCLITE_VERSION ?= 1.9.9-teleport

View file

@ -379,7 +379,7 @@ impl ClipboardPDUHeader {
let typ = payload.read_u16::<LittleEndian>()?;
Ok(Self {
msg_type: ClipboardPDUType::from_u16(typ)
.ok_or_else(|| invalid_data_error(&format!("invalid message type {:#04x}", typ)))?,
.ok_or_else(|| invalid_data_error(&format!("invalid message type {typ:#04x}")))?,
msg_flags: ClipboardHeaderFlags::from_bits(payload.read_u16::<LittleEndian>()?)
.ok_or_else(|| invalid_data_error("invalid flags in clipboard header"))?,
data_len: payload.read_u32::<LittleEndian>()?,
@ -453,8 +453,7 @@ impl GeneralClipboardCapabilitySet {
let set_type = payload.read_u16::<LittleEndian>()?;
if set_type != ClipboardCapabilitySetType::General as u16 {
return Err(invalid_data_error(&format!(
"expected general capability set (1), got {}",
set_type
"expected general capability set (1), got {set_type}"
)));
}
@ -616,7 +615,7 @@ impl ShortFormatName {
fn from_str(id: u32, name: &str) -> RdpResult<Self> {
if name.len() > 32 {
return Err(invalid_data_error(
format!("{} is too long for short format name", name).as_str(),
format!("{name} is too long for short format name").as_str(),
));
}
let mut dest = [0u8; 32];
@ -1154,8 +1153,7 @@ mod tests {
assert_eq!(
expected,
*c.clipboard.get(&(format as u32)).unwrap(),
"testing {}",
input,
"testing {input}",
);
}
}

View file

@ -81,7 +81,7 @@ pub fn test() {}
#[no_mangle]
pub extern "C" fn init() {
env_logger::try_init().unwrap_or_else(|e| println!("failed to initialize Rust logger: {}", e));
env_logger::try_init().unwrap_or_else(|e| println!("failed to initialize Rust logger: {e}"));
}
#[derive(Clone)]
@ -657,7 +657,7 @@ impl<S: Read + Write> RdpClient<S> {
}
_ => Err(RdpError::RdpError(RdpProtocolError::new(
RdpErrorKind::UnexpectedType,
&format!("Invalid channel name {:?}", channel_name),
&format!("Invalid channel name {channel_name:?}"),
))),
}
}
@ -784,7 +784,7 @@ impl TryFrom<BitmapEvent> for CGOPNG {
let mut encoded = Vec::with_capacity(8192);
encode_png(&mut encoded, w, h, e.decompress()?).map_err(|err| {
Self::Error::TryError(format!("failed to encode bitmap to png: {:?}", err))
Self::Error::TryError(format!("failed to encode bitmap to png: {err:?}"))
})?;
res.data_ptr = encoded.as_mut_ptr();
@ -1270,7 +1270,7 @@ fn read_rdp_output_inner(client: &Client) -> ReadRdpOutputReturns {
}
Err(e) => {
return ReadRdpOutputReturns {
user_message: format!("RDP read failed: {:?}", e),
user_message: format!("RDP read failed: {e:?}"),
disconnect_code: CGODisconnectCode::DisconnectCodeUnknown,
err_code: CGOErrCode::ErrCodeFailure,
};

View file

@ -54,7 +54,7 @@ pub struct Card<const S: usize> {
impl<const S: usize> Card<S> {
pub fn new(uuid: Uuid, cert_der: &[u8], key_der: &[u8], pin: String) -> RdpResult<Self> {
let piv_auth_key = RsaPrivateKey::from_pkcs1_der(key_der).map_err(|e| {
invalid_data_error(&format!("failed to parse private key from DER: {:?}", e))
invalid_data_error(&format!("failed to parse private key from DER: {e:?}"))
})?;
Ok(Self {
@ -154,7 +154,7 @@ impl<const S: usize> Card<S> {
return Ok(Response::new(Status::NotFound));
}
let request_tlv = Tlv::from_bytes(cmd.data())
.map_err(|e| invalid_data_error(&format!("TLV invalid: {:?}", e)))?;
.map_err(|e| invalid_data_error(&format!("TLV invalid: {e:?}")))?;
if *request_tlv.tag() != tlv_tag(0x5C)? {
return Ok(Response::new(Status::NotFound));
}
@ -246,11 +246,10 @@ impl<const S: usize> Card<S> {
}
let request_tlv = Tlv::from_bytes(cmd.data())
.map_err(|e| invalid_data_error(&format!("TLV invalid: {:?}", e)))?;
.map_err(|e| invalid_data_error(&format!("TLV invalid: {e:?}")))?;
if *request_tlv.tag() != tlv_tag(TLV_TAG_DYNAMIC_AUTHENTICATION_TEMPLATE)? {
return Err(invalid_data_error(&format!(
"general authenticate command TLV invalid: {:?}",
request_tlv
"general authenticate command TLV invalid: {request_tlv:?}"
)));
}
@ -258,8 +257,7 @@ impl<const S: usize> Card<S> {
let request_tlvs = match request_tlv.value() {
Value::Primitive(_) => {
return Err(invalid_data_error(&format!(
"general authenticate command TLV invalid: {:?}",
request_tlv
"general authenticate command TLV invalid: {request_tlv:?}"
)));
}
Value::Constructed(tlvs) => tlvs,
@ -273,16 +271,14 @@ impl<const S: usize> Card<S> {
Value::Primitive(chal) => Some(chal),
Value::Constructed(_) => {
return Err(invalid_data_error(&format!(
"general authenticate command TLV invalid: {:?}",
request_tlv
"general authenticate command TLV invalid: {request_tlv:?}"
)));
}
};
}
let challenge = challenge.ok_or_else(|| {
invalid_data_error(&format!(
"general authenticate command TLV invalid: {:?}, missing challenge data",
request_tlv
"general authenticate command TLV invalid: {request_tlv:?}, missing challenge data"
))
})?;
@ -406,12 +402,11 @@ const TLV_TAG_RESPONSE: u8 = 0x82;
fn tlv(tag: u8, value: Value) -> RdpResult<Tlv> {
Tlv::new(tlv_tag(tag)?, value)
.map_err(|e| invalid_data_error(&format!("TLV with tag {:#X} invalid: {:?}", tag, e)))
.map_err(|e| invalid_data_error(&format!("TLV with tag {tag:#X} invalid: {e:?}")))
}
fn tlv_tag(val: u8) -> RdpResult<Tag> {
Tag::try_from(val)
.map_err(|e| invalid_data_error(&format!("TLV tag {:#X} invalid: {:?}", val, e)))
Tag::try_from(val).map_err(|e| invalid_data_error(&format!("TLV tag {val:#X} invalid: {e:?}")))
}
fn hex_data<const S: usize>(cmd: &Command<S>) -> String {
@ -422,7 +417,7 @@ fn to_hex(bytes: &[u8]) -> String {
let mut s = String::new();
for b in bytes {
// https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
let _ = write!(s, "{:02X}", b);
let _ = write!(s, "{b:02X}");
}
s
}

View file

@ -524,8 +524,7 @@ impl Client {
}
_ => {
return Err(invalid_data_error(&format!(
"received unknown CreateDisposition value for RDP {:?}",
rdp_req
"received unknown CreateDisposition value for RDP {rdp_req:?}"
)));
}
}
@ -1675,10 +1674,10 @@ impl SharedHeader {
let packet_id = payload.read_u16::<LittleEndian>()?;
Ok(Self {
component: Component::from_u16(component).ok_or_else(|| {
invalid_data_error(&format!("invalid component value {:#06x}", component))
invalid_data_error(&format!("invalid component value {component:#06x}"))
})?,
packet_id: PacketId::from_u16(packet_id).ok_or_else(|| {
invalid_data_error(&format!("invalid packet_id value {:#06x}", packet_id))
invalid_data_error(&format!("invalid packet_id value {packet_id:#06x}"))
})?,
})
}
@ -1858,7 +1857,7 @@ impl CapabilityHeader {
let cap_type = payload.read_u16::<LittleEndian>()?;
Ok(Self {
cap_type: CapabilityType::from_u16(cap_type).ok_or_else(|| {
invalid_data_error(&format!("invalid capability type {:#06x}", cap_type))
invalid_data_error(&format!("invalid capability type {cap_type:#06x}"))
})?,
length: payload.read_u16::<LittleEndian>()?,
version: payload.read_u32::<LittleEndian>()?,
@ -2030,7 +2029,7 @@ impl DeviceAnnounceHeader {
if name.len() > 7 {
name = &name[..7];
}
w.extend_from_slice(&format!("{:\x00<8}", name).into_bytes());
w.extend_from_slice(&format!("{name:\x00<8}").into_bytes());
w.write_u32::<LittleEndian>(self.device_data_length)?;
w.extend_from_slice(&self.device_data);
Ok(w)
@ -2054,8 +2053,7 @@ impl ServerDeviceAnnounceResponse {
});
}
Err(RdpError::TryError(format!(
"Read unsupported NTSTATUS: {}",
result_code,
"Read unsupported NTSTATUS: {result_code}",
)))
}
}
@ -2138,8 +2136,7 @@ impl DeviceIoRequest {
let major_function = payload.read_u32::<LittleEndian>()?;
let major_function = MajorFunction::from_u32(major_function).ok_or_else(|| {
invalid_data_error(&format!(
"invalid major function value {:#010x}",
major_function
"invalid major function value {major_function:#010x}"
))
})?;
let minor_function = payload.read_u32::<LittleEndian>()?;
@ -2157,8 +2154,7 @@ impl DeviceIoRequest {
};
let minor_function = MinorFunction::from_u32(minor_function).ok_or_else(|| {
invalid_data_error(&format!(
"invalid minor function value {:#010x}",
minor_function
"invalid minor function value {minor_function:#010x}"
))
})?;
@ -2202,8 +2198,7 @@ impl DeviceControlRequest {
let io_control_code = payload.read_u32::<LittleEndian>()?;
let io_control_code = IoctlCode::from_u32(io_control_code).ok_or_else(|| {
invalid_data_error(&format!(
"invalid I/O control code value {:#010x}",
io_control_code
"invalid I/O control code value {io_control_code:#010x}"
))
})?;
payload.seek(SeekFrom::Current(20))?; // padding
@ -2308,8 +2303,7 @@ impl DeviceCreateRequest {
debug!("In DeviceCreateRequest decode");
let invalid_flags = |flag_name: &str, v: u32| {
invalid_data_error(&format!(
"invalid flags in Device Create Request: {} = {}",
flag_name, v
"invalid flags in Device Create Request: {flag_name} = {v}"
))
};
@ -2461,8 +2455,7 @@ impl ServerDriveQueryInformationRequest {
Err(invalid_data_error(
format!(
"received invalid FileInformationClass in ServerDriveQueryInformationRequest: {}",
n
"received invalid FileInformationClass in ServerDriveQueryInformationRequest: {n}"
)
.as_str(),
))
@ -2534,8 +2527,7 @@ impl FileInformationClass {
))
}
_ => Err(invalid_data_error(&format!(
"decode invalid FileInformationClassLevel: {:?}",
file_information_class_level
"decode invalid FileInformationClassLevel: {file_information_class_level:?}"
))),
}
}
@ -3770,8 +3762,7 @@ impl ServerDriveSetInformationRequest {
| FileInformationClassLevel::FileAllocationInformation => {}
_ => {
return Err(invalid_data_error(&format!(
"read invalid FileInformationClassLevel: {:?}",
file_information_class_level
"read invalid FileInformationClassLevel: {file_information_class_level:?}"
)))
}
};
@ -3835,8 +3826,7 @@ impl ServerDriveQueryDirectoryRequest {
if !VALID_LEVELS.contains(&file_info_class_lvl) {
return Err(invalid_data_error(&format!(
"read invalid FileInformationClassLevel: {:?}, expected one of {:?}",
file_info_class_lvl, VALID_LEVELS,
"read invalid FileInformationClassLevel: {file_info_class_lvl:?}, expected one of {VALID_LEVELS:?}",
)));
}
@ -3904,16 +3894,14 @@ impl ClientDriveQueryDirectoryResponse {
| NTSTATUS::STATUS_UNSUCCESSFUL => {
if buffer.is_some() {
return Err(invalid_data_error(&format!(
"a ClientDriveQueryDirectoryResponse with NTSTATUS = {:?} \
should have a None buffer, got {:?}",
io_status, buffer,
"a ClientDriveQueryDirectoryResponse with NTSTATUS = {io_status:?} \
should have a None buffer, got {buffer:?}",
)));
}
}
_ => {
return Err(invalid_data_error(&format!(
"received unsupported io_status for ClientDriveQueryDirectoryResponse: {:?}",
io_status
"received unsupported io_status for ClientDriveQueryDirectoryResponse: {io_status:?}"
)))
}
}
@ -3931,7 +3919,7 @@ impl ClientDriveQueryDirectoryResponse {
fs_info_class.size()
}
_ => {
return Err(not_implemented_error(&format!("ClientDriveQueryDirectoryResponse not implemented for fs_information_class {:?}", fs_information_class)));
return Err(not_implemented_error(&format!("ClientDriveQueryDirectoryResponse not implemented for fs_information_class {fs_information_class:?}")));
}
},
None => 0,
@ -3992,8 +3980,7 @@ impl ServerDriveQueryVolumeInformationRequest {
if !VALID_LEVELS.contains(&fs_info_class_lvl) {
return Err(invalid_data_error(&format!(
"read invalid FileInformationClassLevel: {:?}, expected one of {:?}",
fs_info_class_lvl, VALID_LEVELS,
"read invalid FileInformationClassLevel: {fs_info_class_lvl:?}, expected one of {VALID_LEVELS:?}",
)));
}
@ -4033,16 +4020,14 @@ impl ClientDriveQueryVolumeInformationResponse {
NTSTATUS::STATUS_UNSUCCESSFUL => {
if buffer.is_some() {
return Err(invalid_data_error(&format!(
"a ClientDriveQueryVolumeInformationResponse with NTSTATUS = {:?} \
should have a None buffer, got {:?}",
io_status, buffer,
"a ClientDriveQueryVolumeInformationResponse with NTSTATUS = {io_status:?} \
should have a None buffer, got {buffer:?}",
)));
}
}
_ => {
return Err(invalid_data_error(&format!(
"received unsupported io_status for ClientDriveQueryVolumeInformationResponse: {:?}",
io_status
"received unsupported io_status for ClientDriveQueryVolumeInformationResponse: {io_status:?}"
)))
}
}

View file

@ -654,7 +654,7 @@ impl EstablishContext_Call {
let scope = payload.read_u32::<LittleEndian>()?;
Ok(Self {
scope: Scope::from_u32(scope).ok_or_else(|| {
invalid_data_error(&format!("invalid smart card scope {:?}", scope))
invalid_data_error(&format!("invalid smart card scope {scope:?}"))
})?,
})
}
@ -767,8 +767,7 @@ fn decode_ptr(payload: &mut Payload, index: &mut u32) -> RdpResult<u32> {
*index += 1;
if ptr != expect_ptr {
Err(invalid_data_error(&format!(
"invalid NDR pointer value {:#010X}, expected {:#010X}",
ptr, expect_ptr
"invalid NDR pointer value {ptr:#010X}, expected {expect_ptr:#010X}"
)))
} else {
Ok(ptr)

View file

@ -46,7 +46,7 @@ pub fn from_unicode(s: Vec<u8>) -> RdpResult<String> {
/// Converts a &str into a null-terminated UTF-8 encoded Vec<u8>
pub fn to_utf8(s: &str) -> Vec<u8> {
format!("{}\x00", s).into_bytes()
format!("{s}\x00").into_bytes()
}
/// Takes a Rust string slice and calculates it's unicode size in bytes.