6#if !defined(SIGNET_ENABLE_COMMERCIAL) || !SIGNET_ENABLE_COMMERCIAL
7#error "signet/ai/data_classification.hpp requires SIGNET_ENABLE_COMMERCIAL=ON (AGPL-3.0 commercial tier). See LICENSE_COMMERCIAL."
36#include <unordered_map>
118 (void)commercial::require_feature(
"DataClassificationOntology");
129 auto it = rules_.find(field_name);
130 if (it != rules_.end())
return it->second;
142 [[nodiscard]] std::vector<DataClassificationRule>
all_rules()
const {
143 std::vector<DataClassificationRule> out;
144 out.reserve(rules_.size());
145 for (
const auto& [_, r] : rules_) out.push_back(r);
150 [[nodiscard]]
size_t size()
const {
return rules_.size(); }
153 [[nodiscard]]
const std::string&
ontology_id()
const {
return ontology_id_; }
160 const std::string& field_name,
162 bool is_pseudonymised,
163 bool purpose_is_allowed =
true)
const
165 auto rule =
lookup(field_name);
168 if (rule.require_encryption && !is_encrypted) {
170 "Data classification violation: field '" + field_name +
171 "' requires encryption (classification=" +
172 classification_name(rule.classification) +
")"};
177 !is_pseudonymised && !rule.allow_logging) {
179 "Data classification violation: field '" + field_name +
180 "' contains sensitive data and must be pseudonymised for logging"};
184 if (!purpose_is_allowed && !rule.allowed_purposes.empty()) {
186 "Data classification violation: field '" + field_name +
187 "' processing purpose not in allowed list (GDPR Art.5(1)(b))"};
281 std::string ontology_id_;
282 std::unordered_map<std::string, DataClassificationRule> rules_;
A named collection of data classification rules forming a formal ontology.
const std::string & ontology_id() const
Ontology identifier.
DataClassificationRule lookup(const std::string &field_name) const
Look up the classification rule for a field.
DataClassificationOntology(const std::string &ontology_id="default")
Construct an ontology with the given identifier.
expected< void > validate_handling(const std::string &field_name, bool is_encrypted, bool is_pseudonymised, bool purpose_is_allowed=true) const
Validate that a field's actual handling meets classification requirements.
std::vector< DataClassificationRule > all_rules() const
Get all registered rules.
static DataClassificationOntology financial_default()
Build a default ontology with standard financial/compliance field rules.
size_t size() const
Number of registered rules.
void add_rule(const DataClassificationRule &rule)
Add a classification rule for a field.
A lightweight result type that holds either a success value of type T or an Error.
RegulatoryRegime
Regulatory regime(s) applicable to the data.
@ SEC_17A4
SEC Rule 17a-4 (records retention)
@ PCI_DSS
Payment Card Industry Data Security Standard.
@ GDPR
EU General Data Protection Regulation.
@ DORA
Digital Operational Resilience Act.
@ MIFID2
Markets in Financial Instruments Directive II.
@ EU_AI_ACT
EU Artificial Intelligence Act.
@ HIPAA
Health Insurance Portability and Accountability Act.
DataClassification
Data confidentiality level per DORA Art.8 + ISO 27001 Annex A.
@ RESTRICTED
Regulated data (GDPR, FCA, MiFID II)
@ INTERNAL
Business-internal, not for external sharing.
@ HIGHLY_RESTRICTED
Cryptographic keys, trading secrets, PII.
@ PUBLIC
No confidentiality requirement.
DataSensitivity
Data sensitivity per GDPR Art.9 special categories.
@ BIOMETRIC
Biometric data (Art.9 special category)
@ ANONYMISED
Irreversibly de-identified (Art.4(1))
@ NEUTRAL
No special sensitivity.
@ FINANCIAL_PII
Financial account data, trading activity.
@ HEALTH
Health/genetic data (Art.9 special category)
@ PII
Personally Identifiable Information.
@ PSEUDONYMISED
Identifiable only with additional key (Art.25)
@ INVALID_ARGUMENT
A caller-supplied argument is outside the valid range or violates a precondition.
Per-field data classification and handling policy.
bool allow_logging
Biometric, health → false in plaintext.
DataClassification classification
bool require_encryption
RESTRICTED/HIGHLY_RESTRICTED → true.
int64_t max_retention_ns
Max retention (default 5y)
DataSensitivity sensitivity
bool allow_export
HIGHLY_RESTRICTED → false.
std::vector< std::string > allowed_purposes
bool allow_pseudonymisation
std::string field_name
Column/field path (e.g., "user.email", "price")
int64_t min_retention_ns
Minimum retention (0 = no min)
bool allow_ml_training
PII, secrets → false.
Lightweight error value carrying an ErrorCode and a human-readable message.