Skip to content

Commit 554cbb3

Browse files
committed
Removed deprecated VendorConsent and ConsentStringParser. Better handle out of bound conditions with corrupt consent strings
1 parent 75c6492 commit 554cbb3

File tree

12 files changed

+36
-990
lines changed

12 files changed

+36
-990
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [Unreleased]
4+
## [3.0.1] - 12-21-2018
5+
6+
### Changed
7+
- Removed VendorConsent class that was deprecated since version 2.0.1
8+
- Better handle index out of bounds conditions with corrupt consent strings
59

610
## [2.0.2] - 06-19-2018
711

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repositories {
1010
}
1111

1212
group = 'com.conversantmedia.gdpr'
13-
version = '2.0.2'
13+
version = '3.0.1'
1414

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

src/main/java/com/iab/gdpr/Bits.java

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public Bits(byte[] b) {
2727
*/
2828
public boolean getBit(int index) {
2929
int byteIndex = index / 8;
30+
if (byteIndex > bytes.length - 1)
31+
throw new VendorConsentParseException("Expected consent string to contain at least " + byteIndex + "bytes, but found only " + bytes.length + " bytes");
3032
int bitExact = index % 8;
3133
byte b = bytes[byteIndex];
3234
return (b & bytePows[bitExact]) != 0;
@@ -61,7 +63,7 @@ public void unsetBit(int index) {
6163
* the nth to begin interpreting from
6264
* @param size:
6365
* the number of bits to interpret
64-
* @return
66+
* @return integer value
6567
* @throws VendorConsentException
6668
* when the bits cannot fit in an int sized field
6769
*/
@@ -113,7 +115,7 @@ public void setInt(int startInclusive, int size, int to) throws VendorConsentExc
113115
* @throws VendorConsentException
114116
* when the bits cannot fit in an int sized field
115117
*/
116-
public long getLong(int startInclusive, int size) throws VendorConsentException {
118+
private long getLong(int startInclusive, int size) throws VendorConsentException {
117119
if (size > Long.SIZE) {
118120
throw new VendorConsentParseException("can't fit bit range in long: " + size);
119121
}
@@ -142,7 +144,7 @@ public long getLong(int startInclusive, int size) throws VendorConsentException
142144
* @throws VendorConsentException
143145
* when the bits cannot fit into the provided size
144146
*/
145-
public void setLong(int startInclusive, int size, long to) throws VendorConsentException {
147+
private void setLong(int startInclusive, int size, long to) throws VendorConsentException {
146148
if (size > Long.SIZE || to > maxOfSize(size) || to < 0) {
147149
throw new VendorConsentCreateException("can't fit long into bit range of size " + size);
148150
}
@@ -158,7 +160,7 @@ public void setLong(int startInclusive, int size, long to) throws VendorConsentE
158160
* the bit from which to begin interpreting
159161
* @param size:
160162
* the number of bits to interpret
161-
* @return
163+
* @return instant value
162164
* @throws VendorConsentException
163165
* when the number of bits requested cannot fit in a long
164166
*/
@@ -172,14 +174,6 @@ public void setInstantToEpochDeciseconds(int startInclusive, int size, Instant i
172174
setLong(startInclusive, size, instant.toEpochMilli() / 100);
173175
}
174176

175-
/**
176-
* @return the number of bits in the bit string
177-
*
178-
*/
179-
public int length() {
180-
return bytes.length * 8;
181-
}
182-
183177
/**
184178
* This method interprets the given interval in the bit string as a series of six bit characters, where 0=A and 26=Z
185179
*
@@ -229,24 +223,6 @@ public void setSixBitString(int startInclusive, int size, String to) throws Vend
229223
}
230224
}
231225

232-
/**
233-
*
234-
* @return a string representation of the byte array passed in the constructor. for example, a bit array of [4]
235-
* yields a String of "0100"
236-
*/
237-
public String getBinaryString() {
238-
StringBuilder s = new StringBuilder();
239-
int size = length();
240-
for (int i = 0; i < size; i++) {
241-
if (getBit(i)) {
242-
s.append("1");
243-
} else {
244-
s.append("0");
245-
}
246-
}
247-
return s.toString();
248-
}
249-
250226
public byte[] toByteArray() {
251227
return bytes;
252228
}

src/main/java/com/iab/gdpr/GdprConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.iab.gdpr;
22

3+
/**
4+
* Various constants related to positions and sizes of GDPR consent string bits
5+
*/
36
public class GdprConstants {
47
public static final int VENDOR_ENCODING_RANGE = 1;
58
public static final int VERSION_BIT_OFFSET = 0;

0 commit comments

Comments
 (0)