Skip to content
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
46 changes: 34 additions & 12 deletions Consent String SDK Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
objects = {

/* Begin PBXBuildFile section */
0B3E03CE22A0206C0078D316 /* ConsentStringBuilding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3E03CD22A0206C0078D316 /* ConsentStringBuilding.swift */; };
0B8FBC7222954495002F733D /* NSRange+ConsentString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B8FBC7122954495002F733D /* NSRange+ConsentString.swift */; };
0B8FBC76229558F3002F733D /* VendorIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B8FBC75229558F3002F733D /* VendorIdentifier.swift */; };
0BA327D3228EA54A00606697 /* ConsentStringBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA327D2228EA54A00606697 /* ConsentStringBuilder.swift */; };
0BA327D5228EC1A300606697 /* Purpose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA327D4228EC1A300606697 /* Purpose.swift */; };
0BA327D9228EC84900606697 /* ConsentStringBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA327D8228EC84900606697 /* ConsentStringBuilderTests.swift */; };
0BA327DB228ED14600606697 /* VendorEncodingType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA327DA228ED14600606697 /* VendorEncodingType.swift */; };
0BAECEE12292B9A000CC4DDB /* BinaryStringTestSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BAECEE02292B9A000CC4DDB /* BinaryStringTestSupport.swift */; };
F142B52A2093A1C5001ABE60 /* Consent_String_SDK_Swift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F142B5202093A1C5001ABE60 /* Consent_String_SDK_Swift.framework */; };
F142B52F2093A1C5001ABE60 /* Consent_String_SDK_SwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B52E2093A1C5001ABE60 /* Consent_String_SDK_SwiftTests.swift */; };
F142B5312093A1C5001ABE60 /* Consent_String_SDK_Swift.h in Headers */ = {isa = PBXBuildFile; fileRef = F142B5232093A1C5001ABE60 /* Consent_String_SDK_Swift.h */; settings = {ATTRIBUTES = (Public, ); }; };
F142B53F2093A207001ABE60 /* ConsentString.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53A2093A206001ABE60 /* ConsentString.swift */; };
F142B5402093A207001ABE60 /* ConsentString.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53A2093A206001ABE60 /* ConsentString.swift */; };
F142B5412093A207001ABE60 /* ConsentStringError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53B2093A206001ABE60 /* ConsentStringError.swift */; };
F142B5422093A207001ABE60 /* ConsentStringError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53B2093A206001ABE60 /* ConsentStringError.swift */; };
F142B5432093A207001ABE60 /* ConsentStringProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53C2093A206001ABE60 /* ConsentStringProtocol.swift */; };
F142B5442093A207001ABE60 /* ConsentStringProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53C2093A206001ABE60 /* ConsentStringProtocol.swift */; };
F142B5452093A207001ABE60 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53D2093A207001ABE60 /* String.swift */; };
F142B5462093A207001ABE60 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53D2093A207001ABE60 /* String.swift */; };
F142B5472093A207001ABE60 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53E2093A207001ABE60 /* Data.swift */; };
F142B5482093A207001ABE60 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = F142B53E2093A207001ABE60 /* Data.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -33,6 +36,14 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0B3E03CD22A0206C0078D316 /* ConsentStringBuilding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsentStringBuilding.swift; sourceTree = "<group>"; };
0B8FBC7122954495002F733D /* NSRange+ConsentString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSRange+ConsentString.swift"; sourceTree = "<group>"; };
0B8FBC75229558F3002F733D /* VendorIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VendorIdentifier.swift; sourceTree = "<group>"; };
0BA327D2228EA54A00606697 /* ConsentStringBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsentStringBuilder.swift; sourceTree = "<group>"; };
0BA327D4228EC1A300606697 /* Purpose.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Purpose.swift; sourceTree = "<group>"; };
0BA327D8228EC84900606697 /* ConsentStringBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsentStringBuilderTests.swift; sourceTree = "<group>"; };
0BA327DA228ED14600606697 /* VendorEncodingType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VendorEncodingType.swift; sourceTree = "<group>"; };
0BAECEE02292B9A000CC4DDB /* BinaryStringTestSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryStringTestSupport.swift; sourceTree = "<group>"; };
F142B5202093A1C5001ABE60 /* Consent_String_SDK_Swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Consent_String_SDK_Swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F142B5232093A1C5001ABE60 /* Consent_String_SDK_Swift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Consent_String_SDK_Swift.h; sourceTree = "<group>"; };
F142B5242093A1C5001ABE60 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -93,6 +104,12 @@
F142B53D2093A207001ABE60 /* String.swift */,
F142B5232093A1C5001ABE60 /* Consent_String_SDK_Swift.h */,
F142B5242093A1C5001ABE60 /* Info.plist */,
0BA327D2228EA54A00606697 /* ConsentStringBuilder.swift */,
0B3E03CD22A0206C0078D316 /* ConsentStringBuilding.swift */,
0BA327D4228EC1A300606697 /* Purpose.swift */,
0B8FBC75229558F3002F733D /* VendorIdentifier.swift */,
0B8FBC7122954495002F733D /* NSRange+ConsentString.swift */,
0BA327DA228ED14600606697 /* VendorEncodingType.swift */,
);
path = "Consent String SDK Swift";
sourceTree = "<group>";
Expand All @@ -101,6 +118,8 @@
isa = PBXGroup;
children = (
F142B52E2093A1C5001ABE60 /* Consent_String_SDK_SwiftTests.swift */,
0BA327D8228EC84900606697 /* ConsentStringBuilderTests.swift */,
0BAECEE02292B9A000CC4DDB /* BinaryStringTestSupport.swift */,
F142B5302093A1C5001ABE60 /* Info.plist */,
);
path = "Consent String SDK SwiftTests";
Expand Down Expand Up @@ -216,10 +235,16 @@
buildActionMask = 2147483647;
files = (
F142B5432093A207001ABE60 /* ConsentStringProtocol.swift in Sources */,
0BA327D5228EC1A300606697 /* Purpose.swift in Sources */,
0B8FBC76229558F3002F733D /* VendorIdentifier.swift in Sources */,
0BA327D3228EA54A00606697 /* ConsentStringBuilder.swift in Sources */,
0BA327DB228ED14600606697 /* VendorEncodingType.swift in Sources */,
0B8FBC7222954495002F733D /* NSRange+ConsentString.swift in Sources */,
F142B5472093A207001ABE60 /* Data.swift in Sources */,
F142B5412093A207001ABE60 /* ConsentStringError.swift in Sources */,
F142B5452093A207001ABE60 /* String.swift in Sources */,
F142B53F2093A207001ABE60 /* ConsentString.swift in Sources */,
0B3E03CE22A0206C0078D316 /* ConsentStringBuilding.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -228,11 +253,8 @@
buildActionMask = 2147483647;
files = (
F142B52F2093A1C5001ABE60 /* Consent_String_SDK_SwiftTests.swift in Sources */,
F142B5482093A207001ABE60 /* Data.swift in Sources */,
F142B5442093A207001ABE60 /* ConsentStringProtocol.swift in Sources */,
F142B5462093A207001ABE60 /* String.swift in Sources */,
F142B5422093A207001ABE60 /* ConsentStringError.swift in Sources */,
F142B5402093A207001ABE60 /* ConsentString.swift in Sources */,
0BAECEE12292B9A000CC4DDB /* BinaryStringTestSupport.swift in Sources */,
0BA327D9228EC84900606697 /* ConsentStringBuilderTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -299,7 +321,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -356,7 +378,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
64 changes: 33 additions & 31 deletions Consent String SDK Swift/ConsentString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

import Foundation

class ConsentString:ConsentStringProtocol {

public class ConsentString: ConsentStringProtocol {

static let bitFieldVendorStart: Int = 173
static let rangeEntryOffset: Int = 186
static let vendorIdentifierSize: Int = 16

/**
The current Consent String. Setting will allow replacement of the curr
*/
Expand Down Expand Up @@ -41,30 +45,26 @@ class ConsentString:ConsentStringProtocol {
}
consentData = dataValue
}



