icookforms 0.1.0

The World's Reference Cookie Audit Software - Complete Security & Compliance Analysis
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
//! Regulation types for compliance checking

use serde::{Deserialize, Serialize};
use std::fmt;

/// Privacy and data protection regulations
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum Regulation {
    /// General Data Protection Regulation (EU)
    GDPR,

    /// UK GDPR (United Kingdom)
    UKGDPR,

    /// California Consumer Privacy Act
    CCPA,

    /// California Privacy Rights Act (enhanced CCPA)
    CPRA,

    /// Lei Geral de Proteção de Dados (Brazil)
    LGPD,

    /// Personal Information Protection and Electronic Documents Act (Canada)
    PIPEDA,

    /// Protection of Personal Information Act (South Africa)
    POPIA,

    /// Personal Data Protection Act (Singapore)
    PDPA,

    /// Privacy Act (Australia)
    PrivacyAct,

    /// ePrivacy Directive (EU)
    EPrivacy,

    /// Children's Online Privacy Protection Act (USA)
    COPPA,

    /// Health Insurance Portability and Accountability Act (USA)
    HIPAA,

    /// Payment Card Industry Data Security Standard
    PCIDSS,

    /// Virginia Consumer Data Protection Act
    VCDPA,

    /// Colorado Privacy Act
    CPA,

    /// Connecticut Data Privacy Act
    CTDPA,

    /// Utah Consumer Privacy Act
    UCPA,

    /// China Personal Information Protection Law
    PIPL,

    /// Japan Act on the Protection of Personal Information
    APPI,

    /// Korea Personal Information Protection Act
    PIPA,

    /// Thailand Personal Data Protection Act
    THPDPA,

    /// Indonesia Personal Data Protection
    IDPDP,

    /// Philippines Data Privacy Act
    PHDPA,

    /// New Zealand Privacy Act
    NZPA,

    /// Swiss Federal Act on Data Protection
    FADP,
}

impl fmt::Display for Regulation {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::GDPR => write!(f, "GDPR (EU General Data Protection Regulation)"),
            Self::UKGDPR => write!(f, "UK GDPR"),
            Self::CCPA => write!(f, "CCPA (California Consumer Privacy Act)"),
            Self::CPRA => write!(f, "CPRA (California Privacy Rights Act)"),
            Self::LGPD => write!(f, "LGPD (Brazil)"),
            Self::PIPEDA => write!(f, "PIPEDA (Canada)"),
            Self::POPIA => write!(f, "POPIA (South Africa)"),
            Self::PDPA => write!(f, "PDPA (Singapore)"),
            Self::PrivacyAct => write!(f, "Privacy Act (Australia)"),
            Self::EPrivacy => write!(f, "ePrivacy Directive (EU)"),
            Self::COPPA => write!(f, "COPPA (Children's Online Privacy)"),
            Self::HIPAA => write!(f, "HIPAA (Health Insurance Portability)"),
            Self::PCIDSS => write!(f, "PCI DSS (Payment Card Industry)"),
            Self::VCDPA => write!(f, "VCDPA (Virginia)"),
            Self::CPA => write!(f, "CPA (Colorado)"),
            Self::CTDPA => write!(f, "CTDPA (Connecticut)"),
            Self::UCPA => write!(f, "UCPA (Utah)"),
            Self::PIPL => write!(f, "PIPL (China)"),
            Self::APPI => write!(f, "APPI (Japan)"),
            Self::PIPA => write!(f, "PIPA (Korea)"),
            Self::THPDPA => write!(f, "PDPA (Thailand)"),
            Self::IDPDP => write!(f, "PDP (Indonesia)"),
            Self::PHDPA => write!(f, "Data Privacy Act (Philippines)"),
            Self::NZPA => write!(f, "Privacy Act (New Zealand)"),
            Self::FADP => write!(f, "FADP (Switzerland)"),
        }
    }
}

