Something went wrong. Try again.
A public mirror for the whole atmosphere hubble.microcosm.blue
Something went wrong. Try again.
938 B · 28 lines
Rust
at main
1234567891011121314151617181920212223242526272829//! Checking a block against the CID that claims to address it.
use crate::cid::{Cid, Multihash};
#[derive(Debug, thiserror::Error)]pub enum BlockError { #[error("block hashes to {computed}, not the {claimed} it is filed under")] CidMismatch { claimed: Cid, computed: Cid }, #[error("block is addressed by {found:?}, but atproto only uses sha2-256")] UnsupportedMultihash { found: Multihash },}
/// Check that `block`'s contents really are for its cid.pub fn verify_block(claimed: &Cid, block: &[u8]) -> Result<(), BlockError> { let found = claimed.multihash_type(); if !matches!(found, Multihash::Sha2256) { return Err(BlockError::UnsupportedMultihash { found }); } let computed = Cid::digest_sha2(claimed.codec(), block); if computed == *claimed { Ok(()) } else { Err(BlockError::CidMismatch { claimed: *claimed, computed, }) }}