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
2 changes: 2 additions & 0 deletions .rake_tasks~
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default
test
1 change: 1 addition & 0 deletions iab_consent_string.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This library supports the version v1.1 of the specification. It can encode and d
"lib/iab_consent_string/consent/range/start_end_range_entry.rb",
"lib/iab_consent_string/consent/implementation/v1/byte_buffer_backed_vendor_consent.rb",
"lib/iab_consent_string/consent/implementation/v1/vendor_consent_builder.rb",
"lib/iab_consent_string/consent/implementation/v2/vendor_consent_builder.rb",
]
s.homepage = 'https://rubygems.org/gems/iab_consent_string'
s.metadata = { "source_code_uri" => "https://github.com/Fidzup/Consent-String-SDK-Ruby" }
Expand Down
7 changes: 7 additions & 0 deletions lib/iab_consent_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
require 'iab_consent_string/consent/vendor_consent_decoder'
require 'iab_consent_string/consent/implementation/v1/byte_buffer_backed_vendor_consent'
require 'iab_consent_string/consent/implementation/v1/vendor_consent_builder'
require 'iab_consent_string/consent/implementation/v2/vendor_consent_builder'
require 'iab_consent_string/consent/implementation/v2/byte_buffer_backed_vendor_consent'
require 'iab_consent_string/consent/implementation/v2/vendor/vendor_section_parser'
require 'iab_consent_string/consent/implementation/v2/vendor/vendor_section'
require 'iab_consent_string/consent/implementation/v2/vendor/vendor'
require 'iab_consent_string/consent/implementation/v2/publisher_restriction/publisher_restriction'
require 'iab_consent_string/consent/range/range_entry.rb'
require 'iab_consent_string/consent/range/start_end_range_entry.rb'
require 'iab_consent_string/consent/range/single_range_entry.rb'
require 'iab_consent_string/gdpr_constants'
require 'iab_consent_string/gdpr_constants_v2'
require 'iab_consent_string/purpose'
require 'iab_consent_string/util/utils'

Expand Down
15 changes: 14 additions & 1 deletion lib/iab_consent_string/bits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ def unsetBit(index)
@bytes[byteIndex] &= ~(1 << shift)
end

#
# Set on bit boolean value in position
#
# @param [Integer] index position
# @param [Boolean] val Value
def setBoolean(index, val)
if val
setBit(index)
else
unsetBit(index)
end
end

# Interprets n number of bits as a big endiant int
# @param startInclusive [Integer] the nth to begin interpreting from
# @param size [Integer] the number of bits to interpret
Expand Down Expand Up @@ -165,7 +178,7 @@ def setSixBitString(startInclusive, size, to)
charCode = values[i].ord - 65
setInt(startInclusive + (i * 6), 6, charCode)
end
end
end

# @return [String] a string representation of the byte array passed in the constructor. for example, a bit array of [4]
# yields a String of "0100"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ def getAllowedPurposeIds
allowedPurposes
end

def getAllowedVendorIds
allowedVendors = Set[]
if (encodingType() == IABConsentString::GDPRConstants::VERSION_BIT_OFFSET)
for i in (IABConsentString::GDPRConstants::VENDOR_BITFIELD_OFFSET...(IABConsentString::GDPRConstants::VENDOR_BITFIELD_OFFSET + getMaxVendorId())) do
if (@bits.getBit(i))
allowedVendors.add(i - IABConsentString::GDPRConstants::VENDOR_BITFIELD_OFFSET + 1)
end
end
else
for i in (1..getMaxVendorId())
allowedVendors.add(i) if isVendorAllowed(i)
end
end
allowedVendors
end

def getAllowedPurposes
allowedPurposes = getAllowedPurposeIds().map! {|id| IABConsentString::Purpose.new(id)}
allowedPurposes.to_a.uniq{|o| [o.getId]}.to_set
Expand Down Expand Up @@ -92,6 +108,10 @@ def isVendorAllowed(vendorId)
end
end

def toByteArrayList
[self.toByteArray]
end

def toByteArray
@bits.toByteArray()
end
Expand Down Expand Up @@ -125,7 +145,7 @@ def isVendorPresentInRange(vendorId)
numEntries = @bits.getInt(IABConsentString::GDPRConstants::NUM_ENTRIES_OFFSET, IABConsentString::GDPRConstants::NUM_ENTRIES_SIZE)
maxVendorId = getMaxVendorId()
currentOffset = IABConsentString::GDPRConstants::RANGE_ENTRY_OFFSET
for i in (0...numEntries) do
numEntries.times do
range = @bits.getBit(currentOffset)
currentOffset += 1
if range
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'set'
require 'date'
require 'iab_consent_string/bits'
require 'iab_consent_string/gdpr_constants'
require 'iab_consent_string/consent/vendor_consent'