impl Regulation {
    /// Get the short name/acronym
    #[must_use]
    pub fn short_name(&self) -> &'static str {
        match self {
            Self::GDPR => "GDPR",
            Self::UKGDPR => "UK GDPR",
            Self::CCPA => "CCPA",
            Self::CPRA => "CPRA",
            Self::LGPD => "LGPD",
            Self::PIPEDA => "PIPEDA",
            Self::POPIA => "POPIA",
            Self::PDPA | Self::THPDPA => "PDPA",
            Self::PrivacyAct | Self::NZPA => "Privacy Act",
            Self::EPrivacy => "ePrivacy",
            Self::COPPA => "COPPA",
            Self::HIPAA => "HIPAA",
            Self::PCIDSS => "PCI DSS",
            Self::VCDPA => "VCDPA",
            Self::CPA => "CPA",
            Self::CTDPA => "CTDPA",
            Self::UCPA => "UCPA",
            Self::PIPL => "PIPL",
            Self::APPI => "APPI",
            Self::PIPA => "PIPA",
            Self::IDPDP => "PDP",
            Self::PHDPA => "DPA",
            Self::FADP => "FADP",
        }
    }

    /// Get the jurisdiction/region
    #[must_use]
    pub fn jurisdiction(&self) -> &'static str {
        match self {
            Self::GDPR | Self::EPrivacy => "European Union",
            Self::UKGDPR => "United Kingdom",
            Self::CCPA | Self::CPRA => "California, USA",
            Self::LGPD => "Brazil",
            Self::PIPEDA => "Canada",
            Self::POPIA => "South Africa",
            Self::PDPA => "Singapore",
            Self::PrivacyAct => "Australia",
            Self::COPPA | Self::HIPAA => "United States",
            Self::PCIDSS => "Global (Payment Cards)",
            Self::VCDPA => "Virginia, USA",
            Self::CPA => "Colorado, USA",
            Self::CTDPA => "Connecticut, USA",
            Self::UCPA => "Utah, USA",
            Self::PIPL => "China",
            Self::APPI => "Japan",
            Self::PIPA => "South Korea",
            Self::THPDPA => "Thailand",
            Self::IDPDP => "Indonesia",
            Self::PHDPA => "Philippines",
            Self::NZPA => "New Zealand",
            Self::FADP => "Switzerland",
        }
    }

    /// Get consent model (opt-in vs opt-out)
    #[must_use]
    pub fn consent_model(&self) -> ConsentModel {
        match self {
            Self::GDPR
            | Self::UKGDPR
            | Self::EPrivacy
            | Self::LGPD
            | Self::POPIA
            | Self::PDPA
            | Self::PIPL
            | Self::APPI
            | Self::PIPA
            | Self::THPDPA
            | Self::FADP => ConsentModel::OptIn,

            Self::CCPA | Self::CPRA | Self::VCDPA | Self::CPA | Self::CTDPA | Self::UCPA => {
                ConsentModel::OptOut
            }

            Self::PIPEDA
            | Self::PrivacyAct
            | Self::COPPA
            | Self::HIPAA
            | Self::PCIDSS
            | Self::IDPDP
            | Self::PHDPA
            | Self::NZPA => ConsentModel::Mixed,
        }
    }

    /// Check if regulation requires explicit consent for cookies
    #[must_use]
    pub fn requires_cookie_consent(&self) -> bool {
        matches!(
            self,
            Self::GDPR
                | Self::UKGDPR
                | Self::EPrivacy
                | Self::LGPD
                | Self::POPIA
                | Self::PDPA
                | Self::PIPL
                | Self::APPI
                | Self::PIPA
                | Self::THPDPA
                | Self::FADP
        )
    }

    /// Get maximum penalty/fine
    #[must_use]
    pub fn max_penalty(&self) -> Option<&'static str> {
        match self {
            Self::GDPR | Self::UKGDPR => Some("€20M or 4% of annual global revenue"),
            Self::CCPA | Self::CPRA => Some("$7,500 per intentional violation"),
            Self::LGPD => Some("R$ 50M per infraction"),
            Self::POPIA => Some("R 10M or up to 10 years imprisonment"),
            Self::PIPL => Some("¥50M or 5% of annual revenue"),
            Self::VCDPA => Some("$7,500 per violation"),
            Self::CPA => Some("$20,000 per violation"),
            Self::CTDPA => Some("$5,000 per violation"),
            _ => None,
        }
    }

    /// Check if regulation has extraterritorial reach
    #[must_use]
    pub fn is_extraterritorial(&self) -> bool {
        matches!(
            self,
            Self::GDPR | Self::CCPA | Self::CPRA | Self::PIPL | Self::LGPD
        )
    }

    /// Get official website/documentation URL
    #[must_use]
    pub fn official_url(&self) -> &'static str {
        match self {
            Self::GDPR => "https://gdpr.eu/",
            Self::UKGDPR => "https://ico.org.uk/for-organisations/guide-to-data-protection/",
            Self::CCPA => "https://oag.ca.gov/privacy/ccpa",
            Self::CPRA => "https://cppa.ca.gov/",
            Self::LGPD => "https://www.gov.br/anpd/",
            Self::PIPEDA => "https://www.priv.gc.ca/en/privacy-topics/privacy-laws-in-canada/",
            Self::POPIA => "https://popia.co.za/",
            Self::PDPA => "https://www.pdpc.gov.sg/",
            Self::PrivacyAct => "https://www.oaic.gov.au/",
            Self::EPrivacy => "https://ec.europa.eu/digital-single-market/en/eprivacy-directive",
            Self::COPPA => "https://www.ftc.gov/legal-library/browse/rules/childrens-online-privacy-protection-rule-coppa",
            Self::HIPAA => "https://www.hhs.gov/hipaa/",
            Self::PCIDSS => "https://www.pcisecuritystandards.org/",
            Self::PIPL => "http://www.npc.gov.cn/",
            _ => "",
        }
    }

    /// Get all regulations applicable to a specific region
    #[must_use]
    pub fn for_region(region: Region) -> Vec<Self> {
        match region {
            Region::EU => vec![Self::GDPR, Self::EPrivacy],
            Region::UK => vec![Self::UKGDPR],
            Region::US => vec![
                Self::CCPA,
                Self::CPRA,
                Self::VCDPA,
                Self::CPA,
                Self::CTDPA,
                Self::UCPA,
                Self::COPPA,
                Self::HIPAA,
            ],
            Region::California => vec![Self::CCPA, Self::CPRA],
            Region::Brazil => vec![Self::LGPD],
            Region::Canada => vec![Self::PIPEDA],
            Region::SouthAfrica => vec![Self::POPIA],
            Region::Singapore => vec![Self::PDPA],
            Region::Australia => vec![Self::PrivacyAct],
            Region::China => vec![Self::PIPL],
            Region::Japan => vec![Self::APPI],
            Region::Korea => vec![Self::PIPA],
            Region::Thailand => vec![Self::THPDPA],
            Region::Switzerland => vec![Self::FADP],
            Region::Global => vec![Self::PCIDSS],
        }
    }
}

