-
Notifications
You must be signed in to change notification settings - Fork 0
/
consent.go
89 lines (78 loc) · 2.61 KB
/
consent.go
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
package iabtcf
import (
"time"
)
// Consent represents Core Consent extracted from an IAB Consent String v2.0
// It's implemented according to specification: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md
type Consent struct {
Version int
Created time.Time
LastUpdated time.Time
CMPID int
CMPVersion int
ConsentScreen int
ConsentLanguage string
VendorListVersion int
TcfPolicyVersion int
IsServiceSpecific bool
UseNonStandardStacks bool
SpecialFeatureOptIns Bits
PurposesConsent Bits
PurposesLITransparency Bits
PurposeOneTreatment bool
PublisherCC string
MaxVendorID int
IsRangeEncoding bool
ConsentedVendors Bits
NumEntries int
RangeEntries []RangeEntry
}
// RangeEntry defines a range groups of Vendor IDs who have been disclosed to a user
type RangeEntry struct {
StartOrOnlyVendorId int
EndVendorID int
}
// EveryPurposeAllowed returns true if every purpose number is allowed in
// the ParsedConsent, otherwise false
func (p *Consent) EveryPurposeAllowed(numbers []int) bool {
for _, number := range numbers {
if !p.PurposeAllowed(number) {
return false
}
}
return true
}
// PurposeAllowed checks if purpose is allowed in the ParsedConsent
func (p *Consent) PurposeAllowed(number int) bool {
return p.PurposesConsent.HasBit(number)
}
// PurposeLITransparencyAllowed checks if purposeLITransparency is allowed in the ParsedConsent
func (p *Consent) PurposeLITransparencyAllowed(number int) bool {
return p.PurposesLITransparency.HasBit(number)
}
// EverySpecialFeatureAllowed returns true if every special feature number is allowed in
// the ParsedConsent, otherwise false
func (p *Consent) EverySpecialFeatureAllowed(numbers []int) bool {
for _, number := range numbers {
if !p.SpecialFeatureAllowed(number) {
return false
}
}
return true
}
// SpecialFeatureAllowed checks if special feature is allowed in the ParsedConsent
func (p *Consent) SpecialFeatureAllowed(number int) bool {
return p.SpecialFeatureOptIns.HasBit(number)
}
// VendorAllowed checks if vendor is in the list of vendors user has given his consent to
func (p *Consent) VendorAllowed(number int) bool {
if p.IsRangeEncoding {
for _, e := range p.RangeEntries {
if e.StartOrOnlyVendorId <= number && number <= e.EndVendorID {
return true
}
}
return false
}
return p.ConsentedVendors.HasBit(number)
}