-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisclosed_vendors.go
More file actions
71 lines (62 loc) · 1.82 KB
/
disclosed_vendors.go
File metadata and controls
71 lines (62 loc) · 1.82 KB
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
package iabtcf
// HasDisclosedVendorsBlock returns true if there is at least one disclosedVendors block in the consent string.
func (c *LazyConsent) HasDisclosedVendorsBlock() bool {
for _, block := range c.Extras {
blockType := block.ReadIntField(0, 3)
if blockType == 1 {
return true
}
}
return false
}
// IsVendorDisclosed examines all of the disclosedVendor blocks and returns true if the given vendor ID is found
// in any of them. Returns false if there are no disclosed vendor blocks in the consent string.
//
// See also https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#disclosed-vendors
func (c *LazyConsent) IsVendorDisclosed(vendorID int) bool {
if vendorID <= 0 {
return false
}
for _, block := range c.Extras {
blockType := block.ReadIntField(0, 3)
if blockType != 1 {
// not a disclosedVendor block
continue
}
maxVendorID := block.ReadIntField(3, 16)
if vendorID > maxVendorID {
continue
}
isRangeEncoding := block.ReadBoolField(19)
if isRangeEncoding {
// range encoding
numEntries := block.ReadIntField(20, 12)
offset := 32
for range numEntries {
isaRange := block.ReadBoolField(offset)
offset++
startID := block.ReadIntField(offset, 16)
offset += 16
if vendorID == startID {
// found vendor ID
return true
}
if isaRange {
endID := block.ReadIntField(offset, 16)
offset += 16
if vendorID > startID && vendorID <= endID {
// vendor ID is in a range
return true
}
}
}
} else {
// Bit field encoding: bit fields start at offset 20, and vendor ID starts at 1
if block.ReadBoolField(19 + vendorID) {
// found vendor ID
return true
}
}
}
return false
}