diff options
Diffstat (limited to 'src/initramfs.rs')
| -rw-r--r-- | src/initramfs.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/initramfs.rs b/src/initramfs.rs index a108b85..4ece24c 100644 --- a/src/initramfs.rs +++ b/src/initramfs.rs @@ -249,4 +249,24 @@ impl InitramfsResult { pub fn sha256(&self) -> &str { &self.sha256 } + + /// Ensure the initrd recorded by the platform adapter still exists in the + /// assembled rootfs and has not changed before native packaging begins. + pub fn verify_in_rootfs(&self, rootfs: &Path) -> Result<()> { + let contents = fs::read(rootfs.join(&self.initrd_path)).with_context(|| { + format!( + "read generated initrd {}", + rootfs.join(&self.initrd_path).display() + ) + })?; + let digest = format!("{:x}", Sha256::digest(contents)); + if digest != self.sha256 { + bail!( + "generated initrd digest changed for {}: expected {}, found {digest}", + self.initrd_path.display(), + self.sha256 + ); + } + Ok(()) + } } |