iabconsent

package module
v0.0.0-...-89ccf5b Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2018 License: MIT Imports: 3 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(p *ParsedConsent) string

Format takes a ParsedConsent and returns the base64 Raw URL Encoded string

Example Usage:

var cs = iabconsent.Format("BONJ5bvONJ5bvAMAPyFRAL7AAAAMhuqKklS-gAAAAAAAAAAAAAAAAAAAAAAAAAA")

Types

type Bits

type Bits struct {
	// contains filtered or unexported fields
}

func NewBits

func NewBits(bytes []byte) *Bits

func (*Bits) ReadBool

func (b *Bits) ReadBool() bool

func (*Bits) ReadInt

func (b *Bits) ReadInt(n uint) int

func (*Bits) WriteBool

func (b *Bits) WriteBool(v bool)

WriteBool writes the value v in the next bit

func (*Bits) WriteInt

func (b *Bits) WriteInt(v int, n uint)

WriteInt writes the value v in the next n bits

func (*Bits) WriteNumber

func (b *Bits) WriteNumber(v int64, n uint)

func (*Bits) WriteString

func (b *Bits) WriteString(v string)

WriteString writes the value v in the len(v)* 6 next bits

type ConsentReader

type ConsentReader struct {
	*Bits
}

ConsentReader provides additional Consent String-specific bit-reading functionality on top of Bits.

func NewConsentReader

func NewConsentReader(src []byte) *ConsentReader

NewConsentReader returns a new ConsentReader backed by src.

func (*ConsentReader) ReadBitField

func (r *ConsentReader) ReadBitField(n uint) map[int]bool

ReadBitField reads the next n bits and converts them to a map[int]bool.

func (*ConsentReader) ReadRangeEntries

func (r *ConsentReader) ReadRangeEntries(n uint) []*RangeEntry

ReadRangeEntries reads the next n bits and converts them to a []*RangeEntry

func (*ConsentReader) ReadString

func (r *ConsentReader) ReadString(n uint) string

ReadString returns a string of length n by reading the next 6 * n bits.

func (*ConsentReader) ReadTime

func (r *ConsentReader) ReadTime() time.Time

ReadTime reads the next 36 bits representing the epoch time in deciseconds and converts it to a time.Time.

func (*ConsentReader) WriteTime

func (r *ConsentReader) WriteTime(v time.Time)

WriteTime writes the value v in the next 36 bits

type ParsedConsent

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
}

ParsedConsent represents data extracted from an IAB Consent String, v1.1.

func Parse

func Parse(s string) (p *ParsedConsent, err error)

Parse takes a base64 Raw URL Encoded string which represents a Vendor Consent String and returns a ParsedConsent with its fields populated with the values stored in the string.

Example Usage:

var pc, err = iabconsent.Parse("BONJ5bvONJ5bvAMAPyFRAL7AAAAMhuqKklS-gAAAAAAAAAAAAAAAAAAAAAAAAAA")

func (*ParsedConsent) EveryPurposeAllowed

func (p *ParsedConsent) EveryPurposeAllowed(ps []int) bool

EveryPurposeAllowed returns true iff every purpose number in ps exists in the ParsedConsent, otherwise false.

func (*ParsedConsent) PurposeAllowed

func (p *ParsedConsent) PurposeAllowed(v int) bool

PurposeAllowed returns true if the purpose number exists in the ParsedConsent and is true, otherwise false

func (*ParsedConsent) ToConsentString

func (p *ParsedConsent) ToConsentString() string

func (*ParsedConsent) ToString

func (p *ParsedConsent) ToString() string

func (*ParsedConsent) VendorAllowed

func (p *ParsedConsent) VendorAllowed(v int) bool

VendorAllowed returns true if the ParsedConsent contains affirmative consent for VendorID v.

type RangeEntry

type RangeEntry struct {
	StartVendorID int
	EndVendorID   int
}

RangeEntry defines an inclusive range of vendor IDs from StartVendorID to EndVendorID.

Jump to

Keyboard shortcuts

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