Skip to content

Commit 43bfe42

Browse files
committed
Clippy, improve logging
1 parent 0e2a286 commit 43bfe42

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

crates/attestation/src/azure/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ mod tests {
462462

463463
let hcl_report = hcl::HclReport::new(hcl_bytes.to_vec()).unwrap();
464464
let hcl_var_data = hcl_report.var_data();
465-
let var_data_values: serde_json::Value = serde_json::from_slice(&hcl_var_data).unwrap();
465+
let var_data_values: serde_json::Value = serde_json::from_slice(hcl_var_data).unwrap();
466466

467467
// Check that it contains 64 byte user data
468468
assert_eq!(hex::decode(var_data_values["user-data"].as_str().unwrap()).unwrap().len(), 64);

crates/attestation/src/dcap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ fn verify_dcap_attestation_with_collateral_and_timestamp(
192192
}
193193

194194
#[cfg(any(test, feature = "mock"))]
195+
#[allow(clippy::unused_async)]
195196
pub async fn verify_dcap_attestation(
196197
input: Vec<u8>,
197198
expected_input_data: [u8; 64],

crates/pccs/src/lib.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,16 @@ impl Pccs {
137137
let collateral = fetch_collateral(&self.pccs_url, fmspc.clone(), ca).await?;
138138
let next_update = extract_next_update(&collateral, now)?;
139139

140-
let mut cache = self.cache.write().map_err(|_| PccsError::CachePoisoned)?;
141-
if let Some(existing) = cache.get(&cache_key) &&
142-
now < existing.next_update
143140
{
144-
return Ok((existing.collateral.clone(), false));
145-
}
141+
let mut cache = self.cache.write().map_err(|_| PccsError::CachePoisoned)?;
142+
if let Some(existing) = cache.get(&cache_key) &&
143+
now < existing.next_update
144+
{
145+
return Ok((existing.collateral.clone(), false));
146+
}
146147

147-
upsert_cache_entry(&mut cache, cache_key.clone(), collateral.clone(), next_update);
148-
drop(cache);
148+
upsert_cache_entry(&mut cache, cache_key.clone(), collateral.clone(), next_update);
149+
}
149150
self.ensure_refresh_task(&cache_key).await;
150151
Ok((collateral, true))
151152
}
@@ -160,7 +161,7 @@ impl Pccs {
160161
let cache_key = PccsInput::new(fmspc.clone(), ca);
161162
let cache = self.cache.read().map_err(|_| PccsError::CachePoisoned)?;
162163
if let Some(entry) = cache.get(&cache_key) {
163-
if now < entry.next_update {
164+
if now >= entry.next_update {
164165
tracing::warn!(
165166
fmspc,
166167
next_update = entry.next_update,
@@ -740,16 +741,17 @@ mod tests {
740741
assert_eq!(summary.successes, 2);
741742
assert_eq!(summary.failures, 0);
742743

743-
let cache_guard = pccs.cache.read().unwrap();
744-
let total_entries = cache_guard.len();
744+
let (total_entries, fmspc, ca) = {
745+
let cache_guard = pccs.cache.read().unwrap();
746+
let total_entries = cache_guard.len();
747+
let (fmspc, ca) = cache_guard
748+
.keys()
749+
.next()
750+
.map(|k| (k.fmspc.clone(), k.ca.clone()))
751+
.expect("expected startup pre-provision to populate PCCS cache");
752+
(total_entries, fmspc, ca)
753+
};
745754
assert_eq!(total_entries, 2, "expected startup pre-provision to cache processor+platform");
746-
747-
let (fmspc, ca) = cache_guard
748-
.keys()
749-
.next()
750-
.map(|k| (k.fmspc.clone(), k.ca.clone()))
751-
.expect("expected startup pre-provision to populate PCCS cache");
752-
drop(cache_guard);
753755
let ca_static = ca_as_static(&ca).expect("unexpected CA value in warmed cache entry");
754756
let now = unix_now().unwrap();
755757
let (_, is_fresh) = pccs.get_collateral(fmspc, ca_static, now as u64).await.unwrap();

0 commit comments

Comments
 (0)