Skip to main content

Module mask

Module mask 

Source
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.coma***@example.com.
mask_id_card
Mask a Chinese ID card number (15 or 18 digits/X): 110101199001011234110101********1234.
mask_middle
Generic helper: keep prefix chars at the start and suffix chars 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: 13812345678138****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.