public var cmpId: Int {
return Int(consentData.intValue(fromBit: 78, toBit: 89))
return Int(consentData.intValue(for: .cmpIdentifier))
}

public var consentScreen: Int {
return Int(consentData.intValue(fromBit: 102, toBit: 107))
return Int(consentData.intValue(for: .consentScreen))
}

public var consentLanguage: String {
var data = consentData.data(fromBit: 108, toBit: 119)
var data = consentData.data(for: .consentLanguage)
data.insert(0, at: 0)
let string = data.base64EncodedString()
return String(string[string.index(string.startIndex, offsetBy: 2)...])
}

let purposesStart:Int64 = 132
let maxPurposes:Int64 = 24

public var purposesAllowed: [Int8] {
var resultsArray = [Int8]()
for purposeId in 1...maxPurposes {
let purposeBit = purposesStart - 1 + Int64(purposeId)
for purposeId in 1...NSRange.purposes.length {
let purposeBit = Int64(NSRange.purposes.lowerBound - 1 + purposeId)
let value = Int(consentData.intValue(fromBit: purposeBit, toBit: purposeBit))
if value > 0 {
resultsArray.append(Int8(purposeId))
Expand All @@ -73,29 +73,32 @@ class ConsentString:ConsentStringProtocol {
return resultsArray
}


public func purposeAllowed(forPurposeId purposeId: Int8) -> Bool {
if purposeId > 24 || purposeId < 1 {
if purposeId > NSRange.purposes.length || purposeId < 1 {
return false
}
let purposeBit = purposesStart - 1 + Int64(purposeId)
let purposeBit = Int64(NSRange.purposes.lowerBound) - 1 + Int64(purposeId)
let value = Int(consentData.intValue(fromBit: purposeBit, toBit: purposeBit))
if value > 0 {
return true
}
return false
}

public var vendorListVersion: Int {
return Int(consentData.intValue(for: .vendorListVersion))
}

//Used to determine whether we need to check for a vendor ID at all if it's greater than this value
private var maxVendorId : Int {
public var maxVendorId : Int {
get {
return Int(consentData.intValue(fromBit: 156, toBit: 171))
return Int(consentData.intValue(for: .maxVendorIdentifier))
}
}

private var isBitField:Bool {
get {
let value = consentData.intValue(fromBit: 172, toBit: 172)
let value = consentData.intValue(for: .encodingType)
return value == 0
}
}
Expand All @@ -105,16 +108,14 @@ class ConsentString:ConsentStringProtocol {
return !isBitField
}
}

private let bitFieldVendorStart:Int64 = 173
private let rangeDefaultConsent:Int64 = 173



public func isVendorAllowed(vendorId: Int) -> Bool {
if vendorId > maxVendorId {
return false
}
if isBitField {
let vendorBitField = bitFieldVendorStart + Int64(vendorId) - 1
let vendorBitField = Int64(ConsentString.bitFieldVendorStart + vendorId - 1)
//not enough bits
guard vendorBitField < consentData.count * 8 else {
return false
Expand All @@ -127,24 +128,25 @@ class ConsentString:ConsentStringProtocol {
}
} else {
let consentDataMaxBit = consentData.count * 8 - 1 //1 byte, last bit is 7, for 2 bytes, last is 15 etc...
let defaultConsent = consentData.intValue(fromBit: rangeDefaultConsent, toBit: rangeDefaultConsent)
let numEntries = Int(consentData.intValue(fromBit: 174, toBit: 185))
var rangeStart = Int64(186)
let defaultConsent = consentData.intValue(for: .defaultConsent)
let numEntries = Int(consentData.intValue(for: .numberOfEntries))
let vendorIdentifierSize = Int64(ConsentString.vendorIdentifierSize)
var rangeStart = Int64(ConsentString.rangeEntryOffset)
for _ in 0..<numEntries {
let entryType = consentData.intValue(fromBit: rangeStart, toBit: rangeStart)
if consentDataMaxBit < rangeStart + 16 + 1 + (entryType * 16) {//typebit + either 16 or 32
if consentDataMaxBit < rangeStart + vendorIdentifierSize + 1 + (entryType * vendorIdentifierSize) {//typebit + either 16 or 32
break
}
if entryType == 0 {//single
let thisVendorId = consentData.intValue(fromBit: rangeStart + 1, toBit: rangeStart + 16)
let thisVendorId = consentData.intValue(fromBit: rangeStart + 1, toBit: rangeStart + vendorIdentifierSize)
if vendorId == thisVendorId {
//if vendorId matches this one, then return opposite of default consent
return defaultConsent == 1 ? false : true
}
rangeStart += 17
} else if entryType == 1 {//range
let vendorStart = consentData.intValue(fromBit: rangeStart + 1, toBit: rangeStart + 16)
let vendorFinish = consentData.intValue(fromBit: rangeStart + 18, toBit: rangeStart + 32)
let vendorStart = consentData.intValue(fromBit: rangeStart + 1, toBit: rangeStart + vendorIdentifierSize)
let vendorFinish = consentData.intValue(fromBit: rangeStart + vendorIdentifierSize + 2, toBit: rangeStart + vendorIdentifierSize * 2)
if vendorStart <= vendorId && vendorId <= vendorFinish {
//if vendorId falls within range, then return opposite of default consent
return defaultConsent == 1 ? false : true
Expand Down
Loading