1818# include < iostream>
1919#endif
2020
21+
2122namespace DB
2223{
2324namespace ErrorCodes
@@ -57,7 +58,7 @@ class SensitiveDataMasker::MaskingRule
5758 DB::ErrorCodes::CANNOT_COMPILE_REGEXP);
5859 }
5960
60- int apply (std::string & data) const
61+ uint64_t apply (std::string & data) const
6162 {
6263 auto m = RE2::GlobalReplace (&data, regexp, replacement);
6364 matches_count += m;
@@ -69,6 +70,7 @@ class SensitiveDataMasker::MaskingRule
6970 uint64_t getMatchesCount () const { return matches_count; }
7071};
7172
73+
7274SensitiveDataMasker::SensitiveDataMasker (const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix)
7375{
7476 Poco::Util::AbstractConfiguration::Keys keys;
@@ -85,23 +87,19 @@ SensitiveDataMasker::SensitiveDataMasker(const Poco::Util::AbstractConfiguration
8587
8688 auto rule_name = config.getString (rule_config_prefix + " .name" , rule_config_prefix);
8789
88- if (used_names.count (rule_name) == 0 )
89- {
90- used_names.insert (rule_name);
91- }
92- else
90+ if (!used_names.insert (rule_name).second )
9391 {
9492 throw Exception (
95- " query_masking_rules configuration contains more than one rule named '" + rule_name + " '." ,
93+ " Query_masking_rules configuration contains more than one rule named '" + rule_name + " '." ,
9694 ErrorCodes::INVALID_CONFIG_PARAMETER);
9795 }
9896
9997 auto regexp = config.getString (rule_config_prefix + " .regexp" , " " );
10098
101- if (regexp == " " )
99+ if (regexp. empty () )
102100 {
103101 throw Exception (
104- " query_masking_rules configuration, rule '" + rule_name + " ' has no <regexp> node or <regexp> is empty." ,
102+ " Query_masking_rules configuration, rule '" + rule_name + " ' has no <regexp> node or <regexp> is empty." ,
105103 ErrorCodes::NO_ELEMENTS_IN_CONFIG);
106104 }
107105
@@ -122,7 +120,8 @@ SensitiveDataMasker::SensitiveDataMasker(const Poco::Util::AbstractConfiguration
122120 LOG_WARNING (logger, " Unused param " << config_prefix << ' .' << rule);
123121 }
124122 }
125- auto rules_count = this ->rulesCount ();
123+
124+ auto rules_count = rulesCount ();
126125 if (rules_count > 0 )
127126 {
128127 LOG_INFO (logger, rules_count << " query masking rules loaded." );
@@ -138,13 +137,11 @@ void SensitiveDataMasker::addMaskingRule(
138137}
139138
140139
141- int SensitiveDataMasker::wipeSensitiveData (std::string & data) const
140+ size_t SensitiveDataMasker::wipeSensitiveData (std::string & data) const
142141{
143- int matches = 0 ;
142+ size_t matches = 0 ;
144143 for (auto & rule : all_masking_rules)
145- {
146144 matches += rule->apply (data);
147- }
148145 return matches;
149146}
150147
@@ -159,7 +156,7 @@ void SensitiveDataMasker::printStats()
159156}
160157#endif
161158
162- unsigned long SensitiveDataMasker::rulesCount () const
159+ size_t SensitiveDataMasker::rulesCount () const
163160{
164161 return all_masking_rules.size ();
165162}
0 commit comments