rpc: add digest

This commit is contained in:
Luna Yao
2026-04-06 11:54:01 +02:00
parent ee3b7f2335
commit 83bdcf0d2b
3 changed files with 17 additions and 2 deletions
+14
View File
@@ -1,7 +1,21 @@
use serde::Serialize;
use sha2::{Digest, Sha256};
use std::fmt::Display;
include!(concat!(env!("OUT_DIR"), "/dns.rs"));
pub trait DeterministicDigest: Serialize {
fn digest(&self) -> Vec<u8> {
let json = serde_json::to_vec(self).expect("failed to serialize the object to json");
let mut hasher = Sha256::new();
hasher.update(json);
hasher.finalize().to_vec()
}
}
impl DeterministicDigest for DnsConfigPb {}
impl DeterministicDigest for ZoneConfigPb {}
impl Display for ZoneConfigPb {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "; EasyTier Magic DNS zone file")?;