Skip to content

Commit

Permalink
Removed deprecated VendorConsent and ConsentStringParser. Better hand…
Browse files Browse the repository at this point in the history
…le out of bound conditions with corrupt consent strings
  • Loading branch information
lanusau committed Dec 21, 2018
1 parent 75c6492 commit 554cbb3
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 990 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [Unreleased]
## [3.0.1] - 12-21-2018

### Changed
- Removed VendorConsent class that was deprecated since version 2.0.1
- Better handle index out of bounds conditions with corrupt consent strings

## [2.0.2] - 06-19-2018

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
}

group = 'com.conversantmedia.gdpr'
version = '2.0.2'
version = '3.0.1'

description = 'A Java implementation of the IAB Consent String spec.'

Expand Down
36 changes: 6 additions & 30 deletions src/main/java/com/iab/gdpr/Bits.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public Bits(byte[] b) {
*/
public boolean getBit(int index) {
int byteIndex = index / 8;
if (byteIndex > bytes.length - 1)
throw new VendorConsentParseException("Expected consent string to contain at least " + byteIndex + "bytes, but found only " + bytes.length + " bytes");
int bitExact = index % 8;
byte b = bytes[byteIndex];
return (b & bytePows[bitExact]) != 0;
Expand Down Expand Up @@ -61,7 +63,7 @@ public void unsetBit(int index) {
* the nth to begin interpreting from
* @param size:
* the number of bits to interpret
* @return
* @return integer value
* @throws VendorConsentException
* when the bits cannot fit in an int sized field
*/
Expand Down Expand Up @@ -113,7 +115,7 @@ public void setInt(int startInclusive, int size, int to) throws VendorConsentExc
* @throws VendorConsentException
* when the bits cannot fit in an int sized field
*/
public long getLong(int startInclusive, int size) throws VendorConsentException {
private long getLong(int startInclusive, int size) throws VendorConsentException {
if (size > Long.SIZE) {
throw new VendorConsentParseException("can't fit bit range in long: " + size);
}
Expand Down Expand Up @@ -142,7 +144,7 @@ public long getLong(int startInclusive, int size) throws VendorConsentException
* @throws VendorConsentException
* when the bits cannot fit into the provided size
*/
public void setLong(int startInclusive, int size, long to) throws VendorConsentException {
private void setLong(int startInclusive, int size, long to) throws VendorConsentException {
if (size > Long.SIZE || to > maxOfSize(size) || to < 0) {
throw new VendorConsentCreateException("can't fit long into bit range of size " + size);
}
Expand All @@ -158,7 +160,7 @@ public void setLong(int startInclusive, int size, long to) throws VendorConsentE
* the bit from which to begin interpreting
* @param size:
* the number of bits to interpret
* @return
* @return instant value
* @throws VendorConsentException
* when the number of bits requested cannot fit in a long
*/
Expand All @@ -172,14 +174,6 @@ public void setInstantToEpochDeciseconds(int startInclusive, int size, Instant i
setLong(startInclusive, size, instant.toEpochMilli() / 100);
}

/**
* @return the number of bits in the bit string
*
*/
public int length() {
return bytes.length * 8;
}

/**
* This method interprets the given interval in the bit string as a series of six bit characters, where 0=A and 26=Z
*
Expand Down Expand Up @@ -229,24 +223,6 @@ public void setSixBitString(int startInclusive, int size, String to) throws Vend
}
}

/**
*
* @return a string representation of the byte array passed in the constructor. for example, a bit array of [4]
* yields a String of "0100"
*/
public String getBinaryString() {
StringBuilder s = new StringBuilder();
int size = length();
for (int i = 0; i < size; i++) {
if (getBit(i)) {
s.append("1");
} else {
s.append("0");
}
}
return s.toString();
}

public byte[] toByteArray() {
return bytes;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/iab/gdpr/GdprConstants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.iab.gdpr;

/**
* Various constants related to positions and sizes of GDPR consent string bits
*/
public class GdprConstants {
public static final int VENDOR_ENCODING_RANGE = 1;
public static final int VERSION_BIT_OFFSET = 0;
Expand Down
Loading

0 comments on commit 554cbb3

Please sign in to comment.