iabconsent

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2018 License: MIT Imports: 7 Imported by: 2

README

iabconsent

Build Status

A Golang implementation of the IAB Consent String 1.1 Spec

To install:

go get -v github.com/LiveRamp/iabconsent

This package defines a struct (ParsedConsent) which contains all of the fields of the IAB Consent String. The function Parse(s string) accepts the Base64 Raw URL Encoded cookie string and returns a ParsedConsent with all relevent fields populated.

Example use:

package main

import (
  "fmt"

  "github.com/LiveRamp/iabconsent"
)

func main() {
  var pc, err = iabconsent.Parse("BONJ5bvONJ5bvAMAPyFRAL7AAAAMhuqKklS-gAAAAAAAAAAAAAAAAAAAAAAAAAA")
  if err != nil {
    panic(err)
  }
  fmt.Printf("%+v\n", pc)
}

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

View Source
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.

View Source
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

func ParseBytes(b []byte) BitString

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

func (b BitString) ParseBitList(offset, size int) (map[int]bool, error)

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) ParseBool

func (b BitString) ParseBool(offset int) (bool, error)

ParseBool returns a bool representing the bit at the passed offset.

func (BitString) ParseInt

func (b BitString) ParseInt(offset, size int) (int, error)

ParseInt takes a bit offset and size and converts the binary number produced from that substring slice into an int.

func (BitString) ParseInt64

func (b BitString) ParseInt64(offset, size int) (int64, error)

ParseInt64 takes a bit offset and size and converts the binary number produced from that substring slice into an int64.

func (BitString) ParseString

func (b BitString) ParseString(offset, size int) (string, error)

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.

func (BitString) ParseTime

func (b BitString) ParseTime(offset, size int) (time.Time, error)

ParseTime takes a bit offset and size and converts the binary number produced from that substring slice into a time.Time.

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) CmpID

func (p *ParsedConsent) CmpID() int

CmpID returns cmpID.

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.

func (*ParsedConsent) Version

func (p *ParsedConsent) Version() int

Version returns the version.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL