From 5b0d26e8926eff0ce2891438c9583e3e1a714837 Mon Sep 17 00:00:00 2001 From: Chad Huff Date: Tue, 5 Aug 2025 06:43:19 -0600 Subject: [PATCH] usnat backwards compatibility for compressed padding --- .../gpp/encoder/segment/UsNatCoreSegment.java | 6 ++++- .../iab/gpp/encoder/section/UsNatTest.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/segment/UsNatCoreSegment.java b/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/segment/UsNatCoreSegment.java index 6c7a7945..0c4769ad 100644 --- a/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/segment/UsNatCoreSegment.java +++ b/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/segment/UsNatCoreSegment.java @@ -99,7 +99,11 @@ protected void decodeSegment(String encodedString, EncodableBitStringFields fiel // Necessary to maintain backwards compatibility when sensitive data processing changed from a // length of 12 to 16 and known child sensitive data consents changed from a length of 2 to 3 in the // DE, IA, NE, NH, NJ, TN release - if (bitString.length() == 66) { + if (bitString.length() == 60) { + bitString = + bitString.substring(0, 48) + "00000000" + bitString.substring(48, 52) + "00" + bitString.substring(52, 60) + "00"; + } + else if (bitString.length() == 66) { bitString = bitString.substring(0, 48) + "00000000" + bitString.substring(48, 52) + "00" + bitString.substring(52, 62); } diff --git a/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/section/UsNatTest.java b/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/section/UsNatTest.java index 67029545..4d32c057 100644 --- a/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/section/UsNatTest.java +++ b/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/section/UsNatTest.java @@ -228,6 +228,28 @@ public void testDecodeWithGpcSegmentExcluded() throws DecodingException { Assertions.assertEquals(2, usNat.getMspaServiceProviderMode()); Assertions.assertEquals(false, usNat.getGpcSegmentIncluded()); } + + @Test + public void testDecodeBackwardsCompatibility() throws DecodingException { + UsNat usNat = new UsNat("BVQqAAAACg"); + + Assertions.assertEquals(1, usNat.getSharingNotice()); + Assertions.assertEquals(1, usNat.getSaleOptOutNotice()); + Assertions.assertEquals(1, usNat.getSharingOptOutNotice()); + Assertions.assertEquals(1, usNat.getTargetedAdvertisingOptOutNotice()); + Assertions.assertEquals(0, usNat.getSensitiveDataProcessingOptOutNotice()); + Assertions.assertEquals(0, usNat.getSensitiveDataLimitUseNotice()); + Assertions.assertEquals(2, usNat.getSaleOptOut()); + Assertions.assertEquals(2, usNat.getSharingOptOut()); + Assertions.assertEquals(2, usNat.getTargetedAdvertisingOptOut()); + Assertions.assertEquals(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), usNat.getSensitiveDataProcessing()); + Assertions.assertEquals(Arrays.asList(0, 0, 0), usNat.getKnownChildSensitiveDataConsents()); + Assertions.assertEquals(2, usNat.getPersonalDataConsents()); + Assertions.assertEquals(2, usNat.getMspaCoveredTransaction()); + Assertions.assertEquals(0, usNat.getMspaOptOutOptionMode()); + Assertions.assertEquals(0, usNat.getMspaServiceProviderMode()); + Assertions.assertEquals(false, usNat.getGpc()); + } @Test() public void testDecodeGarbage() {