fullhash improvement

This commit is contained in:
Pierre
2026-05-31 21:27:11 +02:00
parent f1107d129c
commit 5415eec81f
5 changed files with 64 additions and 23 deletions
+8
View File
@@ -30,6 +30,14 @@ pub fn to_cid(hash: &[u8], algo: HashAlgorithm) -> String {
cid.to_string()
}
/// Returns the multihash code (the algorithm) of a bare CID string, or None
/// if it doesn't parse. Used to tell which digests a record already carries
/// in its bare-CID key-set (cids/<cid>), since the algorithm is no longer in
/// a field name.
pub fn multicodec_of(cid_str: &str) -> Option<u64> {
Cid::try_from(cid_str).ok().map(|c| c.hash().code())
}
#[cfg(test)]
mod tests {
use super::*;