Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add states montana texas and colorado. #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const (
SectionUSPCO SectionID = 10
SectionUSPUT SectionID = 11
SectionUSPCT SectionID = 12
SectionUSPTX SectionID = 16
SectionUSPOR SectionID = 15

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mentioned in the pull request title that Colorado is added but, files sections/uspor/uspor.go and sections/uspor/uspor_test.go as well as this constant's name, seem to hint that the two-letter state code refers to Oregon. Is the pull request title incorrect?

SectionUSPMT SectionID = 14
)

var SectionNamesByID = map[int]string{
Expand All @@ -24,4 +27,6 @@ var SectionNamesByID = map[int]string{
10: "uspco",
11: "usput",
12: "uspct",
16: "usptx",
15: "uspor",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an entry for Montana missing?

29       12: "uspct",
30       16: "usptx",
   +     14: "uspmt",
31       15: "uspor",
32   }
constants/constants.go

Also, can we sort in descending order?

}
167 changes: 167 additions & 0 deletions sections/uspmt/uspmt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package uspmt

import (
"github.com/prebid/go-gpp/constants"
"github.com/prebid/go-gpp/sections"
"github.com/prebid/go-gpp/util"
)

type USPMTCoreSegment struct {
Version byte
SharingNotice byte
SaleOptOutNotice byte
TargetedAdvertisingOptOutNotice byte
SaleOptOut byte
TargetedAdvertisingOptOut byte
SensitiveDataProcessing []byte
KnownChildSensitiveDataConsents []byte
AdditionalDataProcessingConsent byte
MspaCoveredTransaction byte
MspaOptOutOptionMode byte
MspaServiceProviderMode byte
}

func NewUSMTCoreSegment(bs *util.BitStream) (USPMTCoreSegment, error) {
var usmt USPMTCoreSegment
var err error

usmt.Version, err = bs.ReadByte6()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.Version", err)
}

usmt.SharingNotice, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.SharingNotice", err)
}

usmt.SaleOptOutNotice, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.SaleOptOutNotice", err)
}

usmt.TargetedAdvertisingOptOutNotice, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.TargetedAdvertisingOptOutNotice", err)
}

usmt.SaleOptOut, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.SaleOptOut", err)
}

usmt.TargetedAdvertisingOptOut, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.TargetedAdvertisingOptOut", err)
}

usmt.SensitiveDataProcessing, err = bs.ReadTwoBitField(8)
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.SensitiveDataProcessing", err)
}

usmt.KnownChildSensitiveDataConsents, err = bs.ReadTwoBitField(3)
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.KnownChildSensitiveDataConsentsArr", err)
}

usmt.AdditionalDataProcessingConsent, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.AdditionalDataProcessingConsent", err)
}

usmt.MspaCoveredTransaction, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.MspaCoveredTransaction", err)
}

usmt.MspaOptOutOptionMode, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.MspaOptOutOptionMode", err)
}

usmt.MspaServiceProviderMode, err = bs.ReadByte2()
if err != nil {
return usmt, sections.ErrorHelper("USMTSegment.MspaServiceProviderMode", err)
}

return usmt, nil
}

func (segment USPMTCoreSegment) Encode(bs *util.BitStream) {
bs.WriteByte6(segment.Version)
bs.WriteByte2(segment.SharingNotice)
bs.WriteByte2(segment.SaleOptOutNotice)
bs.WriteByte2(segment.TargetedAdvertisingOptOutNotice)
bs.WriteByte2(segment.SaleOptOut)
bs.WriteByte2(segment.TargetedAdvertisingOptOut)
bs.WriteTwoBitField(segment.SensitiveDataProcessing)
bs.WriteTwoBitField(segment.KnownChildSensitiveDataConsents)
bs.WriteByte2(segment.AdditionalDataProcessingConsent)
bs.WriteByte2(segment.MspaCoveredTransaction)
bs.WriteByte2(segment.MspaOptOutOptionMode)
bs.WriteByte2(segment.MspaServiceProviderMode)
}

type USPMT struct {
SectionID constants.SectionID
Value string
CoreSegment USPMTCoreSegment
GPCSegment sections.CommonUSGPCSegment
}

func NewUSPMT(encoded string) (USPMT, error) {
uspmt := USPMT{}

coreBitStream, gpcBitStream, err := sections.CreateBitStreams(encoded, true)
if err != nil {
return uspmt, err
}

coreSegment, err := NewUSMTCoreSegment(coreBitStream)
if err != nil {
return uspmt, err
}

gpcSegment := sections.CommonUSGPCSegment{
SubsectionType: 1,
Gpc: false,
}

if gpcBitStream != nil {
gpcSegment, err = sections.NewCommonUSGPCSegment(gpcBitStream)
if err != nil {
return uspmt, err
}
}

uspmt = USPMT{
SectionID: constants.SectionUSPMT,
Value: encoded,
CoreSegment: coreSegment,
GPCSegment: gpcSegment,
}

return uspmt, nil
}

func (uspmt USPMT) Encode(gpcIncluded bool) []byte {
bs := util.NewBitStreamForWrite()
uspmt.CoreSegment.Encode(bs)
res := bs.Base64Encode()
if !gpcIncluded {
return res
}
bs.Reset()
res = append(res, '.')
uspmt.GPCSegment.Encode(bs)
return append(res, bs.Base64Encode()...)
}

func (uspmt USPMT) GetID() constants.SectionID {
return uspmt.SectionID
}

func (uspmt USPMT) GetValue() string {
return uspmt.Value
}
62 changes: 62 additions & 0 deletions sections/uspmt/uspmt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package uspmt

import (
"testing"

"github.com/prebid/go-gpp/constants"
"github.com/prebid/go-gpp/sections"
"github.com/stretchr/testify/assert"
)

type uspmtTestData struct {
description string
gppString string
expected USPMT
}

func TestUSPCO(t *testing.T) {
testData := []uspmtTestData{
{
description: "should populate USPMT segments correctly",
gppString: "bSFgmAGU.YA",
/*
011011 01 00 10 00 01 0110000010011000 000000 01 10 01 01 01 1 1110
*/
expected: USPMT{
CoreSegment: USPMTCoreSegment{
Version: 27,
SharingNotice: 1,
SaleOptOutNotice: 0,
TargetedAdvertisingOptOutNotice: 2,
SaleOptOut: 0,
TargetedAdvertisingOptOut: 1,
SensitiveDataProcessing: []byte{
1, 2, 0, 0, 2, 1, 2, 0,
},
KnownChildSensitiveDataConsents: []byte{0, 0, 0},
AdditionalDataProcessingConsent: 1,
MspaCoveredTransaction: 2,
MspaOptOutOptionMode: 1,
MspaServiceProviderMode: 1,
},
GPCSegment: sections.CommonUSGPCSegment{
SubsectionType: 1,
Gpc: true,
},
SectionID: constants.SectionUSPMT,
Value: "bSFgmAGU.YA",
},
},
}

for _, test := range testData {
result, err := NewUSPMT(test.gppString)
encodedString := string(test.expected.Encode(true))

assert.Nil(t, err)
assert.Equal(t, test.expected, result)
assert.Equal(t, constants.SectionUSPMT, result.GetID())
assert.Equal(t, test.gppString, result.GetValue())
assert.Equal(t, test.gppString, encodedString)
}
}
Loading