mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-04 01:55:41 +00:00
utils: move DeterministicDigest to utils
This commit is contained in:
@@ -41,7 +41,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::common::config::ConfigLoader;
|
use crate::common::config::ConfigLoader;
|
||||||
use crate::dns::config::DnsGlobalCtxExt;
|
use crate::dns::config::DnsGlobalCtxExt;
|
||||||
use crate::proto::dns::DeterministicDigest;
|
use crate::utils::DeterministicDigest;
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
config::NetworkIdentity,
|
config::NetworkIdentity,
|
||||||
|
|||||||
@@ -1,24 +1,7 @@
|
|||||||
use serde::Serialize;
|
|
||||||
use sha2::{Digest, Sha256};
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/dns.rs"));
|
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 GetExportConfigResponse {}
|
|
||||||
|
|
||||||
impl DeterministicDigest for ZoneConfigPb {}
|
|
||||||
|
|
||||||
impl DeterministicDigest for DnsSnapshot {}
|
|
||||||
|
|
||||||
impl Display for ZoneConfigPb {
|
impl Display for ZoneConfigPb {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
writeln!(f, "; EasyTier Magic DNS zone file")?;
|
writeln!(f, "; EasyTier Magic DNS zone file")?;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use crate::common::log;
|
use crate::common::log;
|
||||||
use indoc::formatdoc;
|
use indoc::formatdoc;
|
||||||
use std::{fs::OpenOptions, str::FromStr};
|
use std::{fs::OpenOptions, str::FromStr};
|
||||||
|
use serde::Serialize;
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
pub type PeerRoutePair = crate::proto::api::instance::PeerRoutePair;
|
pub type PeerRoutePair = crate::proto::api::instance::PeerRoutePair;
|
||||||
|
|
||||||
@@ -148,3 +150,14 @@ pub trait BoxExt: Sized {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> BoxExt for T {}
|
impl<T> BoxExt for T {}
|
||||||
|
|
||||||
|
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<S: Serialize> DeterministicDigest for S {}
|
||||||
|
|||||||
Reference in New Issue
Block a user