From 1f6975683c757e2b40c19ef53d0ffa767a096267 Mon Sep 17 00:00:00 2001 From: Sylvia Liu Date: Mon, 12 Jun 2023 09:59:42 -0400 Subject: [PATCH] add NotSupported type --- gpp_parsed_consent.go | 9 ++++++++- mspa_sections.go | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gpp_parsed_consent.go b/gpp_parsed_consent.go index bdec47e..9932c59 100644 --- a/gpp_parsed_consent.go +++ b/gpp_parsed_consent.go @@ -43,6 +43,7 @@ type GppSection struct { type GppSectionParser interface { ParseConsent() (GppParsedConsent, error) GetSectionId() int + GetSectionValue() string } // GetSectionId returns the Section ID for a given GppSection. @@ -50,6 +51,11 @@ func (g *GppSection) GetSectionId() int { return g.sectionId } +// GetSectionValue returns the Section Value for a given GppSection. +func (g *GppSection) GetSectionValue() string { + return g.sectionValue +} + type GppSubSection struct { // Global Privacy Control (GPC) is signaled and set. Gpc bool @@ -135,9 +141,10 @@ func MapGppSectionToParser(s string) ([]GppSectionParser, error) { gppSection = NewMspaUT(segments[i]) case SectionIDUSCT: gppSection = NewMspaCT(segments[i]) + default: + gppSection = NewNotSupported(segments[i], sid) } - // when the section id is not supported, append nullptr to indicate that this section is invalid gppSections = append(gppSections, gppSection) } return gppSections, nil diff --git a/mspa_sections.go b/mspa_sections.go index 61f01bf..a659a79 100644 --- a/mspa_sections.go +++ b/mspa_sections.go @@ -2,6 +2,7 @@ package iabconsent import ( "encoding/base64" + "fmt" "strings" "github.com/pkg/errors" @@ -43,6 +44,14 @@ type USPV struct { GppSection } +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}} } @@ -79,6 +88,10 @@ func NewMspaCT(section string) *MspaUsCT { return &MspaUsCT{GppSection{sectionId: SectionIDUSCT, sectionValue: section}} } +func NewNotSupported(section string, sectionID int) *NotSupported { + return &NotSupported{GppSection{sectionId: sectionID, sectionValue: section}} +} + func (t TCFEU) ParseConsent() (GppParsedConsent, error) { return ParseV2(t.sectionValue) }