soma_provider_core/registry/
fingerprint.rs1use std::fmt;
2
3use sha2::{Digest, Sha256};
4
5use crate::ProviderCatalog;
6
7#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct RegistryFingerprint(String);
9
10impl RegistryFingerprint {
11 pub(super) fn from_catalogs(catalogs: &[ProviderCatalog]) -> Self {
12 let canonical = serde_json::to_vec(catalogs).expect("provider catalogs serialize");
13 let digest = Sha256::digest(canonical);
14 let hex = digest
15 .iter()
16 .map(|byte| format!("{byte:02x}"))
17 .collect::<String>();
18 Self(format!("sha256:{hex}"))
19 }
20
21 pub fn as_str(&self) -> &str {
22 &self.0
23 }
24}
25
26impl fmt::Display for RegistryFingerprint {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 f.write_str(&self.0)
29 }
30}