Skip to content

Commit

Permalink
TCFv2.0 parsing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
azhukovta committed May 15, 2020
1 parent edef100 commit 42648ea
Show file tree
Hide file tree
Showing 13 changed files with 676 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# travel audience Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [https://contributor-covenant.org/version/1/4][version]

[homepage]: https://contributor-covenant.org
[version]: https://contributor-covenant.org/version/1/4/
38 changes: 38 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contributing

Thanks for choosing to contribute!

The following are a set of guidelines to follow when contributing to this project.

## Have A Question?

Start by filing an issue. The existing committers on this project work to reach
consensus around project direction and issue solutions within issue threads
(when appropriate).

## How to Contribute Code

1. Fork the repo, develop and test your code changes.
1. Submit a pull request.

Lastly, please follow the [pull request template](PULL_REQUEST_TEMPLATE.md) when
submitting a pull request!

#### Documentation PRs

Documentation PRs will follow the same lifecycle as other PRs. They should also be labeled with the
`docs` label. For documentation, special attention will be paid to spelling, grammar, and clarity
(whereas those things don't matter *as* much for comments in code).

<!-- ## Security Issues
Security issues shouldn't be reported on this issue tracker. Instead, please email a report to
[[email protected]](mailto:[email protected]). This will give
us a chance to try to fix the issue before it is exploited in the wild.
-->

## Code Of Conduct

This project adheres to the travel audience [code of conduct](CODE_OF_CONDUCT.md). By participating,
you are expected to uphold this code. Please report unacceptable behavior to
[[email protected]](mailto:[email protected]).
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--- STOP! Before you open an issue please search this repository's issues to see if it has already been reported. This helps reduce duplicate issues from being created. -->

### Expected Behaviour

### Actual Behaviour

### Steps to Reproduce


### Optional additional info:

#### Platform and Version

#### Sample Code that illustrates the problem

#### Logs taken while reproducing problem
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Thanks for sending a pull request! Here are some tips for you:
If this PR closes another issue, add 'closes #<issue number>' somewhere in the PR summary. GitHub will automatically close that issue when this PR gets merged. Alternatively, adding 'refs #<issue number>' will not close the issue, but help provide the reviewer more context.-->

**What this PR does / why we need it**:

**Special notes for your reviewer**:

**If applicable**:
- [ ] this PR contains documentation
- [ ] this PR contains unit tests
- [ ] this PR has been tested for backwards compatibility
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
vendor/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

© Copyright 2019 travel audience. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# go-iabtcf
A Golang implementation of the IAB Transparency and Consent String (TC String) v2.0

The TC String is a technical component of the IAB Europe Transparency & Consent Framework (TCF)

Library provides convenient way to check if:
- vendor is allowed
- purposes are allowed
- special fetures are allowed

## Getting Started

### Installing

go get -v github.com/travelaudience/go-iabtcf

### Example

package main

import (
"fmt"

"github.com/travelaudience/go-iabtcf"
)

func main() {
var s, err = iabtcf.ParseCoreString("COwIsAvOwIsAvBIAAAENAPCMAP_AAP_AAAAAFoQBQABAAGAAQAAwACQAAAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw")
if err != nil {
panic(err)
}
pa := s.EveryPurposeAllowed([]int{1})
sf := s.EverySpecialFeatureAllowed([]int{1})
va := s.VendorAllowed(1)
}

## Contributing

Contributions are welcomed! Read the [Contributing Guide](.github/CONTRIBUTING.md) for more information.

## Licensing

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
71 changes: 71 additions & 0 deletions consent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package iabtcf

import "time"

// Consent represents Core Consent extracted from an IAB Consent String v2.0
// It's implemented according to specification: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md
type Consent struct {
Version int
Created time.Time
LastUpdated time.Time
CMPID int
CMPVersion int
ConsentScreen int
ConsentLanguage string
VendorListVersion int
TcfPolicyVersion int
IsServiceSpecific bool
UseNonStandardStacks bool
SpecialFeatureOptIns map[int]bool
PurposesConsent map[int]bool
PurposesLITransparency map[int]bool
PurposeOneTreatment bool
PublisherCC string
MaxVendorID int
IsRangeEncoding bool
ConsentedVendors map[int]bool
NumEntries int
RangeEntries []*RangeEntry
}

// RangeEntry defines a range groups of Vendor IDs who have been disclosed to a user
type RangeEntry struct {
StartOrOnlyVendorId int
EndVendorID int
}

// EveryPurposeAllowed returns true if every purpose number is allowed in
// the ParsedConsent, otherwise false
func (p *Consent) EveryPurposeAllowed(ps []int) bool {
for _, rp := range ps {
if !p.PurposesConsent[rp] {
return false
}
}
return true
}

// EverySpecialFeatureAllowed returns true if every special feature number is allowed in
// the ParsedConsent, otherwise false
func (p *Consent) EverySpecialFeatureAllowed(ps []int) bool {
for _, rp := range ps {
if !p.SpecialFeatureOptIns[rp] {
return false
}
}
return true
}

// VendorAllowed checks if vendor is in the list of vendors user has given his consent to
func (p *Consent) VendorAllowed(v int) bool {
if p.IsRangeEncoding {
for _, e := range p.RangeEntries {
if e.StartOrOnlyVendorId <= v && v <= e.EndVendorID {
return true
}
}
return false
}

return p.ConsentedVendors[v]
}
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/travelaudience/go-iabtcf

go 1.13

require (
github.com/google/go-cmp v0.4.0
github.com/pkg/errors v0.9.1
github.com/rupertchen/go-bits v0.2.0
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rupertchen/go-bits v0.2.0 h1:B5+B70H4vWgwMppvo3wiYtwgN1j9m2nD9DJnnMqGcbQ=
github.com/rupertchen/go-bits v0.2.0/go.mod h1:V1n1fOC+mPsmLRcRQ5Esgi7CMdsPNeWNz4nVGm+DMJc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Loading

0 comments on commit 42648ea

Please sign in to comment.