implement hash for config

main
Brian Picciano 1 year ago
parent f2a3c78a83
commit a704c7ad34
  1. 11
      src/domain/config.rs

@ -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")]

Loading…
Cancel
Save