Skip to content

Commit 13b8998

Browse files
authored
Merge pull request #512 from IABTechLab/gdm-UID2-5448-cleanup
Made refreshFrom a mandatory field and removed field length check when parsing salt files
2 parents 368a14d + 716fb61 commit 13b8998

File tree

4 files changed

+184
-220
lines changed

4 files changed

+184
-220
lines changed

src/main/java/com/uid2/shared/store/salt/SaltFileParser.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,23 @@ public SaltEntry[] parseFileLines(String[] saltFileLines, Integer size) {
2727

2828
private SaltEntry parseLine(String line, int lineNumber) {
2929
try {
30-
final String[] fields = line.split(",");
30+
final String[] fields = line.split(",", -1);
3131
final long id = Integer.parseInt(fields[0]);
3232
final String hashedId = this.idHashingScheme.encode(id);
3333
final long lastUpdated = Long.parseLong(fields[1]);
3434
final String salt = fields[2];
35+
final long refreshFrom = Long.parseLong(fields[3]);
36+
final String previousSalt = trimToNull(fields[4]);
3537

36-
Long refreshFrom = null;
37-
String previousSalt = null;
38+
// TODO: The fields below should stop being optional once refreshable UIDs features get rolled out in production. We can remove them one by one as necessary.
39+
// AU, 2025/07/28
3840
SaltEntry.KeyMaterial currentKey = null;
3941
SaltEntry.KeyMaterial previousKey = null;
40-
41-
// TODO: The fields below should stop being optional once the refresh from, previous salt
42-
// and refreshable UIDs features get rolled out in production. We can remove them one by one as necessary.
43-
// AU, 2025/04/28
44-
if (fields.length > 3) {
45-
refreshFrom = Long.parseLong(fields[3]);
46-
}
47-
if (fields.length > 4) {
48-
previousSalt = fields[4];
49-
}
50-
if (fields.length > 7) {
42+
if (trimToNull(fields[5]) != null && trimToNull(fields[6]) != null) {
5143
currentKey = new SaltEntry.KeyMaterial(Integer.parseInt(fields[5]), fields[6], fields[7]);
5244
}
53-
if (fields.length > 10) {
45+
46+
if (trimToNull(fields[8]) != null && trimToNull(fields[9]) != null) {
5447
previousKey = new SaltEntry.KeyMaterial(Integer.parseInt(fields[8]), fields[9], fields[10]);
5548
}
5649

@@ -60,4 +53,7 @@ private SaltEntry parseLine(String line, int lineNumber) {
6053
}
6154
}
6255

56+
private String trimToNull(String s) {
57+
return s == null || s.isBlank() ? null : s.trim();
58+
}
6359
}

0 commit comments

Comments
 (0)