Java implementation of the Transparency and Consent Framework 2.0
The library is intended to parse the binary block format of the TCF 2.0 consent string, as documented here:
The parser and structured Java classes are auto-generated with Kaitai Struct (https://kaitai.io/).
The consent string has been fully specified using the Kaitai Struct language, found in the .ksy files under src/main/resources
.
The library is also compatible with TCF version 1.1.
import com.audienceproject.gdpr.TCString;
import com.audienceproject.gdpr.struct.CoreString;
String consentString = "COwaAK3OwaAK3GKAAAENAcCAAAAAAAAAAAAAAAAAAAAA.IF0EWSQgAYWwho0QUBzBAIYAfJgSCAMgSAAQIoCkFQICERBAEKiAQHAEQJAAAGBAAkACAAQAoHCBMCQABgAARiRCEQECIDRNABIBAggAKYQFAAARmikHC3ZCY702yOmQ.YAAAAAAAAAAAAAAAAAA";
TCString tcString = TCString.parse(consentString);
CoreString coreString = tcString.getCoreString();
if (coreString.version() == 1) {
CoreString.CoreStringV1 coreStringV1 = coreString.coreStringV1();
// Version 1 logic.
} else if (coreString.version() == 2) {
CoreString.CoreStringV2 coreStringV2 = coreString.coreStringV2();
// Version 2 logic.
}
If a bug is found in the implementation or the format changes, simply edit the .ksy file and run the Kaitai Struct compiler to generate new classes.
kaitai-struct-compiler -t java --java-package com.audienceproject.gdpr.struct src/main/resources/tcf_core.ksy
kaitai-struct-compiler -t java --java-package com.audienceproject.gdpr.struct src/main/resources/tcf_publisher.ksy
kaitai-struct-compiler -t java --java-package com.audienceproject.gdpr.struct src/main/resources/tcf_vendor.ksy