1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-19 21:08:07 +00:00

chore(rust/trezor-client): run clippy

[no changelog]
This commit is contained in:
Pavol Rusnak 2024-08-26 18:09:06 +02:00 committed by matejcik
parent c8b811bac5
commit 07ac2fd4d8
8 changed files with 32 additions and 32 deletions

View File

@ -237,7 +237,7 @@ impl<'a> EntropyRequest<'a> {
/// Provide exactly 32 bytes or entropy.
pub fn ack_entropy(self, entropy: Vec<u8>) -> Result<TrezorResponse<'a, (), protos::Success>> {
if entropy.len() != 32 {
return Err(Error::InvalidEntropy)
return Err(Error::InvalidEntropy);
}
let mut req = protos::EntropyAck::new();

View File

@ -45,7 +45,7 @@ impl Trezor {
Box::new(|_, m: protos::EthereumMessageSignature| {
let signature = m.signature();
if signature.len() != 65 {
return Err(Error::MalformedSignature)
return Err(Error::MalformedSignature);
}
let r = signature[0..32].try_into().unwrap();
let s = signature[32..64].try_into().unwrap();

View File

@ -22,7 +22,7 @@ use tracing::trace;
/// Fulfill a TxRequest for TXINPUT.
fn ack_input_request(req: &protos::TxRequest, psbt: &psbt::Psbt) -> Result<protos::TxAck> {
if req.details.is_none() || !req.details.has_request_index() {
return Err(Error::MalformedTxRequest(req.clone()))
return Err(Error::MalformedTxRequest(req.clone()));
}
// Choose either the tx we are signing or a dependent tx.
@ -63,7 +63,7 @@ fn ack_input_request(req: &protos::TxRequest, psbt: &psbt::Psbt) -> Result<proto
Error::InvalidPsbt(format!("invalid utxo for PSBT input {}", input_index))
})?
} else {
return Err(Error::InvalidPsbt(format!("no utxo for PSBT input {}", input_index)))
return Err(Error::InvalidPsbt(format!("no utxo for PSBT input {}", input_index)));
};
// If there is exactly 1 HD keypath known, we can provide it. If more it's multisig.
@ -108,7 +108,7 @@ fn ack_output_request(
network: Network,
) -> Result<protos::TxAck> {
if req.details.is_none() || !req.details.has_request_index() {
return Err(Error::MalformedTxRequest(req.clone()))
return Err(Error::MalformedTxRequest(req.clone()));
}
// For outputs, the Trezor only needs bin_outputs to be set for dependent txs and full outputs
@ -127,7 +127,7 @@ fn ack_output_request(
} else if let Some(ref utxo) = inp.witness_utxo {
utxo
} else {
return Err(Error::InvalidPsbt("not all inputs have utxo data".to_owned()))
return Err(Error::InvalidPsbt("not all inputs have utxo data".to_owned()));
};
let mut bin_output = TxOutputBinType::new();
@ -187,7 +187,7 @@ fn ack_output_request(
/// Fulfill a TxRequest for TXMETA.
fn ack_meta_request(req: &protos::TxRequest, psbt: &psbt::Psbt) -> Result<protos::TxAck> {
if req.details.is_none() {
return Err(Error::MalformedTxRequest(req.clone()))
return Err(Error::MalformedTxRequest(req.clone()));
}
// Choose either the tx we are signing or a dependent tx.
@ -312,9 +312,9 @@ impl<'a> SignTxProgress<'a> {
TxRequestType::TXOUTPUT => ack_output_request(&self.req, psbt, network),
TxRequestType::TXMETA => ack_meta_request(&self.req, psbt),
TxRequestType::TXEXTRADATA => unimplemented!(), //TODO(stevenroose) implement
TxRequestType::TXORIGINPUT |
TxRequestType::TXORIGOUTPUT |
TxRequestType::TXPAYMENTREQ => unimplemented!(),
TxRequestType::TXORIGINPUT
| TxRequestType::TXORIGOUTPUT
| TxRequestType::TXPAYMENTREQ => unimplemented!(),
TxRequestType::TXFINISHED => unreachable!(),
}?;
self.ack_msg(ack)

View File

@ -159,7 +159,7 @@ mod tests {
#[serial]
fn test_emulator_find() {
let trezors = find_devices(false);
assert!(trezors.len() > 0);
assert!(!trezors.is_empty());
assert!(trezors.iter().any(|t| t.model == Model::TrezorEmulator));
}
@ -169,12 +169,12 @@ mod tests {
let emulator = init_emulator();
let features = emulator.features().expect("Failed to get features");
assert_eq!(features.vendor(), "trezor.io");
assert_eq!(features.initialized(), true);
assert_eq!(features.firmware_present(), false);
assert_eq!(features.initialized(), true);
assert_eq!(features.pin_protection(), false);
assert_eq!(features.passphrase_protection(), false);
assert!(["T", "Safe 3"].contains(&features.model()));
assert!(features.initialized());
assert!(!features.firmware_present());
assert!(features.initialized());
assert!(!features.pin_protection());
assert!(!features.passphrase_protection());
assert!(["T", "Safe 3", "Safe 5"].contains(&features.model()));
}
#[test]

View File

@ -40,7 +40,7 @@ impl<L: Link> Protocol for ProtocolV2<L> {
let resp = self.link.read_chunk()?;
if resp[0] != 0x03 {
println!("bad magic in v2 session_begin: {:x} instead of 0x03", resp[0]);
return Err(Error::DeviceBadMagic)
return Err(Error::DeviceBadMagic);
}
self.session_id = BigEndian::read_u32(&resp[1..5]);
Ok(())
@ -55,7 +55,7 @@ impl<L: Link> Protocol for ProtocolV2<L> {
let resp = self.link.read_chunk()?;
if resp[0] != 0x04 {
println!("bad magic in v2 session_end: {:x} instead of 0x04", resp[0]);
return Err(Error::DeviceBadMagic)
return Err(Error::DeviceBadMagic);
}
self.session_id = 0;
Ok(())
@ -107,10 +107,10 @@ impl<L: Link> Protocol for ProtocolV2<L> {
let chunk = self.link.read_chunk()?;
if chunk[0] != 0x01 {
println!("bad magic in v2 read: {:x} instead of 0x01", chunk[0]);
return Err(Error::DeviceBadMagic)
return Err(Error::DeviceBadMagic);
}
if BigEndian::read_u32(&chunk[1..5]) != self.session_id {
return Err(Error::DeviceBadSessionId)
return Err(Error::DeviceBadSessionId);
}
let message_type_id = BigEndian::read_u32(&chunk[5..9]);
let message_type = MessageType::from_i32(message_type_id as i32)
@ -123,13 +123,13 @@ impl<L: Link> Protocol for ProtocolV2<L> {
let chunk = self.link.read_chunk()?;
if chunk[0] != 0x02 {
println!("bad magic in v2 session_begin: {:x} instead of 0x02", chunk[0]);
return Err(Error::DeviceBadMagic)
return Err(Error::DeviceBadMagic);
}
if BigEndian::read_u32(&chunk[1..5]) != self.session_id {
return Err(Error::DeviceBadSessionId)
return Err(Error::DeviceBadSessionId);
}
if BigEndian::read_u32(&chunk[5..9]) != seq as u32 {
return Err(Error::DeviceUnexpectedSequenceNumber)
return Err(Error::DeviceUnexpectedSequenceNumber);
}
seq += 1;
@ -185,7 +185,7 @@ impl<L: Link> Protocol for ProtocolV1<L> {
"bad magic in v1 read: {:x}{:x}{:x} instead of 0x3f2323",
chunk[0], chunk[1], chunk[2]
);
return Err(Error::DeviceBadMagic)
return Err(Error::DeviceBadMagic);
}
let message_type_id = BigEndian::read_u16(&chunk[3..5]) as u32;
let message_type = MessageType::from_i32(message_type_id as i32)
@ -197,7 +197,7 @@ impl<L: Link> Protocol for ProtocolV1<L> {
let chunk = self.link.read_chunk()?;
if chunk[0] != 0x3f {
println!("bad magic in v1 read: {:x} instead of 0x3f", chunk[0]);
return Err(Error::DeviceBadMagic)
return Err(Error::DeviceBadMagic);
}
data.extend(&chunk[1..]);

View File

@ -48,7 +48,7 @@ impl Link for UdpLink {
let timeout = Duration::from_millis(WRITE_TIMEOUT_MS);
self.socket.set_write_timeout(Some(timeout))?;
if let Err(e) = self.socket.send(&chunk) {
return Err(e.into())
return Err(e.into());
}
Ok(())
}

View File

@ -53,7 +53,7 @@ impl Link for WebUsbLink {
debug_assert_eq!(CHUNK_SIZE, chunk.len());
let timeout = Duration::from_millis(WRITE_TIMEOUT_MS);
if let Err(e) = self.handle.write_interrupt(self.endpoint, &chunk, timeout) {
return Err(e.into())
return Err(e.into());
}
Ok(())
}
@ -101,7 +101,7 @@ impl WebUsbTransport {
.ok_or(rusb::Error::Other)?
.class_code();
if class_code != constants::LIBUSB_CLASS_VENDOR_SPEC {
continue
continue;
}
devices.push(AvailableDevice {
@ -137,9 +137,9 @@ impl WebUsbTransport {
let dev_desc = dev.device_descriptor()?;
let dev_id = (dev_desc.vendor_id(), dev_desc.product_id());
if derive_model(dev_id).as_ref() != Some(&device.model) {
return Err(Error::DeviceDisconnected)
return Err(Error::DeviceDisconnected);
}
let mut handle = dev.open()?;
let handle = dev.open()?;
handle.claim_interface(interface)?;
Ok(Box::new(WebUsbTransport {

View File

@ -45,7 +45,7 @@ pub fn parse_recoverable_signature(
sig: &[u8],
) -> Result<RecoverableSignature, bitcoin::secp256k1::Error> {
if sig.len() != 65 {
return Err(bitcoin::secp256k1::Error::InvalidSignature)
return Err(bitcoin::secp256k1::Error::InvalidSignature);
}
// Bitcoin Core sets the first byte to `27 + rec + (fCompressed ? 4 : 0)`.