Skip to content

Commit 2ae26b1

Browse files
committed
1. Renamed TokenUtils.java's functions to be blatently clear on the input value type
2. Fixed the old testIdentityMapForOptOutUser test that was using raw DII as a hash 3. Renamed all uses of IdentityString/IdentityHash variables to rawDii and hashedDii
1 parent a8f0915 commit 2ae26b1

File tree

6 files changed

+86
-86
lines changed

6 files changed

+86
-86
lines changed

src/main/java/com/uid2/operator/service/InputUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public InputVal(String provided, String normalized, DiiType diiType, DiiInputTyp
197197
this.valid = valid;
198198
if (valid) {
199199
if (this.inputType == DiiInputType.Raw) {
200-
this.diiInput = TokenUtils.getDiiHash(this.normalized);
200+
this.diiInput = TokenUtils.getHashedDii(this.normalized);
201201
} else {
202202
this.diiInput = EncodingUtils.fromBase64(this.normalized);
203203
}

src/main/java/com/uid2/operator/service/TokenUtils.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@
77
import java.util.Set;
88

99
public class TokenUtils {
10-
public static byte[] getDiiHash(String identityString) {
11-
return EncodingUtils.getSha256Bytes(identityString);
10+
public static byte[] getHashedDii(String rawDii) {
11+
return EncodingUtils.getSha256Bytes(rawDii);
1212
}
1313

14-
public static String getDiiHashString(String identityString) {
15-
return EncodingUtils.toBase64String(getDiiHash(identityString));
14+
public static String getHashedDiiString(String rawDii) {
15+
return EncodingUtils.toBase64String(getHashedDii(rawDii));
1616
}
1717

18-
public static byte[] getFirstLevelHash(byte[] identityHash, String firstLevelSalt) {
19-
return getFirstLevelHashFromIdentityHash(EncodingUtils.toBase64String(identityHash), firstLevelSalt);
18+
public static byte[] getFirstLevelHashFromHashedDii(byte[] hashedDii, String firstLevelSalt) {
19+
return getFirstLevelHashFromHashedDii(EncodingUtils.toBase64String(hashedDii), firstLevelSalt);
2020
}
2121

22-
public static byte[] getFirstLevelHashFromIdentity(String identityString, String firstLevelSalt) {
23-
return getFirstLevelHash(getDiiHash(identityString), firstLevelSalt);
22+
public static byte[] getFirstLevelHashFromRawDii(String rawDii, String firstLevelSalt) {
23+
return getFirstLevelHashFromHashedDii(getHashedDii(rawDii), firstLevelSalt);
2424
}
2525

26-
public static byte[] getFirstLevelHashFromIdentityHash(String identityHash, String firstLevelSalt) {
27-
return EncodingUtils.getSha256Bytes(identityHash, firstLevelSalt);
26+
public static byte[] getFirstLevelHashFromHashedDii(String hashedDii, String firstLevelSalt) {
27+
return EncodingUtils.getSha256Bytes(hashedDii, firstLevelSalt);
2828
}
2929

3030
public static byte[] getRawUidV2(byte[] firstLevelHash, String rotatingSalt) {
3131
return EncodingUtils.getSha256Bytes(EncodingUtils.toBase64String(firstLevelHash), rotatingSalt);
3232
}
3333

34-
public static byte[] getRawUidV2FromIdentity(String identityString, String firstLevelSalt, String rotatingSalt) {
35-
return getRawUidV2(getFirstLevelHashFromIdentity(identityString, firstLevelSalt), rotatingSalt);
34+
public static byte[] getRawUidV2FromRawDii(String rawDii, String firstLevelSalt, String rotatingSalt) {
35+
return getRawUidV2(getFirstLevelHashFromRawDii(rawDii, firstLevelSalt), rotatingSalt);
3636
}
3737

38-
public static byte[] getRawUidV2FromIdentityHash(String identityString, String firstLevelSalt, String rotatingSalt) {
39-
return getRawUidV2(getFirstLevelHashFromIdentityHash(identityString, firstLevelSalt), rotatingSalt);
38+
public static byte[] getRawUidV2FromHashedDii(String hashedDii, String firstLevelSalt, String rotatingSalt) {
39+
return getRawUidV2(getFirstLevelHashFromHashedDii(hashedDii, firstLevelSalt), rotatingSalt);
4040
}
4141

4242
public static byte[] getRawUidV3(IdentityScope scope, DiiType type, byte[] firstLevelHash, String rotatingSalt) {
@@ -47,12 +47,12 @@ public static byte[] getRawUidV3(IdentityScope scope, DiiType type, byte[] first
4747
return rawUid;
4848
}
4949

50-
public static byte[] getRawUidV3FromIdentity(IdentityScope scope, DiiType type, String identityString, String firstLevelSalt, String rotatingSalt) {
51-
return getRawUidV3(scope, type, getFirstLevelHashFromIdentity(identityString, firstLevelSalt), rotatingSalt);
50+
public static byte[] getRawUidV3FromRawDii(IdentityScope scope, DiiType type, String rawDii, String firstLevelSalt, String rotatingSalt) {
51+
return getRawUidV3(scope, type, getFirstLevelHashFromRawDii(rawDii, firstLevelSalt), rotatingSalt);
5252
}
5353

54-
public static byte[] getRawUidV3FromIdentityHash(IdentityScope scope, DiiType type, String identityString, String firstLevelSalt, String rotatingSalt) {
55-
return getRawUidV3(scope, type, getFirstLevelHashFromIdentityHash(identityString, firstLevelSalt), rotatingSalt);
54+
public static byte[] getRawUidV3FromHashedDii(IdentityScope scope, DiiType type, String hashedDii, String firstLevelSalt, String rotatingSalt) {
55+
return getRawUidV3(scope, type, getFirstLevelHashFromHashedDii(hashedDii, firstLevelSalt), rotatingSalt);
5656
}
5757

5858
public static byte encodeIdentityScope(IdentityScope identityScope) {

src/main/java/com/uid2/operator/service/UIDOperatorService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ public IdentityMapResponseItem mapHashedDii(IdentityMapRequestItem request) {
170170
}
171171

172172
@Override
173-
public IdentityMapResponseItem map(HashedDii diiIdentity, Instant asOf) {
174-
final FirstLevelHash firstLevelHash = getFirstLevelHashIdentity(diiIdentity, asOf);
173+
public IdentityMapResponseItem map(HashedDii hashedDii, Instant asOf) {
174+
final FirstLevelHash firstLevelHash = getFirstLevelHashIdentity(hashedDii, asOf);
175175
return generateRawUid(firstLevelHash, asOf);
176176
}
177177

@@ -233,8 +233,8 @@ private FirstLevelHash getFirstLevelHashIdentity(IdentityScope identityScope, Di
233233
return new FirstLevelHash(identityScope, diiType, firstLevelHash, null);
234234
}
235235

236-
private byte[] getFirstLevelHash(byte[] identityHash, Instant asOf) {
237-
return TokenUtils.getFirstLevelHash(identityHash, getSaltProviderSnapshot(asOf).getFirstLevelSalt());
236+
private byte[] getFirstLevelHash(byte[] hashedDii, Instant asOf) {
237+
return TokenUtils.getFirstLevelHashFromHashedDii(hashedDii, getSaltProviderSnapshot(asOf).getFirstLevelSalt());
238238
}
239239

240240
private IdentityMapResponseItem generateRawUid(FirstLevelHash firstLevelHash, Instant asOf) {

src/test/java/com/uid2/operator/TokenEncodingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void testRefreshTokenEncoding(TokenVersion tokenVersion) {
5555
final EncryptedTokenEncoder encoder = new EncryptedTokenEncoder(this.keyManager);
5656
final Instant now = EncodingUtils.NowUTCMillis();
5757

58-
final byte[] firstLevelHash = TokenUtils.getFirstLevelHashFromIdentity("[email protected]", "some-salt");
58+
final byte[] firstLevelHash = TokenUtils.getFirstLevelHashFromRawDii("[email protected]", "some-salt");
5959

6060
final TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(tokenVersion,
6161
now,

src/test/java/com/uid2/operator/UIDOperatorServiceTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
2626

27-
import static com.uid2.operator.service.TokenUtils.getFirstLevelHash;
27+
import static com.uid2.operator.service.TokenUtils.getFirstLevelHashFromHashedDii;
2828
import static org.junit.jupiter.api.Assertions.*;
2929

3030
import org.junit.jupiter.params.ParameterizedTest;
@@ -144,11 +144,11 @@ private void setNow(Instant now) {
144144
when(clock.instant()).thenAnswer(i -> this.now);
145145
}
146146

147-
private HashedDii createHashedDiiIdentity(String rawIdentityHash, IdentityScope scope, DiiType type) {
147+
private HashedDii createHashedDii(String hashedDii, IdentityScope scope, DiiType type) {
148148
return new HashedDii(
149149
scope,
150150
type,
151-
rawIdentityHash.getBytes(StandardCharsets.UTF_8)
151+
hashedDii.getBytes(StandardCharsets.UTF_8)
152152
);
153153
}
154154

@@ -189,7 +189,7 @@ public void testGenerateAndRefresh(int siteId, TokenVersion tokenVersion) {
189189

190190
final TokenGenerateRequest tokenGenerateRequest = new TokenGenerateRequest(
191191
new SourcePublisher(siteId, 124, 125),
192-
createHashedDiiIdentity("test-email-hash", expectedIdentityScope, expectedDiiType),
192+
createHashedDii("test-email-hash", expectedIdentityScope, expectedDiiType),
193193
OptoutCheckPolicy.DoNotRespect, PrivacyBits.fromInt(0),
194194
this.now.minusSeconds(234)
195195
);
@@ -214,7 +214,7 @@ public void testGenerateAndRefresh(int siteId, TokenVersion tokenVersion) {
214214
assertIdentityScopeIdentityType(expectedIdentityScope, expectedDiiType, tokenRefreshRequest.firstLevelHash);
215215
assertEquals(tokenGenerateRequest.establishedAt, tokenRefreshRequest.firstLevelHash.establishedAt());
216216

217-
final byte[] firstLevelHash = getFirstLevelHash(tokenGenerateRequest.hashedDii.hashedDii(),
217+
final byte[] firstLevelHash = getFirstLevelHashFromHashedDii(tokenGenerateRequest.hashedDii.hashedDii(),
218218
saltProvider.getSnapshot(this.now).getFirstLevelSalt() );
219219
assertArrayEquals(firstLevelHash, tokenRefreshRequest.firstLevelHash.firstLevelHash());
220220

@@ -311,7 +311,7 @@ public void testTestOptOutKeyIdentityScopeMismatch() {
311311
"Phone,+01010101010,UID2",
312312
"Phone,+01010101010,EUID"})
313313
public void testGenerateTokenForOptOutUser(DiiType type, String id, IdentityScope scope) {
314-
final HashedDii hashedDii = createHashedDiiIdentity(TokenUtils.getDiiHashString(id),
314+
final HashedDii hashedDii = createHashedDii(TokenUtils.getHashedDiiString(id),
315315
scope, type);
316316

317317
final TokenGenerateRequest tokenGenerateRequestForceGenerate = new TokenGenerateRequest(
@@ -364,7 +364,7 @@ public void testGenerateTokenForOptOutUser(DiiType type, String id, IdentityScop
364364
"Phone,+01010101010,UID2",
365365
"Phone,+01010101010,EUID"})
366366
public void testIdentityMapForOptOutUser(DiiType type, String identity, IdentityScope scope) {
367-
final HashedDii hashedDii = createHashedDiiIdentity(identity, scope, type);
367+
final HashedDii hashedDii = createHashedDii(TokenUtils.getHashedDiiString(identity), scope, type);
368368
final Instant now = Instant.now();
369369

370370
final IdentityMapRequestItem mapRequestForceIdentityMapItem = new IdentityMapRequestItem(

0 commit comments

Comments
 (0)