Skip to main content

HashMasker

Struct HashMasker 

Source
pub struct HashMasker { /* private fields */ }
Expand description

哈希脱敏器:将输入计算为确定性哈希值,保留前 N 位用于数据关联。

适用于需要脱敏但仍需关联同一实体的场景(如用户 ID 脱敏后仍可聚合统计)。 同一输入始终产生同一输出,可在不同系统间做关联分析而不泄露原始值。

Implementations§

Source§

impl HashMasker

Source

pub fn new() -> Self

创建默认哈希脱敏器(SipHash,保留 12 位前缀)

Source

pub fn with_algorithm(self, algo: HashAlgorithm) -> Self

设置哈希算法(链式)

Source

pub fn with_keep_prefix(self, n: usize) -> Self

设置保留前缀长度(链式)

Source

pub fn with_suffix(self, suffix: &str) -> Self

设置后缀(链式)

Source

pub fn algorithm(&self) -> HashAlgorithm

哈希算法

Source

pub fn keep_prefix(&self) -> usize

保留前缀长度

Source

pub fn suffix(&self) -> &str

后缀

Source

pub fn mask(&self, value: &str) -> String

脱敏单个值

Source

pub fn mask_fields( &self, fields: &[String], data: &HashMap<String, String>, ) -> HashMap<String, String>

脱敏 HashMap 中的指定字段

Source

pub fn mask_json(&self, fields: &[String], json: &str) -> String

脱敏 JSON 字符串中的指定字段

Source

pub fn mask_batch(&self, values: &[String]) -> Vec<String>

批量脱敏:对同一值列表逐个脱敏,保持顺序

Trait Implementations§

Source§

impl Clone for HashMasker

Source§

fn clone(&self) -> HashMasker

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HashMasker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HashMasker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.