|
dolibarr 25.0.0-alpha
|
Class to manage privacy data masking and unmasking. More...
Public Member Functions | |
| mask ($text) | |
| Mask sensitive GDPR data in the query. | |
| unmask ($jsonString) | |
| Restore real data from a masked string. | |
| unmaskAiResponse ($text) | |
| Unmasks a string from an AI response, handling cases where the AI might have stripped the [[ and ]] delimiters from a token. | |
| maskNames ($text, $names) | |
| Mask the names of the objects carried in this payload. | |
Private Member Functions | |
| maskCreditCardCallback (array $matches) | |
| Callback function for preg_replace_callback to mask credit cards. | |
| passesLuhnCheck ($number) | |
| Validates a number string using the Luhn algorithm. | |
| startSession () | |
| Start the masking session for this guard instance, once. | |
| createToken ($value, $type) | |
| Create a unique token and store the original value in the map. | |
Class to manage privacy data masking and unmasking.
Definition at line 29 of file privacy_guard.class.php.
|
private |
Create a unique token and store the original value in the map.
| string | $value | The original sensitive value. |
| string | $type | The type of data (e.g., 'EMAIL'). |
Definition at line 619 of file privacy_guard.class.php.
Referenced by mask(), maskCreditCardCallback(), and maskNames().
| PrivacyGuard::mask | ( | $text | ) |
Mask sensitive GDPR data in the query.
This method iterates through a series of patterns to find and replace sensitive data with tokens.
| string | $text | The input string containing potentially sensitive data. |
| array<int,string> | $m |
| array<int,string> | $m |
| array<int,string> | $m |
| array<int,string> | $m |
| array<int,string> | $m |
| array<int,string> | $m |
| array<int,string> | $m |
| array<int,string> | $m |
| array<int,string> | $m |
Definition at line 59 of file privacy_guard.class.php.
References createToken(), and startSession().
|
private |
Callback function for preg_replace_callback to mask credit cards.
It first validates the number using the Luhn algorithm.
| array<int,string> | $matches The regex matches array. |
Definition at line 511 of file privacy_guard.class.php.
References createToken(), and passesLuhnCheck().
| PrivacyGuard::maskNames | ( | $text, | |
| $names ) |
Mask the names of the objects carried in this payload.
Thirdparty and product names are arbitrary strings: no pattern can recognize them, so they are masked from a dictionary built out of the values actually present in the text. Longest first, so "ACME Ltd" is replaced before "ACME".
| string | $text | Text to mask. |
| array<string> | $names Candidate names to look for. |
Definition at line 649 of file privacy_guard.class.php.
References createToken(), dol_strlen(), and startSession().
|
private |
Validates a number string using the Luhn algorithm.
| string | $number | The number string, can contain spaces or hyphens. |
Definition at line 528 of file privacy_guard.class.php.
Referenced by maskCreditCardCallback().
|
private |
Start the masking session for this guard instance, once.
Definition at line 599 of file privacy_guard.class.php.
References dol_hash(), and dol_substr().
Referenced by mask(), and maskNames().
| PrivacyGuard::unmask | ( | $jsonString | ) |
Restore real data from a masked string.
This method is stateful and relies on the map generated by the preceding mask() call.
| string | $jsonString | The string containing tokens to be replaced. |
Definition at line 491 of file privacy_guard.class.php.
Referenced by unmaskAiResponse().
| PrivacyGuard::unmaskAiResponse | ( | $text | ) |
Unmasks a string from an AI response, handling cases where the AI might have stripped the [[ and ]] delimiters from a token.
| string | $text | The string to unmask. |
Definition at line 569 of file privacy_guard.class.php.
References unmask().