What changed, and why it matters
This commit only changes how numbers appear in log messages for the Trezor hardware protocol (THP) Rust code. It switches decimal formatting (e.g., '123') to hexadecimal formatting (e.g., '0x7b') for control bytes, channel IDs, and error codes. There are no functional code changes, no security fixes, and no behavior changes.
No security action required. This is a non-functional logging refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure logging-format refactor across six files in rust/trezor-thp. Format strings are updated to use hex specifiers (0x{:x}, {:04x}) for control bytes, channel IDs, and transport error codes. No logic, parsing, validation, cryptography, or state-machine code is modified. The commit title and message explicitly describe it as a ‘log format’ refactor.
Changed components
rust/trezor-thp/src/channel/device.rsrust/trezor-thp/src/channel/host.rsrust/trezor-thp/src/channel/mod.rsrust/trezor-thp/src/control_byte.rsrust/trezor-thp/src/fragment.rsrust/trezor-thp/src/header.rsInspect captured patch +31 / −24
diff --git a/rust/trezor-thp/src/channel/device.rs b/rust/trezor-thp/src/channel/device.rs
index 809a2216..0ba02e2e 100644
--- a/rust/trezor-thp/src/channel/device.rs
+++ b/rust/trezor-thp/src/channel/device.rs
@@ -144,7 +144,7 @@ where
// No Header::TransportError for broadcast.
_ => {
log::debug!(
- "Broadcast channel: ignoring packet with control byte {}.",
+ "Broadcast channel: ignoring packet with control byte 0x{:x}.",
packet[0]
);
Err(Error::malformed_data())
@@ -198,7 +198,7 @@ where
return self.handle_v1(packet_buffer);
}
if !channel_id_valid(channel_id) {
- log::warn!("Invalid channel id {}.", channel_id);
+ log::warn!("Invalid channel id {:04x}.", channel_id);
return PacketInResult::ignore(Error::malformed_data());
}
if channel_id != BROADCAST_CHANNEL_ID {
@@ -339,7 +339,7 @@ impl<C: CredentialVerifier, B: Backend> ChannelOpen<C, B> {
self.state = HandshakeState::SendingCompletionResponse { pairing_state };
}
_ => {
- log::error!("[{}] Unexpected handshake state.", self.channel_id());
+ log::error!("[{:04x}] Unexpected handshake state.", self.channel_id());
return Err(Error::unexpected_input());
}
}
@@ -422,7 +422,7 @@ impl<C: CredentialVerifier, B: Backend> ChannelOpen<C, B> {
if !self.handshake_done() {
return Err(Error::not_ready());
}
- log::debug!("Handshake complete.");
+ log::debug!("[{:04x}] Handshake complete.", self.channel_id());
Ok(match self.state {
HandshakeState::SendingCompletionResponse { pairing_state } => {
self.channel.pairing_state = pairing_state;
@@ -477,7 +477,7 @@ where
.packet_in(packet_buffer, &mut self.internal_buffer);
if let PacketInResult::EnlargeBuffer { buffer_size, .. } = res {
log::error!(
- "[{}] Payload length {} exceeds handshake limit.",
+ "[{:04x}] Payload length {} exceeds handshake limit.",
self.channel_id(),
buffer_size
);
diff --git a/rust/trezor-thp/src/channel/host.rs b/rust/trezor-thp/src/channel/host.rs
index 7a91310f..0f5ed45c 100644
--- a/rust/trezor-thp/src/channel/host.rs
+++ b/rust/trezor-thp/src/channel/host.rs
@@ -178,7 +178,7 @@ where
// No Header::TransportError for broadcast channel.
_ => {
log::debug!(
- "Broadcast channel: ignoring packet with control byte {}.",
+ "Broadcast channel: ignoring packet with control byte 0x{:x}.",
packet[0]
);
Err(Error::malformed_data())
@@ -215,7 +215,7 @@ where
try_to_unlock: *try_to_unlock,
channel_id,
};
- log::debug!("Got channel id {}.", channel_id);
+ log::debug!("Got channel id {:04x}.", channel_id);
Ok(PacketInResult::channel_allocation())
}
}
@@ -239,7 +239,7 @@ where
return PacketInResult::ignore(Error::malformed_data());
};
if !channel_id_valid(channel_id) {
- log::warn!("Invalid channel id {}.", channel_id);
+ log::warn!("Invalid channel id {:04x}.", channel_id);
return PacketInResult::ignore(Error::malformed_data());
}
if channel_id != BROADCAST_CHANNEL_ID && !cb.is_codec_v1() {
@@ -460,7 +460,7 @@ impl<C: CredentialStore, B: Backend> ChannelOpen<C, B> {
if self.channel.noise.is_none() {
return Err(Error::unexpected_input());
}
- log::debug!("Handshake complete.");
+ log::debug!("[{:04x}] Handshake complete.", self.channel_id());
Ok(match self.state {
HandshakeState::Finished { pairing_state } => {
self.channel.pairing_state = pairing_state;
@@ -490,7 +490,7 @@ where
.packet_in(packet_buffer, &mut self.internal_buffer);
if let PacketInResult::EnlargeBuffer { buffer_size, .. } = res {
log::error!(
- "[{}] Payload length {} exceeds handshake limit.",
+ "[{:04x}] Payload length {} exceeds handshake limit.",
self.channel_id(),
buffer_size
);
diff --git a/rust/trezor-thp/src/channel/mod.rs b/rust/trezor-thp/src/channel/mod.rs
index 96e03493..8319c941 100644
--- a/rust/trezor-thp/src/channel/mod.rs
+++ b/rust/trezor-thp/src/channel/mod.rs
@@ -276,7 +276,7 @@ impl<R: Role, B: Backend> Channel<R, B> {
return Ok(());
}
}
- log::warn!("[{}] Unexpected ACK.", self.channel_id);
+ log::warn!("[{:04x}] Unexpected ACK.", self.channel_id);
Err(Error::malformed_data())
}
@@ -285,14 +285,18 @@ impl<R: Role, B: Backend> Channel<R, B> {
if let Ok((header, payload)) = Reassembler::<R>::single(packet_buffer, &mut err_buf) {
if header.is_error() {
if let Ok(te) = TransportError::try_from(payload) {
- log::error!("[{}] Peer sent an error: {}.", self.channel_id, te as u8);
+ log::error!(
+ "[{:04x}] Peer sent an error: {}.",
+ self.channel_id,
+ te as u8
+ );
if !te.is_recoverable() {
self.state = ChannelState::Failed { error: Some(te) };
}
return Ok(te);
} else {
log::error!(
- "[{}] Peer sent unknown error {}.",
+ "[{:04x}] Peer sent unknown error 0x{:x}.",
self.channel_id,
payload.first().unwrap_or(&0)
);
@@ -301,7 +305,10 @@ impl<R: Role, B: Backend> Channel<R, B> {
self.state = ChannelState::Failed { error: None };
return Err(Error::malformed_data());
}
- log::warn!("[{}] Peer sent an error with invalid CRC.", self.channel_id);
+ log::warn!(
+ "[{:04x}] Peer sent an error with invalid CRC.",
+ self.channel_id
+ );
Err(Error::malformed_data())
}
@@ -690,7 +697,7 @@ impl<R: Role, B: Backend> ChannelIO for Channel<R, B> {
if !header.is_encrypted() {
log::error!(
- "[{}] Invalid message type, expecting EncryptedTransport.",
+ "[{:04x}] Invalid message type, expecting EncryptedTransport.",
self.channel_id
);
return Err(Error::malformed_data());
@@ -713,7 +720,7 @@ impl<R: Role, B: Backend> ChannelIO for Channel<R, B> {
}
};
if receive_buffer.len() < APP_HEADER_LEN {
- log::error!("[{}] Incoming message too short.", self.channel_id);
+ log::error!("[{:04x}] Incoming message too short.", self.channel_id);
// fails on the next two lines
}
let (session_id, rest) = receive_buffer
@@ -732,10 +739,10 @@ impl<R: Role, B: Backend> ChannelIO for Channel<R, B> {
fn message_retransmit(&mut self) -> Result<()> {
let ChannelState::Sending { fragmenter, retry } = &mut self.state else {
- log::warn!("[{}] Nothing to retransmit.", self.channel_id);
+ log::warn!("[{:04x}] Nothing to retransmit.", self.channel_id);
return Ok(());
};
- log::debug!("[{}] Retransmitting message.", self.channel_id);
+ log::debug!("[{:04x}] Retransmitting message.", self.channel_id);
fragmenter.reset();
*retry = retry.saturating_add(1);
Ok(())
diff --git a/rust/trezor-thp/src/control_byte.rs b/rust/trezor-thp/src/control_byte.rs
index e4edf0d1..a8bfd94b 100644
--- a/rust/trezor-thp/src/control_byte.rs
+++ b/rust/trezor-thp/src/control_byte.rs
@@ -149,7 +149,7 @@ impl TryFrom<u8> for ControlByte {
|| cb.is_handshake()
|| cb.is_codec_v1();
if !valid {
- log::warn!("Invalid control byte {}.", byte);
+ log::warn!("Invalid control byte 0x{:x}.", byte);
return Err(Error::malformed_data());
}
Ok(cb)
diff --git a/rust/trezor-thp/src/fragment.rs b/rust/trezor-thp/src/fragment.rs
index 5bbff26c..a5e7aa33 100644
--- a/rust/trezor-thp/src/fragment.rs
+++ b/rust/trezor-thp/src/fragment.rs
@@ -143,7 +143,7 @@ impl<R: Role> Reassembler<R> {
let (header, after_header) = Header::<R>::parse(input)?;
if !header.is_continuation() {
log::error!(
- "[{}] Unexpected initiation packet.",
+ "[{:04x}] Unexpected initiation packet.",
self.header.channel_id()
);
return Err(Error::unexpected_input());
@@ -151,7 +151,7 @@ impl<R: Role> Reassembler<R> {
if header.channel_id() != self.header.channel_id() {
log::error!(
- "[{}] Unexpected channel id {}.",
+ "[{:04x}] Unexpected channel id {:04x}.",
self.header.channel_id(),
header.channel_id()
);
diff --git a/rust/trezor-thp/src/header.rs b/rust/trezor-thp/src/header.rs
index a066bfb8..16539275 100644
--- a/rust/trezor-thp/src/header.rs
+++ b/rust/trezor-thp/src/header.rs
@@ -101,7 +101,7 @@ impl<R: Role> Header<R> {
}
}
if !channel_id_valid(channel_id) {
- log::error!("Invalid channel id {}.", channel_id);
+ log::error!("Invalid channel id {:04x}.", channel_id);
return Err(Error::malformed_data());
}
if cb.is_continuation() {
@@ -132,7 +132,7 @@ impl<R: Role> Header<R> {
return Ok((header, rest));
}
log::error!(
- "Unknown header: ({}, {}, {}).",
+ "Unknown header: (0x{:x}, {:04x}, {}).",
u8::from(cb),
channel_id,
payload_len
@@ -303,7 +303,7 @@ impl<R: Role> Header<R> {
fn validate_channel(channel_id: u16) -> Result<u16> {
if !channel_id_valid(channel_id) {
- log::error!("Cannot construct: invalid channel id {}.", channel_id);
+ log::error!("Cannot construct: invalid channel id {:04x}.", channel_id);
return Err(Error::unexpected_input());
}
Ok(channel_id)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.