From 1c9c17c72e6189ae7d4c40d750f5866ae46d01ce Mon Sep 17 00:00:00 2001 From: Sylvia Liu Date: Tue, 13 Jun 2023 11:13:01 -0400 Subject: [PATCH] ccpa support; formatting --- ccpa_parsed_consent.go | 13 +++++++++++++ gpp_parsed_consent_test.go | 8 ++++++++ mspa_sections.go | 33 ++++++++++++--------------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/ccpa_parsed_consent.go b/ccpa_parsed_consent.go index 0227609..60b28ce 100644 --- a/ccpa_parsed_consent.go +++ b/ccpa_parsed_consent.go @@ -42,3 +42,16 @@ func IsValidCCPAString(ccpaString string) (bool, error) { return true, nil } + +func ParseCCPA(s string) (*CcpaParsedConsent, error) { + if valid, err := IsValidCCPAString(s); !valid { + return nil, err + } + + return &CcpaParsedConsent{ + int(s[0] - '0'), + s[1], + s[2], + s[3], + }, nil +} diff --git a/gpp_parsed_consent_test.go b/gpp_parsed_consent_test.go index 10eeaf3..18a4c26 100644 --- a/gpp_parsed_consent_test.go +++ b/gpp_parsed_consent_test.go @@ -61,6 +61,14 @@ func (s *GppParseSuite) TestParseGppHeader(c *check.C) { Version: 1, Sections: []int{6, 7}}, }, + { + description: "US CA", + header: "DBABBg", + expected: &iabconsent.GppHeader{ + Type: 3, + Version: 1, + Sections: []int{8}}, + }, } for _, tc := range tcs { diff --git a/mspa_sections.go b/mspa_sections.go index a659a79..7183815 100644 --- a/mspa_sections.go +++ b/mspa_sections.go @@ -48,10 +48,6 @@ type NotSupported struct { GppSection } -func (u NotSupported) ParseConsent() (GppParsedConsent, error) { - return nil, errors.New(fmt.Sprintf("Section ID %d is not supported", u.sectionId)) -} - func NewTCFEU(section string) *TCFEU { return &TCFEU{GppSection{sectionId: SectionIDEUTCFv2, sectionValue: section}} } @@ -92,25 +88,20 @@ func NewNotSupported(section string, sectionID int) *NotSupported { return &NotSupported{GppSection{sectionId: sectionID, sectionValue: section}} } -func (t TCFEU) ParseConsent() (GppParsedConsent, error) { - return ParseV2(t.sectionValue) +func (n *NotSupported) ParseConsent() (GppParsedConsent, error) { + return nil, errors.New(fmt.Sprintf("Section ID %d is not supported", n.sectionId)) } -func (t TCFCA) ParseConsent() (GppParsedConsent, error) { +func (t *TCFEU) ParseConsent() (GppParsedConsent, error) { return ParseV2(t.sectionValue) } -func (u USPV) ParseConsent() (GppParsedConsent, error) { - if valid, err := IsValidCCPAString(u.sectionValue); !valid { - return nil, err - } +func (t *TCFCA) ParseConsent() (GppParsedConsent, error) { + return ParseV2(t.sectionValue) +} - return &CcpaParsedConsent{ - int(u.sectionValue[0] - '0'), - u.sectionValue[1], - u.sectionValue[2], - u.sectionValue[3], - }, nil +func (u *USPV) ParseConsent() (GppParsedConsent, error) { + return ParseCCPA(u.sectionValue) } @@ -205,7 +196,7 @@ func (m *MspaUsVA) ParseConsent() (GppParsedConsent, error) { return p, r.Err } -func (m MspaUsCO) ParseConsent() (GppParsedConsent, error) { +func (m *MspaUsCO) ParseConsent() (GppParsedConsent, error) { var segments = strings.Split(m.sectionValue, ".") var b, err = base64.RawURLEncoding.DecodeString(segments[0]) @@ -245,7 +236,7 @@ func (m MspaUsCO) ParseConsent() (GppParsedConsent, error) { return p, r.Err } -func (m MspaUsUT) ParseConsent() (GppParsedConsent, error) { +func (m *MspaUsUT) ParseConsent() (GppParsedConsent, error) { var segments = strings.Split(m.sectionValue, ".") var b, err = base64.RawURLEncoding.DecodeString(segments[0]) @@ -285,7 +276,7 @@ func (m MspaUsUT) ParseConsent() (GppParsedConsent, error) { return p, r.Err } -func (m MspaUsCT) ParseConsent() (GppParsedConsent, error) { +func (m *MspaUsCT) ParseConsent() (GppParsedConsent, error) { var segments = strings.Split(m.sectionValue, ".") var b, err = base64.RawURLEncoding.DecodeString(segments[0]) @@ -326,7 +317,7 @@ func (m MspaUsCT) ParseConsent() (GppParsedConsent, error) { } -func (m MspaUsCA) ParseConsent() (GppParsedConsent, error) { +func (m *MspaUsCA) ParseConsent() (GppParsedConsent, error) { var segments = strings.Split(m.sectionValue, ".") var b, err = base64.RawURLEncoding.DecodeString(segments[0])