mirror of
https://github.com/matter-labs/teepot.git
synced 2025-07-21 23:23:57 +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
|
@ -61,13 +61,11 @@ pub fn extend_sha384(base: &str, extend: &str) -> Result<String> {
|
|||
let mut hasher = sha2::Sha384::new();
|
||||
|
||||
hasher.update(pad::<48>(&hex::decode(base).context(format!(
|
||||
"Failed to decode base digest '{}' - expected hex string",
|
||||
base
|
||||
"Failed to decode base digest '{base}' - expected hex string",
|
||||
))?)?);
|
||||
|
||||
hasher.update(pad::<48>(&hex::decode(extend).context(format!(
|
||||
"Failed to decode extend digest '{}' - expected hex string",
|
||||
extend
|
||||
"Failed to decode extend digest '{extend}' - expected hex string",
|
||||
))?)?);
|
||||
|
||||
Ok(hex::encode(hasher.finalize()))
|
||||
|
|
|
@ -26,7 +26,7 @@ async fn main() -> Result<()> {
|
|||
.context("failed to get quote and collateral")?;
|
||||
|
||||
let base64_string = general_purpose::STANDARD.encode(report.quote.as_ref());
|
||||
print!("{}", base64_string);
|
||||
print!("{base64_string}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ fn print_quote_verification_summary(quote_verification_result: &QuoteVerificatio
|
|||
for advisory in advisories {
|
||||
println!("\tInfo: Advisory ID: {advisory}");
|
||||
}
|
||||
println!("Quote verification result: {}", tcblevel);
|
||||
println!("Quote verification result: {tcblevel}");
|
||||
|
||||
println!("{:#}", "e.report);
|
||||
}
|
||||
|
|
|
@ -26,12 +26,10 @@ impl MainNodeClient {
|
|||
/// Create a new client for the main node
|
||||
pub fn new(rpc_url: Url, chain_id: u64) -> error::Result<Self> {
|
||||
let chain_id = L2ChainId::try_from(chain_id)
|
||||
.map_err(|e| error::Error::Internal(format!("Invalid chain ID: {}", e)))?;
|
||||
.map_err(|e| error::Error::Internal(format!("Invalid chain ID: {e}")))?;
|
||||
|
||||
let node_client = NodeClient::http(rpc_url.into())
|
||||
.map_err(|e| {
|
||||
error::Error::Internal(format!("Failed to create JSON-RPC client: {}", e))
|
||||
})?
|
||||
.map_err(|e| error::Error::Internal(format!("Failed to create JSON-RPC client: {e}")))?
|
||||
.for_network(chain_id.into())
|
||||
.build();
|
||||
|
||||
|
@ -46,13 +44,13 @@ impl JsonRpcClient for MainNodeClient {
|
|||
.get_l1_batch_details(batch_number)
|
||||
.rpc_context("get_l1_batch_details")
|
||||
.await
|
||||
.map_err(|e| error::Error::JsonRpc(format!("Failed to get batch details: {}", e)))?
|
||||
.map_err(|e| error::Error::JsonRpc(format!("Failed to get batch details: {e}")))?
|
||||
.ok_or_else(|| {
|
||||
error::Error::JsonRpc(format!("No details found for batch #{}", batch_number))
|
||||
error::Error::JsonRpc(format!("No details found for batch #{batch_number}"))
|
||||
})?;
|
||||
|
||||
batch_details.base.root_hash.ok_or_else(|| {
|
||||
error::Error::JsonRpc(format!("No root hash found for batch #{}", batch_number))
|
||||
error::Error::JsonRpc(format!("No root hash found for batch #{batch_number}"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,15 +190,12 @@ impl VerifierConfig {
|
|||
pub fn new(args: VerifierConfigArgs) -> error::Result<Self> {
|
||||
let policy = if let Some(path) = &args.attestation_policy_file {
|
||||
let policy_content = fs::read_to_string(path).map_err(|e| {
|
||||
error::Error::internal(format!("Failed to read attestation policy file: {}", e))
|
||||
error::Error::internal(format!("Failed to read attestation policy file: {e}"))
|
||||
})?;
|
||||
|
||||
let policy_config: AttestationPolicyConfig = serde_yaml::from_str(&policy_content)
|
||||
.map_err(|e| {
|
||||
error::Error::internal(format!(
|
||||
"Failed to parse attestation policy file: {}",
|
||||
e
|
||||
))
|
||||
error::Error::internal(format!("Failed to parse attestation policy file: {e}"))
|
||||
})?;
|
||||
|
||||
tracing::info!("Loaded attestation policy from file: {:?}", path);
|
||||
|
|
|
@ -31,13 +31,13 @@ impl fmt::Display for VerifierMode {
|
|||
end_batch,
|
||||
} => {
|
||||
if start_batch == end_batch {
|
||||
write!(f, "one-shot mode (batch {})", start_batch)
|
||||
write!(f, "one-shot mode (batch {start_batch})")
|
||||
} else {
|
||||
write!(f, "one-shot mode (batches {}-{})", start_batch, end_batch)
|
||||
write!(f, "one-shot mode (batches {start_batch}-{end_batch})")
|
||||
}
|
||||
}
|
||||
VerifierMode::Continuous { start_batch } => {
|
||||
write!(f, "continuous mode (starting from batch {})", start_batch)
|
||||
write!(f, "continuous mode (starting from batch {start_batch})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,7 @@ impl fmt::Display for VerificationResult {
|
|||
} => {
|
||||
write!(
|
||||
f,
|
||||
"Partial Success ({} verified, {} failed)",
|
||||
verified_count, unverified_count
|
||||
"Partial Success ({verified_count} verified, {unverified_count} failed)"
|
||||
)
|
||||
}
|
||||
VerificationResult::Failure => write!(f, "Failure"),
|
||||
|
|
|
@ -74,7 +74,7 @@ async fn main() -> Result<()> {
|
|||
},
|
||||
Err(e) => {
|
||||
tracing::error!("Task panicked: {}", e);
|
||||
Err(Error::internal(format!("Task panicked: {}", e)))
|
||||
Err(Error::internal(format!("Task panicked: {e}")))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -21,7 +21,7 @@ impl ProofResponseParser {
|
|||
}
|
||||
}
|
||||
|
||||
return Err(error::Error::JsonRpc(format!("JSONRPC error: {:?}", error)));
|
||||
return Err(error::Error::JsonRpc(format!("JSONRPC error: {error:?}")));
|
||||
}
|
||||
|
||||
// Extract proofs from the result
|
||||
|
|
|
@ -17,7 +17,7 @@ impl AttestationVerifier {
|
|||
// Get current time for verification
|
||||
let unix_time: i64 = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map_err(|e| error::Error::internal(format!("Failed to get system time: {}", e)))?
|
||||
.map_err(|e| error::Error::internal(format!("Failed to get system time: {e}")))?
|
||||
.as_secs() as _;
|
||||
|
||||
// Verify the quote with the collateral
|
||||
|
|
|
@ -107,8 +107,7 @@ impl PolicyEnforcer {
|
|||
) -> Result<()> {
|
||||
if !allowed_levels.contains(actual_level) {
|
||||
let error_msg = format!(
|
||||
"Quote verification failed: TCB level mismatch (expected one of: {:?}, actual: {})",
|
||||
allowed_levels, actual_level
|
||||
"Quote verification failed: TCB level mismatch (expected one of: {allowed_levels:?}, actual: {actual_level})",
|
||||
);
|
||||
return Err(Error::policy_violation(error_msg));
|
||||
}
|
||||
|
@ -152,8 +151,7 @@ impl PolicyEnforcer {
|
|||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let error_msg = format!(
|
||||
"Quote verification failed: {} mismatch (expected one of: [ {} ], actual: {:x})",
|
||||
field_name, valid_values, actual_value
|
||||
"Quote verification failed: {field_name} mismatch (expected one of: [ {valid_values} ], actual: {actual_value:x})"
|
||||
);
|
||||
return Err(Error::policy_violation(error_msg));
|
||||
}
|
||||
|
|
|
@ -30,9 +30,8 @@ impl SignatureVerifier {
|
|||
let report_data_bytes = quote_verification_result.quote.get_report_data();
|
||||
tracing::trace!(?report_data_bytes);
|
||||
|
||||
let report_data = ReportData::try_from(report_data_bytes).map_err(|e| {
|
||||
error::Error::internal(format!("Could not convert to ReportData: {}", e))
|
||||
})?;
|
||||
let report_data = ReportData::try_from(report_data_bytes)
|
||||
.map_err(|e| error::Error::internal(format!("Could not convert to ReportData: {e}")))?;
|
||||
|
||||
Self::verify(&report_data, &root_hash, signature)
|
||||
}
|
||||
|
@ -100,7 +99,7 @@ impl SignatureVerifier {
|
|||
})?;
|
||||
|
||||
recover_signer(&signature_bytes, &root_hash_msg).map_err(|e| {
|
||||
error::Error::signature_verification(format!("Failed to recover signer: {}", e))
|
||||
error::Error::signature_verification(format!("Failed to recover signer: {e}"))
|
||||
})?
|
||||
}
|
||||
// Any other length is invalid
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue