Documentation ¶
Overview ¶
Package iabconsent provides structs and methods for parsing Vendor Consent Strings as defined by the IAB Consent String 1.1 Spec. More info on the spec here: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/Consent%20string%20and%20vendor%20list%20formats%20v1.1%20Final.md#vendor-consent-string-format-.
Copyright (c) 2018 LiveRamp. All rights reserved.
Written by Andy Day, Software Engineer @ LiveRamp for use in the LiveRamp Pixel Server.
Index ¶
- Constants
- type BitString
- func (b BitString) ParseBitList(offset, size int) (map[int]bool, error)
- func (b BitString) ParseBool(offset int) (bool, error)
- func (b BitString) ParseInt(offset, size int) (int, error)
- func (b BitString) ParseInt64(offset, size int) (int64, error)
- func (b BitString) ParseString(offset, size int) (string, error)
- func (b BitString) ParseTime(offset, size int) (time.Time, error)
- type ParsedConsent
- func (p *ParsedConsent) CmpID() int
- func (p *ParsedConsent) CmpVersion() int
- func (p *ParsedConsent) ConsentLanguage() string
- func (p *ParsedConsent) ConsentScreen() int
- func (p *ParsedConsent) ConsentString() string
- func (p *ParsedConsent) Created() time.Time
- func (p *ParsedConsent) LastUpdated() time.Time
- func (p *ParsedConsent) MaxVendorID() int
- func (p *ParsedConsent) PurposeAllowed(pu int) bool
- func (p *ParsedConsent) PurposesAllowed(pu []int) bool
- func (p *ParsedConsent) VendorAllowed(i int) bool
- func (p *ParsedConsent) VendorListVersion() int
- func (p *ParsedConsent) Version() int
Constants ¶
const ( VersionBitOffset = 0 VersionBitSize = 6 CreatedBitOffset = 6 CreatedBitSize = 36 UpdatedBitOffset = 42 UpdatedBitSize = 36 CmpIdOffset = 78 CmpIdSize = 12 CmpVersionOffset = 90 CmpVersionSize = 12 ConsentScreenSizeOffset = 102 ConsentScreenSize = 6 ConsentLanguageOffset = 108 ConsentLanguageSize = 12 VendorListVersionOffset = 120 VendorListVersionSize = 12 PurposesOffset = 132 PurposesSize = 24 MaxVendorIdOffset = 156 MaxVendorIdSize = 16 EncodingTypeOffset = 172 VendorBitFieldOffset = 173 DefaultConsentOffset = 173 NumEntriesOffset = 174 NumEntriesSize = 12 RangeEntryOffset = 186 VendorIdSize = 16 )
These constants represent the bit offsets and sizes of the fields in the IAB Consent String 1.1 Spec.
const ( BitField consentType = iota SingleRangeWithSingleID SingleRangeWithRange MultipleRangesWithSingleID MultipleRangesWithRange MultipleRangesMixed )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BitString ¶
type BitString struct {
// contains filtered or unexported fields
}
BitString is a simple struct which has only one field, value. The value is expected to be a string containing only ones and zeros which represent a Vendor Consent String as defined by the IAB spec found here: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/Consent%20string%20and%20vendor%20list%20formats%20v1.1%20Final.md#vendor-consent-string-format-. The type is defined to enable common operations needed to parse the string which are defined below.
func ParseBytes ¶
ParseBytes takes in a []byte |b| and returns a BitString |bs| whose value is the concatenation of the 8 bit binary representation of each element of |b|. Given that the consent string is not necessarily a multiple of 8 bits, we pad the end of the string with 0s.
func (BitString) ParseBitList ¶
ParseBitList takes a bit offset and size which specify a range of bits in the BitString's value which represent an ordered list of bits representing purposes as defined in the IAB spec. More on the purposes here: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/Consent%20string%20and%20vendor%20list%20formats%20v1.1%20Final.md#purposes-features. The resulting map's keys represent the purposes allowed for this user.
func (BitString) ParseInt ¶
ParseInt takes a bit offset and size and converts the binary number produced from that substring slice into an int.
func (BitString) ParseInt64 ¶
ParseInt64 takes a bit offset and size and converts the binary number produced from that substring slice into an int64.
func (BitString) ParseString ¶
ParseString take a bit offset and size which should represent size / 6 characters to be parsed. Each six bits is parsed into a letter and returned in a final string. ParseString will error if size is not divisible by 6.
type ParsedConsent ¶
type ParsedConsent struct {
// contains filtered or unexported fields
}
ParsedConsent contains all fields defined in the IAB Consent String 1.1 Spec.
func Parse ¶
func Parse(s string) (*ParsedConsent, error)
Parse takes a base64 Raw URL Encoded string which represents a Vendor Consent String and returns a ParsedConsent with it's fields populated with the values stored in the string. Example Usage:
var pc, err = iabconsent.Parse("BONJ5bvONJ5bvAMAPyFRAL7AAAAMhuqKklS-gAAAAAAAAAAAAAAAAAAAAAAAAAA")
func (*ParsedConsent) CmpVersion ¶
func (p *ParsedConsent) CmpVersion() int
CmpVersion returns cmpVersion.
func (*ParsedConsent) ConsentLanguage ¶
func (p *ParsedConsent) ConsentLanguage() string
ConsentLanguage returns consentLanguage.
func (*ParsedConsent) ConsentScreen ¶
func (p *ParsedConsent) ConsentScreen() int
ConsentScreen returns consentScreen.
func (*ParsedConsent) ConsentString ¶
func (p *ParsedConsent) ConsentString() string
ConsentString returns the consentString.
func (*ParsedConsent) Created ¶
func (p *ParsedConsent) Created() time.Time
Created returns the created.
func (*ParsedConsent) LastUpdated ¶
func (p *ParsedConsent) LastUpdated() time.Time
LastUpdated returns lastUpdated.
func (*ParsedConsent) MaxVendorID ¶
func (p *ParsedConsent) MaxVendorID() int
MaxVendorID returns maxVendorID.
func (*ParsedConsent) PurposeAllowed ¶
func (p *ParsedConsent) PurposeAllowed(pu int) bool
PurposeAllowed returns true if the consent ID |pu| exists in the ParsedConsent and false otherwise.
func (*ParsedConsent) PurposesAllowed ¶
func (p *ParsedConsent) PurposesAllowed(pu []int) bool
PurposesAllowed returns true if each consent ID in |pu| exists in the ParsedConsent, and false if any does not.
func (*ParsedConsent) VendorAllowed ¶
func (p *ParsedConsent) VendorAllowed(i int) bool
VendorAllowed returns true if the ParsedConsent contains affirmative consent for Vendor of ID |i|.
func (*ParsedConsent) VendorListVersion ¶
func (p *ParsedConsent) VendorListVersion() int
VendorListVersion returns vendorListVersion.