mirror of
https://github.com/matter-labs/teepot.git
synced 2025-07-21 07:03:56 +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
|
@ -25,20 +25,18 @@ impl ApiClient {
|
|||
|
||||
if technology == "tdx" && self.api_version == ApiVersion::V3 {
|
||||
return Err(IntelApiError::UnsupportedApiVersion(format!(
|
||||
"TDX endpoint /{}/{}/{} requires API v4",
|
||||
service, endpoint, technology
|
||||
"TDX endpoint /{service}/{endpoint}/{technology} requires API v4",
|
||||
)));
|
||||
}
|
||||
if technology == "sgx" && service == "registration" {
|
||||
// Registration paths are fixed at v1 regardless of client's api_version
|
||||
return Ok(format!("/sgx/registration/v1/{}", endpoint).replace("//", "/"));
|
||||
return Ok(format!("/sgx/registration/v1/{endpoint}").replace("//", "/"));
|
||||
}
|
||||
|
||||
Ok(format!(
|
||||
"/{}/certification/{}/{}/{}",
|
||||
technology, api_segment, service, endpoint
|
||||
Ok(
|
||||
format!("/{technology}/certification/{api_segment}/{service}/{endpoint}")
|
||||
.replace("//", "/"),
|
||||
)
|
||||
.replace("//", "/"))
|
||||
}
|
||||
|
||||
/// Helper to add an optional header if the string is non-empty.
|
||||
|
@ -187,13 +185,11 @@ impl ApiClient {
|
|||
/// Ensures the client is configured for API v4, otherwise returns an error.
|
||||
pub(super) fn ensure_v4_api(&self, function_name: &str) -> Result<(), IntelApiError> {
|
||||
if self.api_version != ApiVersion::V4 {
|
||||
Err(IntelApiError::UnsupportedApiVersion(format!(
|
||||
"{} requires API v4",
|
||||
function_name
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
return Err(IntelApiError::UnsupportedApiVersion(format!(
|
||||
"{function_name} requires API v4",
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks if a V4-only parameter is provided with a V3 API version.
|
||||
|
@ -204,8 +200,7 @@ impl ApiClient {
|
|||
) -> Result<(), IntelApiError> {
|
||||
if self.api_version == ApiVersion::V3 && param_value.is_some() {
|
||||
Err(IntelApiError::UnsupportedApiVersion(format!(
|
||||
"'{}' parameter requires API v4",
|
||||
param_name
|
||||
"'{param_name}' parameter requires API v4",
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
|
|
|
@ -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