lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

command_obtained.rs (1318B)


      1 //! Original obtained bytes outlive any fallible storage-evidence conversion.
      2 use radroots_domain::OperationId;
      3 use radroots_signing::issuance::SignedArtifact;
      4 use radroots_storage::command::{ArtifactEvidence, OperationError, SigningAttempt};
      5 use std::sync::OnceLock;
      6 
      7 #[cfg(all(test, not(target_arch = "wasm32")))]
      8 #[path = "command_obtained_tests.rs"]
      9 mod tests;
     10 
     11 pub(super) struct Obtained {
     12     attempt: SigningAttempt,
     13     artifact: SignedArtifact,
     14     evidence: OnceLock<Result<ArtifactEvidence, OperationError>>,
     15 }
     16 impl Obtained {
     17     pub(super) fn new(attempt: SigningAttempt, artifact: SignedArtifact) -> Self {
     18         Self {
     19             attempt,
     20             artifact,
     21             evidence: OnceLock::new(),
     22         }
     23     }
     24     pub(super) fn operation(&self) -> OperationId {
     25         self.attempt.identity().operation_id()
     26     }
     27     pub(super) fn evidence(&self) -> Result<&ArtifactEvidence, OperationError> {
     28         self.evidence
     29             .get_or_init(|| {
     30                 self.artifact.with_json(|raw| {
     31                     ArtifactEvidence::verify(
     32                         &self.attempt,
     33                         raw,
     34                         self.artifact.observed_at_unix_ms(),
     35                     )
     36                 })
     37             })
     38             .as_ref()
     39             .map_err(|error| *error)
     40     }
     41 }