/// Consent model type
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum ConsentModel {
    /// Requires explicit opt-in (GDPR style)
    OptIn,
    /// Allows opt-out (CCPA style)
    OptOut,
    /// Mixed requirements
    Mixed,
}

impl fmt::Display for ConsentModel {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::OptIn => write!(f, "Opt-In (Explicit Consent Required)"),
            Self::OptOut => write!(f, "Opt-Out (Right to Refuse)"),
            Self::Mixed => write!(f, "Mixed (Varies by Context)"),
        }
    }
}

/// Geographic regions for regulation applicability
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum Region {
    /// European Union
    EU,
    /// United Kingdom
    UK,
    /// United States (federal)
    US,
    /// California specifically
    California,
    /// Brazil
    Brazil,
    /// Canada
    Canada,
    /// South Africa
    SouthAfrica,
    /// Singapore
    Singapore,
    /// Australia
    Australia,
    /// China
    China,
    /// Japan
    Japan,
    /// South Korea
    Korea,
    /// Thailand
    Thailand,
    /// Switzerland
    Switzerland,
    /// Global (applies everywhere)
    Global,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_regulation_display() {
        assert!(Regulation::GDPR.to_string().contains("GDPR"));
        assert!(Regulation::CCPA.to_string().contains("California"));
    }

    #[test]
    fn test_consent_model() {
        assert_eq!(Regulation::GDPR.consent_model(), ConsentModel::OptIn);
        assert_eq!(Regulation::CCPA.consent_model(), ConsentModel::OptOut);
    }

    #[test]
    fn test_cookie_consent_requirement() {
        assert!(Regulation::GDPR.requires_cookie_consent());
        assert!(Regulation::LGPD.requires_cookie_consent());
        assert!(!Regulation::CCPA.requires_cookie_consent());
    }

    #[test]
    fn test_jurisdiction() {
        assert_eq!(Regulation::GDPR.jurisdiction(), "European Union");
        assert_eq!(Regulation::CCPA.jurisdiction(), "California, USA");
        assert_eq!(Regulation::LGPD.jurisdiction(), "Brazil");
    }

    #[test]
    fn test_max_penalty() {
        assert!(Regulation::GDPR.max_penalty().is_some());
        assert!(Regulation::CCPA.max_penalty().is_some());
    }

    #[test]
    fn test_extraterritorial() {
        assert!(Regulation::GDPR.is_extraterritorial());
        assert!(Regulation::CCPA.is_extraterritorial());
        assert!(!Regulation::COPPA.is_extraterritorial());
    }

    #[test]
    fn test_region_regulations() {
        let eu_regs = Regulation::for_region(Region::EU);
        assert!(eu_regs.contains(&Regulation::GDPR));
        assert!(eu_regs.contains(&Regulation::EPrivacy));

        let us_regs = Regulation::for_region(Region::US);
        assert!(us_regs.contains(&Regulation::CCPA));
        assert!(us_regs.contains(&Regulation::COPPA));
    }

    #[test]
    fn test_short_name() {
        assert_eq!(Regulation::GDPR.short_name(), "GDPR");
        assert_eq!(Regulation::CCPA.short_name(), "CCPA");
    }

    #[test]
    fn test_official_url() {
        assert!(!Regulation::GDPR.official_url().is_empty());
        assert!(Regulation::GDPR.official_url().starts_with("https://"));
    }
}