module IABConsentString
module Consent
module Implementation
module V2
module ByteBufferBackedAllowedVendorConsent
def getAllowedVendor
parser = IABConsentString::Consent::Implementation::V2::VendorSectionParser.new(@bits_allowed_vendors, IABConsentString::GDPRConstantsV2::Segment::VENDOR_START_SECTION_OFFSET)
vendor_consent = parser.parse
vendor_consent
end

def isAllowedVendor(id)
self.getAllowedVendor.isVendorConsented(id)
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
require 'set'
require 'date'
require 'iab_consent_string/bits'
require 'iab_consent_string/gdpr_constants'
require 'iab_consent_string/consent/vendor_consent'

module IABConsentString
module Consent
module Implementation
module V2
module ByteBufferBackedVendorConsentCore
def getVersion
@bits_core.getInt(IABConsentString::GDPRConstantsV2::Core::VERSION_BIT_OFFSET,IABConsentString::GDPRConstantsV2::Core::VERSION_BIT_SIZE)
end

def getConsentRecordCreated
@bits_core.getDateTimeFromEpochDeciseconds(IABConsentString::GDPRConstantsV2::Core::CREATED_BIT_OFFSET, IABConsentString::GDPRConstantsV2::Core::CREATED_BIT_SIZE)
end

def getConsentRecordLastUpdated
@bits_core.getDateTimeFromEpochDeciseconds(IABConsentString::GDPRConstantsV2::Core::UPDATED_BIT_OFFSET,IABConsentString::GDPRConstantsV2::Core::UPDATED_BIT_SIZE)
end

def getCmpId
@bits_core.getInt(IABConsentString::GDPRConstantsV2::Core::CMP_ID_OFFSET,IABConsentString::GDPRConstantsV2::Core::CMP_ID_SIZE)
end

def getCmpVersion
@bits_core.getInt(IABConsentString::GDPRConstantsV2::Core::CMP_VERSION_OFFSET,IABConsentString::GDPRConstantsV2::Core::CMP_VERSION_SIZE)
end

def getConsentScreen
@bits_core.getInt(IABConsentString::GDPRConstantsV2::Core::CONSENT_SCREEN_OFFSET,IABConsentString::GDPRConstantsV2::Core::CONSENT_SCREEN_SIZE)
end

def getConsentLanguage
@bits_core.getSixBitString(IABConsentString::GDPRConstantsV2::Core::CONSENT_LANGUAGE_OFFSET,IABConsentString::GDPRConstantsV2::Core::CONSENT_LANGUAGE_SIZE)
end

def getVendorListVersion
@bits_core.getInt(IABConsentString::GDPRConstantsV2::Core::VENDOR_LIST_VERSION_OFFSET,IABConsentString::GDPRConstantsV2::Core::VENDOR_LIST_VERSION_SIZE)
end

def getTcfPolicyVersion
@bits_core.getInt(IABConsentString::GDPRConstantsV2::Core::TCF_POLICY_VERSION_OFFSET,IABConsentString::GDPRConstantsV2::Core::TCF_POLICY_VERSION_SIZE)
end

def getIsServiceSpecific
@bits_core.getBit(IABConsentString::GDPRConstantsV2::Core::IS_SERVICE_SPECIFIC_OFFSET)
end

def getUseNonStandardStacks
@bits_core.getBit(IABConsentString::GDPRConstantsV2::Core::USE_NON_STANDARD_STACKS_OFFSET)
end

def isSpecialFeatureOptIn(id)
if ((id < 1) || (id > IABConsentString::GDPRConstantsV2::Core::SPECIAL_FEATURE_OPT_INS_SIZE))
return false
end
@bits_core.getBit(IABConsentString::GDPRConstantsV2::Core::SPECIAL_FEATURE_OPT_INS_OFFSET + id - 1);
end

def isPurposesConsented(purpose_id)
if ((purpose_id < 1) || (purpose_id > IABConsentString::GDPRConstantsV2::Core::PURPOSES_CONSENT_SIZE))
return false
end
@bits_core.getBit(IABConsentString::GDPRConstantsV2::Core::PURPOSES_CONSENT_OFFSET + purpose_id - 1);
end

def isPurposesLITransparency(purpose_id)
if ((purpose_id < 1) || (purpose_id > IABConsentString::GDPRConstantsV2::Core::PURPOSES_LI_TRANSPARENCY_SIZE))
return false
end
@bits_core.getBit(IABConsentString::GDPRConstantsV2::Core::PURPOSES_LI_TRANSPARENCY_OFFSET + purpose_id - 1);
end

