-
Notifications
You must be signed in to change notification settings - Fork 16
/
parsed_consent.go
73 lines (65 loc) · 1.84 KB
/
parsed_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
package iabconsent
import (
"time"
)
// ParsedConsent represents data extracted from an IAB Consent String, v1.1.
type ParsedConsent struct {
Version int
Created time.Time
LastUpdated time.Time
CMPID int
CMPVersion int
ConsentScreen int
ConsentLanguage string
VendorListVersion int
PurposesAllowed map[int]bool
MaxVendorID int
IsRangeEncoding bool
ConsentedVendors map[int]bool
DefaultConsent bool
NumEntries int
RangeEntries []*RangeEntry
}
// EveryPurposeAllowed returns true iff every purpose number in ps exists in
// the ParsedConsent, otherwise false.
func (p *ParsedConsent) EveryPurposeAllowed(ps []int) bool {
for _, rp := range ps {
if !p.PurposesAllowed[rp] {
return false
}
}
return true
}
// PurposeAllowed returns true if the passed purpose number exists in
// the ParsedConsent, otherwise false.
func (p *ParsedConsent) PurposeAllowed(ps int) bool {
if !p.PurposesAllowed[ps] {
return false
}
return true
}
// VendorAllowed returns true if the ParsedConsent contains affirmative consent
// for VendorID v.
func (p *ParsedConsent) VendorAllowed(v int) bool {
if p.IsRangeEncoding {
for _, re := range p.RangeEntries {
if re.StartVendorID <= v && v <= re.EndVendorID {
return !p.DefaultConsent
}
}
return p.DefaultConsent
}
return p.ConsentedVendors[v]
}
// SuitableToProcess is the union of EveryPurposeAllowed(ps) and
// VendorAllowed(v). It's used to make possible an interface that
// can be used to check whether its legal to process v1 & v2 strings.
func (p *ParsedConsent) SuitableToProcess(ps []int, v int) bool {
return p.EveryPurposeAllowed(ps) && p.VendorAllowed(v)
}
// RangeEntry defines an inclusive range of vendor IDs from StartVendorID to
// EndVendorID.
type RangeEntry struct {
StartVendorID int
EndVendorID int
}