Available on crate feature
mask only.Expand description
Sensitive-data masking helpers.
Each function takes a &str and returns a String. Inputs that don’t
match the expected shape are returned with a best-effort mask rather
than panicking — these functions are intended for log output, where
crashing is worse than over-masking.
Functions§
- mask_
bank_ card - Mask a bank card number, keeping the first 4 and last 4 digits.
- mask_
email - Mask an email address:
alice@example.com→a***@example.com. - mask_
id_ card - Mask a Chinese ID card number (15 or 18 digits/X):
110101199001011234→110101********1234. - mask_
middle - Generic helper: keep
prefixchars at the start andsuffixchars at the end, replacing the middle with stars (one star per masked char). - mask_
name - Mask a Chinese name.
- mask_
phone - Mask a Chinese mainland mobile number:
13812345678→138****5678. - mask_
secret - Generic credential masking — port of
du-node-utils.maskSecret. - mask_
token - Mask an API token / secret. Shows the first 4 and last 4 characters, or fully stars out short inputs.