mirror of
https://github.com/matter-labs/teepot.git
synced 2025-07-23 16:04:46 +02:00
refactor: prefer inline format args
This commit is contained in:
parent
71a04ad4e2
commit
2dea589c0e
18 changed files with 42 additions and 62 deletions
|
@ -53,10 +53,7 @@ pub fn setup_logging(
|
|||
.try_from_env()
|
||||
.unwrap_or(match *log_level {
|
||||
LevelFilter::OFF => EnvFilter::new("off"),
|
||||
_ => EnvFilter::new(format!(
|
||||
"warn,{crate_name}={log_level},teepot={log_level}",
|
||||
log_level = log_level
|
||||
)),
|
||||
_ => EnvFilter::new(format!("warn,{crate_name}={log_level},teepot={log_level}")),
|
||||
});
|
||||
|
||||
let fmt_layer = tracing_subscriber::fmt::layer()
|
||||
|
|
|
@ -37,8 +37,7 @@ pub enum ReportData {
|
|||
fn report_data_to_bytes(data: &[u8], version: u8) -> [u8; REPORT_DATA_LENGTH] {
|
||||
debug_assert!(
|
||||
data.len() < REPORT_DATA_LENGTH, // Ensure there is space for the version byte
|
||||
"Data length exceeds maximum of {} bytes",
|
||||
REPORT_DATA_LENGTH
|
||||
"Data length exceeds maximum of {REPORT_DATA_LENGTH} bytes",
|
||||
);
|
||||
let mut bytes = [0u8; REPORT_DATA_LENGTH];
|
||||
bytes[..data.len()].copy_from_slice(data);
|
||||
|
|
|
@ -104,7 +104,7 @@ pub trait QuoteContextErr {
|
|||
impl<T, E: std::fmt::Display> QuoteContextErr for Result<T, E> {
|
||||
type Ok = T;
|
||||
fn str_context<I: std::fmt::Display>(self, msg: I) -> Result<T, QuoteError> {
|
||||
self.map_err(|e| QuoteError::Unexpected(format!("{}: {}", msg, e)))
|
||||
self.map_err(|e| QuoteError::Unexpected(format!("{msg}: {e}")))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -583,7 +583,7 @@ impl Display for TEEType {
|
|||
TEEType::TDX => "tdx",
|
||||
TEEType::SNP => "snp",
|
||||
};
|
||||
write!(f, "{}", str)
|
||||
write!(f, "{str}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,14 +134,14 @@ fn convert_to_collateral(
|
|||
/// Split the last zero byte
|
||||
fn get_str_from_bytes(bytes: &[u8], context: &str) -> Result<String, QuoteError> {
|
||||
let c_str = CStr::from_bytes_until_nul(bytes)
|
||||
.str_context(format!("Failed to extract CString: {}", context))?;
|
||||
.str_context(format!("Failed to extract CString: {context}"))?;
|
||||
Ok(c_str.to_string_lossy().into_owned())
|
||||
}
|
||||
|
||||
/// Parse JSON field from collateral data
|
||||
fn parse_json_field(data: &[u8], context: &str) -> Result<serde_json::Value, QuoteError> {
|
||||
serde_json::from_str(&get_str_from_bytes(data, context)?)
|
||||
.str_context(format!("Failed to parse JSON: {}", context))
|
||||
.str_context(format!("Failed to parse JSON: {context}"))
|
||||
}
|
||||
|
||||
/// Convert Collateral to QuoteCollateralV3
|
||||
|
|
|
@ -46,7 +46,7 @@ impl FromStr for TcbLevel {
|
|||
"outofdate" => Ok(TcbLevel::OutOfDate),
|
||||
"outofdateconfigneeded" => Ok(TcbLevel::OutOfDateConfigNeeded),
|
||||
"invalid" => Ok(TcbLevel::Invalid),
|
||||
_ => Err(format!("Invalid TCB level: {}", s)),
|
||||
_ => Err(format!("Invalid TCB level: {s}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ pub fn parse_tcb_levels(
|
|||
let mut set = EnumSet::new();
|
||||
for level_str in s.split(',') {
|
||||
let level_str = level_str.trim();
|
||||
let level = TcbLevel::from_str(level_str)
|
||||
.map_err(|_| format!("Invalid TCB level: {}", level_str))?;
|
||||
let level =
|
||||
TcbLevel::from_str(level_str).map_err(|_| format!("Invalid TCB level: {level_str}"))?;
|
||||
set.insert(level);
|
||||
}
|
||||
Ok(set)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue