implement hash for config

This commit is contained in:
Brian Picciano 2023-05-09 16:40:40 +02:00
parent f2a3c78a83
commit a704c7ad34

View File

@ -4,8 +4,9 @@ use std::{fs, io};
use crate::origin::Descr;
use mockall::automock;
use hex::ToHex;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
/// Values which the owner of a domain can configure when they install a domain.
@ -13,6 +14,14 @@ pub struct Config {
pub origin_descr: Descr,
}
impl Config {
pub fn hash(&self) -> Result<String, Box<dyn Error>> {
let mut h = Sha256::new();
serde_json::to_writer(&mut h, self)?;
Ok(h.finalize().encode_hex::<String>())
}
}
#[derive(thiserror::Error, Debug)]
pub enum GetError {
#[error("not found")]