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."
37#include <unordered_map>
119 auto gate = commercial::require_feature(
"DataClassificationOntology");
120 if (!gate)
throw std::runtime_error(gate.error().message);
131 auto it = rules_.find(field_name);
132 if (it != rules_.end())
return it->second;
144 [[nodiscard]] std::vector<DataClassificationRule>
all_rules()
const {
145 std::vector<DataClassificationRule> out;
146 out.reserve(rules_.size());
147 for (
const auto& [_, r] : rules_) out.push_back(r);
152 [[nodiscard]]
size_t size()
const {
return rules_.size(); }
155 [[nodiscard]]
const std::string&
ontology_id()
const {
return ontology_id_; }
162 const std::string& field_name,
164 bool is_pseudonymised,
165 bool purpose_is_allowed =
true)
const
167 auto rule =
lookup(field_name);
170 if (rule.require_encryption && !is_encrypted) {
172 "Data classification violation: field '" + field_name +
173 "' requires encryption (classification=" +
174 classification_name(rule.classification) +
")"};
179 !is_pseudonymised && !rule.allow_logging) {
181 "Data classification violation: field '" + field_name +
182 "' contains sensitive data and must be pseudonymised for logging"};
186 if (!purpose_is_allowed && !rule.allowed_purposes.empty()) {
188 "Data classification violation: field '" + field_name +
189 "' processing purpose not in allowed list (GDPR Art.5(1)(b))"};
283 std::string ontology_id_;
284 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.