Skip to content

Commit 4e3c31b

Browse files
committed
Updated identity enums
1 parent 9f1d46a commit 4e3c31b

File tree

6 files changed

+50
-28
lines changed

6 files changed

+50
-28
lines changed

src/main/java/com/uid2/operator/model/IdentityEnvironment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import com.uid2.operator.vertx.ClientInputValidationException;
55

66
public enum IdentityEnvironment {
7-
TEST(0), INTEG(1), PROD(2);
7+
TEST(0),
8+
INTEG(1),
9+
PROD(2);
810

911
private final int value;
1012

src/main/java/com/uid2/operator/model/IdentityScope.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@ public enum IdentityScope {
66
UID2(0),
77
EUID(1);
88

9-
public final int value;
9+
private final int value;
1010

11-
IdentityScope(int value) { this.value = value; }
11+
IdentityScope(int value) {
12+
this.value = value;
13+
}
14+
15+
public int getValue() {
16+
return value;
17+
}
1218

1319
public static IdentityScope fromValue(int value) {
14-
switch (value) {
15-
case 0: return UID2;
16-
case 1: return EUID;
17-
default: throw new ClientInputValidationException("Invalid value for IdentityScope: " + value);
18-
}
20+
return switch (value) {
21+
case 0 -> UID2;
22+
case 1 -> EUID;
23+
default -> throw new ClientInputValidationException("Invalid value for IdentityScope: " + value);
24+
};
1925
}
2026

2127
public static IdentityScope fromString(String str) {
22-
switch (str.toLowerCase()) {
23-
case "uid2": return UID2;
24-
case "euid": return EUID;
25-
default: throw new ClientInputValidationException("Invalid string for IdentityScope: " + str);
26-
}
28+
return switch (str.toLowerCase()) {
29+
case "uid2" -> UID2;
30+
case "euid" -> EUID;
31+
default -> throw new ClientInputValidationException("Invalid string for IdentityScope: " + str);
32+
};
2733
}
2834
}

src/main/java/com/uid2/operator/model/IdentityType.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
import com.uid2.operator.vertx.ClientInputValidationException;
44

55
public enum IdentityType {
6-
Email(0), Phone(1);
6+
Email(0),
7+
Phone(1);
78

8-
public final int value;
9+
private final int value;
910

10-
IdentityType(int value) { this.value = value; }
11+
IdentityType(int value) {
12+
this.value = value;
13+
}
14+
15+
public int getValue() {
16+
return value;
17+
}
1118

1219
public static IdentityType fromValue(int value) {
13-
switch (value) {
14-
case 0: return Email;
15-
case 1: return Phone;
16-
default: throw new ClientInputValidationException("Invalid valid for IdentityType: " + value);
17-
}
20+
return switch (value) {
21+
case 0 -> Email;
22+
case 1 -> Phone;
23+
default -> throw new ClientInputValidationException("Invalid valid for IdentityType: " + value);
24+
};
1825
}
1926
}

src/main/java/com/uid2/operator/model/IdentityVersion.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
import com.uid2.operator.vertx.ClientInputValidationException;
44

55
public enum IdentityVersion {
6-
V3(0), V4(1);
6+
V3(0),
7+
V4(1);
78

8-
public final int value;
9+
private final int value;
910

10-
IdentityVersion(int value) { this.value = value; }
11+
IdentityVersion(int value) {
12+
this.value = value;
13+
}
14+
15+
public int getValue() {
16+
return value;
17+
}
1118

1219
public static IdentityVersion fromValue(int value) {
1320
return switch (value) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private byte[] encryptIdentityV2(PublisherIdentity publisherIdentity, UserIdenti
365365
}
366366

367367
private static byte encodeIdentityTypeV3(UserIdentity userIdentity) {
368-
return (byte) (TokenUtils.encodeIdentityScope(userIdentity.identityScope) | (userIdentity.identityType.value << 2) | 3);
368+
return (byte) (TokenUtils.encodeIdentityScope(userIdentity.identityScope) | (userIdentity.identityType.getValue() << 2) | 3);
369369
// "| 3" is used so that the 2nd char matches the version when V3 or higher. Eg "3" for V3 and "4" for V4
370370
}
371371

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public static byte[] getAdvertisingIdV4FromIdentityHash(IdentityScope scope, Ide
7272
}
7373

7474
public static byte encodeIdentityScope(IdentityScope identityScope) {
75-
return (byte) (identityScope.value << 4);
75+
return (byte) (identityScope.getValue() << 4);
7676
}
7777

7878
public static byte encodeIdentityType(IdentityType identityType) {
79-
return (byte) (identityType.value << 2);
79+
return (byte) (identityType.getValue() << 2);
8080
}
8181

8282
public static byte encodeIdentityVersion(IdentityVersion identityVersion) {
83-
return (byte) (identityVersion.value << 6);
83+
return (byte) (identityVersion.getValue() << 6);
8484
}
8585

8686
public static byte encodeIdentityEnvironment(IdentityEnvironment identityEnvironment) {

0 commit comments

Comments
 (0)