From a704c7ad345502f0f217a7a48ed54d0b295e8293 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 9 May 2023 16:40:40 +0200 Subject: [PATCH] implement hash for config --- src/domain/config.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/domain/config.rs b/src/domain/config.rs index 365f70a..a02f223 100644 --- a/src/domain/config.rs +++ b/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> { + let mut h = Sha256::new(); + serde_json::to_writer(&mut h, self)?; + Ok(h.finalize().encode_hex::()) + } +} + #[derive(thiserror::Error, Debug)] pub enum GetError { #[error("not found")]