pub struct ExactDigestVerifier { /* private fields */ }Expand description
A verifier that proves ownership by exact prior SHA-256 content.
Returns Absent when nothing exists, Owned when the live file hashes to
the expected digest for that member, Foreign when content differs, and
Unknown when the destination cannot be read unambiguously.
Implementations§
Source§impl ExactDigestVerifier
impl ExactDigestVerifier
Sourcepub fn new(expected: Vec<(MemberId, [u8; 32])>) -> Self
pub fn new(expected: Vec<(MemberId, [u8; 32])>) -> Self
Creates a verifier from (member, expected_live_digest) pairs.
Examples found in repository?
examples/ownership.rs (line 44)
24fn main() -> Result<(), Box<dyn std::error::Error>> {
25 let base = temp_root("eggup-ownership");
26 let inputs = base.join("inputs");
27 let root = base.join("install");
28 fs::create_dir_all(&inputs)?;
29 fs::create_dir_all(root.join("bin"))?;
30 fs::write(inputs.join("app"), b"new-app")?;
31 fs::write(root.join("bin/app"), b"old-app")?;
32 let new_digest = eggup_core::hash_file(&inputs.join("app"))?;
33 let old_digest = eggup_core::hash_file(&root.join("bin/app"))?;
34 let member = ArtifactMember::new(MemberId::new("main")?, inputs.join("app"), "bin/app")?
35 .with_integrity(IntegrityRequirement::Sha256(new_digest));
36 let plan = InstallPlan::new(
37 ProductId::new("demo")?,
38 ReleaseId::new("4.0.0")?,
39 &root,
40 ArtifactSet::single(member)?,
41 )?;
42 // Prove the live file is the expected old deployment; deny creation of
43 // absent destinations (replacement-only policy).
44 let verifier = ExactDigestVerifier::new(vec![(MemberId::new("main")?, old_digest)]);
45 let receipt = plan
46 .prepare()?
47 .verify_integrity()?
48 .validate(&AllValidators::new())?
49 .commit(CommitOwnership::new(&verifier, AbsentPolicy::DenyCreate))?;
50 assert_eq!(receipt.disposition(), TransactionDisposition::Committed);
51 assert_eq!(fs::read(root.join("bin/app"))?, b"new-app");
52 let _ = fs::remove_dir_all(&base);
53 println!("ownership-verified commit: {:?}", receipt.disposition());
54 Ok(())
55}Trait Implementations§
Source§impl Clone for ExactDigestVerifier
impl Clone for ExactDigestVerifier
Source§impl Debug for ExactDigestVerifier
impl Debug for ExactDigestVerifier
Auto Trait Implementations§
impl Freeze for ExactDigestVerifier
impl RefUnwindSafe for ExactDigestVerifier
impl Send for ExactDigestVerifier
impl Sync for ExactDigestVerifier
impl Unpin for ExactDigestVerifier
impl UnsafeUnpin for ExactDigestVerifier
impl UnwindSafe for ExactDigestVerifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more