dolibarr 24.0.0-beta
PrivacyGuard Class Reference

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.
 

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.
 
 createToken ($value, $type)
 Create a unique token and store the original value in the map.
 

Detailed Description

Class to manage privacy data masking and unmasking.

Definition at line 28 of file privacy_guard.class.php.

Member Function Documentation

◆ createToken()

PrivacyGuard::createToken ( $value,
$type )
private

Create a unique token and store the original value in the map.

Parameters
string$valueThe original sensitive value.
string$typeThe type of data (e.g., 'EMAIL').
Returns
string The generated token (e.g., [[EMAIL_1]]).

Definition at line 577 of file privacy_guard.class.php.

Referenced by mask(), and maskCreditCardCallback().

◆ mask()

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.

Parameters
string$textThe input string containing potentially sensitive data.
Returns
string The masked string with tokens replacing sensitive data.
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string

Definition at line 53 of file privacy_guard.class.php.

References createToken().

◆ maskCreditCardCallback()

PrivacyGuard::maskCreditCardCallback ( array $matches)
private

Callback function for preg_replace_callback to mask credit cards.

It first validates the number using the Luhn algorithm.

Parameters
array<int,string>$matches The regex matches array.
Returns
string The token if valid, otherwise the original string.

Definition at line 487 of file privacy_guard.class.php.

References createToken(), and passesLuhnCheck().

◆ passesLuhnCheck()

PrivacyGuard::passesLuhnCheck ( $number)
private

Validates a number string using the Luhn algorithm.

Parameters
string$numberThe number string, can contain spaces or hyphens.
Returns
bool True if the number is valid, false otherwise.

Definition at line 504 of file privacy_guard.class.php.

Referenced by maskCreditCardCallback().

◆ unmask()

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.

Parameters
string$jsonStringThe string containing tokens to be replaced.
Returns
string The unmasked string with original data restored.

Definition at line 467 of file privacy_guard.class.php.

Referenced by unmaskAiResponse().

◆ 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.

Parameters
string$textThe string to unmask.
Returns
string The fully unmasked string.

Definition at line 545 of file privacy_guard.class.php.

References unmask().


The documentation for this class was generated from the following file: