Skip to content

Commit

Permalink
fix: consider deserializing a blocking operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Feb 21, 2024
1 parent 81d16df commit f08285a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions csaf/src/verification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};
use async_trait::async_trait;
use csaf::Csaf;
use serde::de::Error as _;
use std::collections::{HashMap, HashSet};
use std::fmt::{Debug, Display};
use std::future::Future;
Expand Down Expand Up @@ -178,9 +179,19 @@ where
}

async fn verify(&self, advisory: A) -> Result<VerifiedAdvisory<A, I>, VerificationError<E, A>> {
let csaf: Csaf = match serde_json::from_slice(&advisory.as_retrieved().data) {
Ok(csaf) => csaf,
Err(error) => return Err(VerificationError::Parsing { error, advisory }),
let data = advisory.as_retrieved().data.clone();

let csaf = match tokio::task::spawn_blocking(move || serde_json::from_slice::<Csaf>(&data))
.await
{
Ok(Ok(csaf)) => csaf,
Ok(Err(error)) => return Err(VerificationError::Parsing { error, advisory }),
Err(_) => {
return Err(VerificationError::Parsing {
error: serde_json::error::Error::custom("failed to wait for deserialization"),
advisory,
})
}
};

let mut failures = HashMap::new();
Expand Down

0 comments on commit f08285a

Please sign in to comment.