mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 17:15:43 +00:00
proto(utils): add TransientDigest trait (#2071)
This commit is contained in:
@@ -12,6 +12,7 @@ pub mod web;
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests;
|
||||
pub mod utils;
|
||||
|
||||
const DESCRIPTOR_POOL_BYTES: &[u8] =
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin"));
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
use prost::Message;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// Generates a stable digest strictly within the lifecycle of the current process.
|
||||
///
|
||||
/// ⚠️ WARNING:
|
||||
/// - This digest is ONLY guaranteed to be deterministic within a **single process and the exact same binary build**.
|
||||
pub trait TransientDigest: Message {
|
||||
fn digest(&self) -> [u8; 32]
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let buf = self.encode_to_vec();
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(buf);
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Message> TransientDigest for S {}
|
||||
Reference in New Issue
Block a user