def getPurposesLiTransparency
@bits_core.getInt(IABConsentString::GDPRConstantsV2::Core::PURPOSES_LI_TRANSPARENCY_OFFSET,IABConsentString::GDPRConstantsV2::Core::PURPOSES_LI_TRANSPARENCY_SIZE)
end

def getPurposeOneTreatment
@bits_core.getBit(IABConsentString::GDPRConstantsV2::Core::PURPOSE_ONE_TREATMENT_OFFSET);
end

def getPublisherCC
@bits_core.getSixBitString(IABConsentString::GDPRConstantsV2::Core::PUBLISHER_CC_OFFSET,IABConsentString::GDPRConstantsV2::Core::PUBLISHER_CC_SIZE)
end

def getVendorConsent
parser = IABConsentString::Consent::Implementation::V2::VendorSectionParser.new(@bits_core, IABConsentString::GDPRConstantsV2::Core::VENDOR_START_SECTION_OFFSET)
vendor_consent = parser.parse
@end_vendor_consent = parser.current_offset
vendor_consent
end

def isVendorConsented(id)
self.getVendorConsent.isVendorConsented(id)
end

def getVendorLegitimateInterest
getVendorConsent unless @end_vendor_consent
parser = IABConsentString::Consent::Implementation::V2::VendorSectionParser.new(@bits_core, @end_vendor_consent)
vendor_consent = parser.parse
@end_vendor_legitimate_interest = parser.current_offset
vendor_consent
end

def isVendorLegitimateInterested(id)
self.getVendorLegitimateInterest.isVendorConsented(id)
end

# get publisher restriction
# @return [PublisherRestrictionSection] publisher restriction object
def getPublisherRestrictions
getVendorLegitimateInterest unless @end_vendor_legitimate_interest
parser = IABConsentString::Consent::Implementation::V2::PublisherRestrictionParser.new(@bits_core, @end_vendor_legitimate_interest)
publisher_restriction = parser.parse
publisher_restriction
end

def getPublisherRestriction(purpose_id, vendor_id)
self.getPublisherRestrictions.getRestriction(purpose_id, vendor_id)
end

end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'set'
require 'date'
require 'iab_consent_string/bits'
require 'iab_consent_string/gdpr_constants'
require 'iab_consent_string/consent/vendor_consent'

module IABConsentString
module Consent
module Implementation
module V2
module ByteBufferBackedDiscloedVendorConsent
def getDisclosedVendor
parser = IABConsentString::Consent::Implementation::V2::VendorSectionParser.new(@bits_disclosed_vendors, IABConsentString::GDPRConstantsV2::Segment::VENDOR_START_SECTION_OFFSET)
vendor_consent = parser.parse
vendor_consent
end

def isDisclosedVendor(id)
self.getDisclosedVendor.isVendorConsented(id)
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'set'
require 'date'
require 'iab_consent_string/bits'
require 'iab_consent_string/gdpr_constants'
require 'iab_consent_string/consent/vendor_consent'

module IABConsentString
module Consent
module Implementation
module V2
module ByteBufferBackedPublisherPurposesTransparency
def getPubPurposeConsent(purpose_id)
@bits_publisher_purpose.getBit(IABConsentString::GDPRConstantsV2::PubPurposesTransparency::PUB_PURPOSES_CONSENT_OFFSET + purpose_id - 1)
end

def getPubPurposeLITransparency(purpose_id)
@bits_publisher_purpose.getBit(IABConsentString::GDPRConstantsV2::PubPurposesTransparency::PUB_PURPOSES_LI_TRANSPARENCY_OFFSET + purpose_id - 1)
end

def getNumCustomPurposes
@bits_publisher_purpose.getInt(IABConsentString::GDPRConstantsV2::PubPurposesTransparency::NUM_CUSTOM_PURPOSES_OFFSET, IABConsentString::GDPRConstantsV2::PubPurposesTransparency::NUM_CUSTOM_PURPOSES_SIZE)
end

def getCustomPurposeConsent(purpose_id)
num_custom_purposes = getNumCustomPurposes
return nil unless (purpose_id > 0 && purpose_id <= num_custom_purposes)
@bits_publisher_purpose.getBit(IABConsentString::GDPRConstantsV2::PubPurposesTransparency::CUSTOM_PURPOSES_OFFSET + purpose_id - 1)
end

def getCustomPurposeLITransparency(purpose_id)
num_custom_purposes = getNumCustomPurposes
return nil unless (purpose_id > 0 && purpose_id <= num_custom_purposes)
offset = IABConsentString::GDPRConstantsV2::PubPurposesTransparency::CUSTOM_PURPOSES_OFFSET + num_custom_purposes
@bits_publisher_purpose.getBit(offset + purpose_id - 1)
end

end
end
end
end
end
Loading