add go mod & rename package

This commit is contained in:
Rémi Demol
2020-04-03 17:50:40 +02:00
parent a95d955c6a
commit 121b974622
12 changed files with 46 additions and 45 deletions

2
.gitignore vendored
View File

@@ -13,3 +13,5 @@
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ # vendor/
.idea

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
type Bits struct { type Bits struct {
position uint position uint

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
import ( import (
"encoding/base64" "encoding/base64"
@@ -31,7 +31,7 @@ func Decode(s string) (t *TCData, err error) {
t.AllowedVendors = segment t.AllowedVendors = segment
} }
} else if segmentType == 3 { } else if segmentType == 3 {
segment, err := DecodePubllisherTC(v) segment, err := DecodePublisherTC(v)
if err == nil { if err == nil {
t.PublisherTC = segment t.PublisherTC = segment
} }
@@ -165,14 +165,13 @@ func DecodeAllowedVendors(s string) (a *AllowedVendors, err error) {
} }
if a.SegmentType != 2 { if a.SegmentType != 2 {
err = fmt.Errorf("allowed vendors segment type must be 2") return nil, fmt.Errorf("allowed vendors segment type must be 2")
return nil, err
} }
return a, nil return a, nil
} }
func DecodePubllisherTC(s string) (p *PublisherTC, err error) { func DecodePublisherTC(s string) (p *PublisherTC, err error) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
err = fmt.Errorf("%v", r) err = fmt.Errorf("%v", r)
@@ -195,8 +194,7 @@ func DecodePubllisherTC(s string) (p *PublisherTC, err error) {
p.CustomPurposesLITransparency = e.readBitField(uint(p.NumCustomPurposes)) p.CustomPurposesLITransparency = e.readBitField(uint(p.NumCustomPurposes))
if p.SegmentType != 3 { if p.SegmentType != 3 {
err = fmt.Errorf("allowed vendors segment type must be 3") return nil, fmt.Errorf("allowed vendors segment type must be 3")
return nil, err
} }
return p, nil return p, nil

View File

@@ -1,14 +1,13 @@
package iabtcf_test package iabtcfv2
import ( import (
iabtcf "github.com/SirDataFR/iab-tcf-v2"
"testing" "testing"
) )
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
str := "COxR03kOxR1CqBcABCENAgCMAP_AAH_AAAqIF3EXySoGY2thI2YVFxBEIYwfJxyigMgChgQIsSwNQIeFLBoGLiAAHBGYJAQAGBAEEACBAQIkHGBMCQAAgAgBiRCMQEGMCzNIBIBAggEbY0FACCVmHkHSmZCY7064O__QLuIJEFQMAkSBAIACLECIQwAQDiAAAYAlAAABAhIaAAgIWBQEeAAAACAwAAgAAABBAAACAAQAAICIAAABAAAgAiAQAAAAGgIQAACBABACRIAAAEANCAAgiCEAQg4EAo4AAA.IF3EXySoGY2tho2YVFzBEIYwfJxyigMgShgQIsS0NQIeFLBoGPiAAHBGYJAQAGBAkkACBAQIsHGBMCQABgAgRiRCMQEGMDzNIBIBAggkbY0FACCVmnkHS3ZCY70-6u__QA.elAAAAAAAWA" str := "COxR03kOxR1CqBcABCENAgCMAP_AAH_AAAqIF3EXySoGY2thI2YVFxBEIYwfJxyigMgChgQIsSwNQIeFLBoGLiAAHBGYJAQAGBAEEACBAQIkHGBMCQAAgAgBiRCMQEGMCzNIBIBAggEbY0FACCVmHkHSmZCY7064O__QLuIJEFQMAkSBAIACLECIQwAQDiAAAYAlAAABAhIaAAgIWBQEeAAAACAwAAgAAABBAAACAAQAAICIAAABAAAgAiAQAAAAGgIQAACBABACRIAAAEANCAAgiCEAQg4EAo4AAA.IF3EXySoGY2tho2YVFzBEIYwfJxyigMgShgQIsS0NQIeFLBoGPiAAHBGYJAQAGBAkkACBAQIsHGBMCQABgAgRiRCMQEGMDzNIBIBAggkbY0FACCVmnkHS3ZCY70-6u__QA.elAAAAAAAWA"
data, err := iabtcf.Decode(str) data, err := Decode(str)
if err != nil { if err != nil {
t.Errorf("TC String should be decoded without error: %s", err) t.Errorf("TC String should be decoded without error: %s", err)
return return
@@ -28,7 +27,7 @@ func TestDecode(t *testing.T) {
func TestDecodeInvalid(t *testing.T) { func TestDecodeInvalid(t *testing.T) {
str := "IF3EXySoGY2tho2YVFzBEIYwfJxyigMgShgQIsS0NQIeFLBoGPiAAHBGYJAQAGBAkkACBAQIsHGBMCQABgAgRiRCMQEGMDzNIBIBAggkbY0FACCVmnkHS3ZCY70-6u__QA.elAAAAAAAWA" str := "IF3EXySoGY2tho2YVFzBEIYwfJxyigMgShgQIsS0NQIeFLBoGPiAAHBGYJAQAGBAkkACBAQIsHGBMCQABgAgRiRCMQEGMDzNIBIBAggkbY0FACCVmnkHS3ZCY70-6u__QA.elAAAAAAAWA"
_, err := iabtcf.Decode(str) _, err := Decode(str)
if err == nil { if err == nil {
t.Errorf("TC String should not be decoded: %s", err) t.Errorf("TC String should not be decoded: %s", err)
return return
@@ -38,12 +37,12 @@ func TestDecodeInvalid(t *testing.T) {
func TestDecodeCoreString(t *testing.T) { func TestDecodeCoreString(t *testing.T) {
str := "COxR03kOxR1CqBcABCENAgCMAP_AAH_AAAqIF3EXySoGY2thI2YVFxBEIYwfJxyigMgChgQIsSwNQIeFLBoGLiAAHBGYJAQAGBAEEACBAQIkHGBMCQAAgAgBiRCMQEGMCzNIBIBAggEbY0FACCVmHkHSmZCY7064O__QLuIJEFQMAkSBAIACLECIQwAQDiAAAYAlAAABAhIaAAgIWBQEeAAAACAwAAgAAABBAAACAAQAAICIAAABAAAgAiAQAAAAGgIQAACBABACRIAAAEANCAAgiCEAQg4EAo4AAA" str := "COxR03kOxR1CqBcABCENAgCMAP_AAH_AAAqIF3EXySoGY2thI2YVFxBEIYwfJxyigMgChgQIsSwNQIeFLBoGLiAAHBGYJAQAGBAEEACBAQIkHGBMCQAAgAgBiRCMQEGMCzNIBIBAggEbY0FACCVmHkHSmZCY7064O__QLuIJEFQMAkSBAIACLECIQwAQDiAAAYAlAAABAhIaAAgIWBQEeAAAACAwAAgAAABBAAACAAQAAICIAAABAAAgAiAQAAAAGgIQAACBABACRIAAAEANCAAgiCEAQg4EAo4AAA"
if iabtcf.DecodeSegmentType(str) != 0 { if DecodeSegmentType(str) != 0 {
t.Errorf("Segment type should be 0") t.Errorf("Segment type should be 0")
return return
} }
segment, err := iabtcf.DecodeCoreString(str) segment, err := DecodeCoreString(str)
if err != nil { if err != nil {
t.Errorf("Segment should be decoded without error: %s", err) t.Errorf("Segment should be decoded without error: %s", err)
return return
@@ -63,12 +62,12 @@ func TestDecodeCoreString(t *testing.T) {
func TestDecodeDisclosedVendors(t *testing.T) { func TestDecodeDisclosedVendors(t *testing.T) {
str := "IF3EXySoGY2tho2YVFzBEIYwfJxyigMgShgQIsS0NQIeFLBoGPiAAHBGYJAQAGBAkkACBAQIsHGBMCQABgAgRiRCMQEGMDzNIBIBAggkbY0FACCVmnkHS3ZCY70-6u__QA" str := "IF3EXySoGY2tho2YVFzBEIYwfJxyigMgShgQIsS0NQIeFLBoGPiAAHBGYJAQAGBAkkACBAQIsHGBMCQABgAgRiRCMQEGMDzNIBIBAggkbY0FACCVmnkHS3ZCY70-6u__QA"
if iabtcf.DecodeSegmentType(str) != 1 { if DecodeSegmentType(str) != 1 {
t.Errorf("Segment type should be 1") t.Errorf("Segment type should be 1")
return return
} }
segment, err := iabtcf.DecodeDisclosedVendors(str) segment, err := DecodeDisclosedVendors(str)
if err != nil { if err != nil {
t.Errorf("Segment should be decoded without error: %s", err) t.Errorf("Segment should be decoded without error: %s", err)
return return
@@ -98,12 +97,12 @@ func TestDecodeDisclosedVendors(t *testing.T) {
func TestDecodeAllowedVendors(t *testing.T) { func TestDecodeAllowedVendors(t *testing.T) {
str := "QF3QAgABAA1A" str := "QF3QAgABAA1A"
if iabtcf.DecodeSegmentType(str) != 2 { if DecodeSegmentType(str) != 2 {
t.Errorf("Segment type should be 2") t.Errorf("Segment type should be 2")
return return
} }
segment, err := iabtcf.DecodeAllowedVendors(str) segment, err := DecodeAllowedVendors(str)
if err != nil { if err != nil {
t.Errorf("Segment should be decoded without error: %s", err) t.Errorf("Segment should be decoded without error: %s", err)
return return
@@ -133,12 +132,12 @@ func TestDecodeAllowedVendors(t *testing.T) {
func TestDecodePublisherTC(t *testing.T) { func TestDecodePublisherTC(t *testing.T) {
str := "elAAAAAAAWA" str := "elAAAAAAAWA"
if iabtcf.DecodeSegmentType(str) != 3 { if DecodeSegmentType(str) != 3 {
t.Errorf("Segment type should be 3") t.Errorf("Segment type should be 3")
return return
} }
segment, err := iabtcf.DecodePubllisherTC(str) segment, err := DecodePublisherTC(str)
if err != nil { if err != nil {
t.Errorf("Segment should be decoded without error: %s", err) t.Errorf("Segment should be decoded without error: %s", err)
return return

View File

@@ -1,15 +1,14 @@
package iabtcf_test package iabtcfv2
import ( import (
iabtcf "github.com/SirDataFR/iab-tcf-v2"
"testing" "testing"
"time" "time"
) )
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
str := "COxSKBCOxSKCCBcABCENAgCMAPzAAEPAAAqIDaQBQAMgAgABqAR0A2gDaQAwAMgAgANoAAA.IDaQBQAMgAgABqAR0A2g.QF3QAgABAA1A.eEAAAAAAAUA" str := "COxSKBCOxSKCCBcABCENAgCMAPzAAEPAAAqIDaQBQAMgAgABqAR0A2gDaQAwAMgAgANoAAA.IDaQBQAMgAgABqAR0A2g.QF3QAgABAA1A.eEAAAAAAAUA"
data := &iabtcf.TCData{ data := &TCData{
CoreString: &iabtcf.CoreString{ CoreString: &CoreString{
Version: 2, Version: 2,
Created: timeFromDeciSeconds(15859228738), Created: timeFromDeciSeconds(15859228738),
LastUpdated: timeFromDeciSeconds(15859228802), LastUpdated: timeFromDeciSeconds(15859228802),
@@ -48,7 +47,7 @@ func TestEncode(t *testing.T) {
IsRangeEncoding: true, IsRangeEncoding: true,
VendorsConsent: map[int]bool{}, VendorsConsent: map[int]bool{},
NumEntries: 5, NumEntries: 5,
RangeEntries: []*iabtcf.RangeEntry{ RangeEntries: []*RangeEntry{
{ {
StartVendorID: 25, StartVendorID: 25,
EndVendorID: 25, EndVendorID: 25,
@@ -74,7 +73,7 @@ func TestEncode(t *testing.T) {
IsRangeEncodingLI: true, IsRangeEncodingLI: true,
VendorsLITransparency: map[int]bool{}, VendorsLITransparency: map[int]bool{},
NumEntriesLI: 3, NumEntriesLI: 3,
RangeEntriesLI: []*iabtcf.RangeEntry{ RangeEntriesLI: []*RangeEntry{
{ {
StartVendorID: 25, StartVendorID: 25,
EndVendorID: 25, EndVendorID: 25,
@@ -90,12 +89,12 @@ func TestEncode(t *testing.T) {
}, },
NumPubRestrictions: 0, NumPubRestrictions: 0,
}, },
DisclosedVendors: &iabtcf.DisclosedVendors{ DisclosedVendors: &DisclosedVendors{
SegmentType: 1, SegmentType: 1,
MaxVendorId: 436, MaxVendorId: 436,
IsRangeEncoding: true, IsRangeEncoding: true,
NumEntries: 5, NumEntries: 5,
RangeEntries: []*iabtcf.RangeEntry{ RangeEntries: []*RangeEntry{
{ {
StartVendorID: 25, StartVendorID: 25,
EndVendorID: 25, EndVendorID: 25,
@@ -118,12 +117,12 @@ func TestEncode(t *testing.T) {
}, },
}, },
}, },
AllowedVendors: &iabtcf.AllowedVendors{ AllowedVendors: &AllowedVendors{
SegmentType: 2, SegmentType: 2,
MaxVendorId: 750, MaxVendorId: 750,
IsRangeEncoding: true, IsRangeEncoding: true,
NumEntries: 2, NumEntries: 2,
RangeEntries: []*iabtcf.RangeEntry{ RangeEntries: []*RangeEntry{
{ {
StartVendorID: 2, StartVendorID: 2,
EndVendorID: 2, EndVendorID: 2,
@@ -134,7 +133,7 @@ func TestEncode(t *testing.T) {
}, },
}, },
}, },
PublisherTC: &iabtcf.PublisherTC{ PublisherTC: &PublisherTC{
SegmentType: 3, SegmentType: 3,
PubPurposesConsent: map[int]bool{ PubPurposesConsent: map[int]bool{
1: true, 1: true,
@@ -158,7 +157,7 @@ func TestEncode(t *testing.T) {
} }
func TestEncodeCoreString(t *testing.T) { func TestEncodeCoreString(t *testing.T) {
str := "COxSKBCOxSKCCBcABCENAgCMAPzAAEPAAAqIDaQBQAMgAgABqAR0A2gDaQAwAMgAgANoAAA" str := "COxSKBCOxSKCCBcABCENAgCMAPzAAEPAAAqIDaQBQAMgAgABqAR0A2gDaQAwAMgAgANoAAA"
segment := &iabtcf.CoreString{ segment := &CoreString{
Version: 2, Version: 2,
Created: timeFromDeciSeconds(15859228738), Created: timeFromDeciSeconds(15859228738),
LastUpdated: timeFromDeciSeconds(15859228802), LastUpdated: timeFromDeciSeconds(15859228802),
@@ -197,7 +196,7 @@ func TestEncodeCoreString(t *testing.T) {
IsRangeEncoding: true, IsRangeEncoding: true,
VendorsConsent: map[int]bool{}, VendorsConsent: map[int]bool{},
NumEntries: 5, NumEntries: 5,
RangeEntries: []*iabtcf.RangeEntry{ RangeEntries: []*RangeEntry{
{ {
StartVendorID: 25, StartVendorID: 25,
EndVendorID: 25, EndVendorID: 25,
@@ -223,7 +222,7 @@ func TestEncodeCoreString(t *testing.T) {
IsRangeEncodingLI: true, IsRangeEncodingLI: true,
VendorsLITransparency: map[int]bool{}, VendorsLITransparency: map[int]bool{},
NumEntriesLI: 3, NumEntriesLI: 3,
RangeEntriesLI: []*iabtcf.RangeEntry{ RangeEntriesLI: []*RangeEntry{
{ {
StartVendorID: 25, StartVendorID: 25,
EndVendorID: 25, EndVendorID: 25,
@@ -248,12 +247,12 @@ func TestEncodeCoreString(t *testing.T) {
func TestEncodeDisclosedVendors(t *testing.T) { func TestEncodeDisclosedVendors(t *testing.T) {
str := "IDaQBQAMgAgABqAR0A2g" str := "IDaQBQAMgAgABqAR0A2g"
segment := &iabtcf.DisclosedVendors{ segment := &DisclosedVendors{
SegmentType: 1, SegmentType: 1,
MaxVendorId: 436, MaxVendorId: 436,
IsRangeEncoding: true, IsRangeEncoding: true,
NumEntries: 5, NumEntries: 5,
RangeEntries: []*iabtcf.RangeEntry{ RangeEntries: []*RangeEntry{
{ {
StartVendorID: 25, StartVendorID: 25,
EndVendorID: 25, EndVendorID: 25,
@@ -285,12 +284,12 @@ func TestEncodeDisclosedVendors(t *testing.T) {
func TestEncodeAllowedVendors(t *testing.T) { func TestEncodeAllowedVendors(t *testing.T) {
str := "QF3QAgABAA1A" str := "QF3QAgABAA1A"
segment := &iabtcf.AllowedVendors{ segment := &AllowedVendors{
SegmentType: 2, SegmentType: 2,
MaxVendorId: 750, MaxVendorId: 750,
IsRangeEncoding: true, IsRangeEncoding: true,
NumEntries: 2, NumEntries: 2,
RangeEntries: []*iabtcf.RangeEntry{ RangeEntries: []*RangeEntry{
{ {
StartVendorID: 2, StartVendorID: 2,
EndVendorID: 2, EndVendorID: 2,
@@ -310,7 +309,7 @@ func TestEncodeAllowedVendors(t *testing.T) {
func TestEncodePublisherTC(t *testing.T) { func TestEncodePublisherTC(t *testing.T) {
str := "eEAAAAAAAUA" str := "eEAAAAAAAUA"
segment := &iabtcf.PublisherTC{ segment := &PublisherTC{
SegmentType: 3, SegmentType: 3,
PubPurposesConsent: map[int]bool{ PubPurposesConsent: map[int]bool{
1: true, 1: true,

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/SirDataFR/iab-tcf-v2
go 1.13

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
import ( import (
"encoding/base64" "encoding/base64"

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
import ( import (
"encoding/base64" "encoding/base64"

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
import ( import (
"encoding/base64" "encoding/base64"

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
import "encoding/base64" import "encoding/base64"

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
import "strings" import "strings"

View File

@@ -1,4 +1,4 @@
package iabtcf package iabtcfv2
import ( import (
"time" "time"