Skip to content

Commit

Permalink
add support for other GPP sections
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvialiu404 committed Jun 8, 2023
1 parent 891f6be commit ef7d015
Show file tree
Hide file tree
Showing 7 changed files with 805 additions and 73 deletions.
44 changes: 44 additions & 0 deletions ccpa_parsed_consent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package iabconsent

import "github.com/pkg/errors"

const (
CCPAYes = 'Y'
CCPANo = 'N'
CCPANotApplicable = '-'
CCPAVersion = 1
)

// CcpaParsedConsent represents data extract from a California Consumer Privacy Act (CCPA) consent string.
// Format can be found here: https://github.com/InteractiveAdvertisingBureau/USPrivacy/blob/master/CCPA/US%20Privacy%20String.md
type CcpaParsedConsent struct {
// The version of this string specification used to encode the string
Version int

// N = No, Y = Yes, - = Not Applicable
Notice uint8

// N = No, Y = Yes, - = Not Applicable; For use ONLY when CCPA does not apply.
OptOutSale uint8

// 0 = No, 1 = Yes, - = Not Applicable
LSPACoveredTransaction uint8
}

func IsValidCCPAString(ccpaString string) (bool, error) {
if len(ccpaString) != 4 {
return false, errors.Wrap(nil, "invalid uspv consent string length")
}

if ccpaString[0]-'0' != CCPAVersion {
return false, errors.Wrap(nil, "invalid uspv consent string version")
}

for i := 1; i < 4; i++ {
if ccpaString[i] != CCPAYes && ccpaString[i] != CCPANo && ccpaString[i] != CCPANotApplicable {
return false, errors.Wrap(nil, "invalid uspv consent string")
}
}

return true, nil
}
32 changes: 30 additions & 2 deletions gpp_parsed_consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import (
"github.com/pkg/errors"
)

const (
SectionIDEUTCFv2 = 2
SectionIDCANTCF = 5
SectionIDUSPV1 = 6
SectionIDUSNAT = 7
SectionIDUSCA = 8
SectionIDUSVA = 9
SectionIDUSCO = 10
SectionIDUSUT = 11
SectionIDUSCT = 12
)

// GppHeader is the first section of a GPP Consent String.
// See ParseGppHeader for in-depth format.
type GppHeader struct {
Expand Down Expand Up @@ -105,13 +117,28 @@ func MapGppSectionToParser(s string) ([]GppSectionParser, error) {
for i := 1; i < len(segments); i++ {
var gppSection GppSectionParser
switch sid := gppHeader.Sections[i-1]; sid {
case 7:
case SectionIDEUTCFv2:
gppSection = NewTCFEU(segments[i])
case SectionIDCANTCF:
gppSection = NewTCFCA(segments[i])
case SectionIDUSPV1:
gppSection = NewUSPV(segments[i])
case SectionIDUSNAT:
gppSection = NewMspaNational(segments[i])
case 9:
case SectionIDUSCA:
gppSection = NewMspaCA(segments[i])
case SectionIDUSVA:
gppSection = NewMspaVA(segments[i])
case SectionIDUSCO:
gppSection = NewMspaCO(segments[i])
case SectionIDUSUT:
gppSection = NewMspaUT(segments[i])
case SectionIDUSCT:
gppSection = NewMspaCT(segments[i])
default:
// Skip if no matching struct, as Section ID is not supported yet.
// Any newly supported Section IDs should be added as cases here.
// TODO: GPP error handling
}
if gppSection != nil {
gppSections = append(gppSections, gppSection)
Expand All @@ -136,6 +163,7 @@ func ParseGppConsent(s string) (map[int]GppParsedConsent, error) {
var consentErr error
consent, consentErr = gpp.ParseConsent()
if consentErr != nil {
// TODO: GPP error handling
// If an error, quietly do not add the consent value to map.
} else {
gppConsents[gpp.GetSectionId()] = consent
Expand Down
Loading

0 comments on commit ef7d015

Please sign in to comment.