Skip to content

Commit d4bd71f

Browse files
author
Athira M
committed
Addressed review comments
1 parent 6a51f70 commit d4bd71f

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

src/main/java/com/google/firebase/remoteconfig/ConditionEvaluator.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
final class ConditionEvaluator {
4343
private static final int MAX_CONDITION_RECURSION_DEPTH = 10;
4444
private static final Logger logger = LoggerFactory.getLogger(ConditionEvaluator.class);
45+
private static final BigInteger MICRO_PERCENT_MODULO = BigInteger.valueOf(100_000_000L);
4546

4647
/**
4748
* Evaluates server conditions and assigns a boolean value to each condition.
@@ -226,8 +227,7 @@ private BigInteger getMicroPercentile(String seed, String randomizationId) {
226227
String seedPrefix = seed != null && !seed.isEmpty() ? seed + "." : "";
227228
String stringToHash = seedPrefix + randomizationId;
228229
BigInteger hash = hashSeededRandomizationId(stringToHash);
229-
BigInteger modValue = new BigInteger(Integer.toString(100 * 1_000_000));
230-
BigInteger microPercentile = hash.mod(modValue);
230+
BigInteger microPercentile = hash.mod(MICRO_PERCENT_MODULO);
231231

232232
return microPercentile;
233233
}
@@ -238,19 +238,8 @@ private BigInteger hashSeededRandomizationId(String seededRandomizationId) {
238238
MessageDigest digest = MessageDigest.getInstance("SHA-256");
239239
byte[] hashBytes = digest.digest(seededRandomizationId.getBytes(StandardCharsets.UTF_8));
240240

241-
// Convert the hash bytes to a hexadecimal string.
242-
StringBuilder hexString = new StringBuilder();
243-
for (byte b : hashBytes) {
244-
String hex = Integer.toHexString(0xff & b);
245-
if (hex.length() == 1) {
246-
hexString.append('0');
247-
}
248-
hexString.append(hex);
249-
}
250-
251-
// Convert the hexadecimal string to a BigInteger
252-
return new BigInteger(hexString.toString(), 16);
253-
241+
// Convert the hash bytes to a BigInteger
242+
return new BigInteger(1, hashBytes);
254243
} catch (NoSuchAlgorithmException e) {
255244
logger.error("SHA-256 algorithm not found", e);
256245
throw new RuntimeException("SHA-256 algorithm not found", e);

src/main/java/com/google/firebase/remoteconfig/MicroPercentRange.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.firebase.remoteconfig;
1818

19-
import com.google.firebase.internal.NonNull;
2019
import com.google.firebase.internal.Nullable;
2120
import com.google.firebase.remoteconfig.internal.ServerTemplateResponse.MicroPercentRangeResponse;
2221

@@ -30,12 +29,10 @@ public MicroPercentRange(@Nullable Integer microPercentLowerBound,
3029
this.microPercentUpperBound = microPercentUpperBound != null ? microPercentUpperBound : 0;
3130
}
3231

33-
@NonNull
3432
int getMicroPercentLowerBound() {
3533
return microPercentLowerBound;
3634
}
3735

38-
@NonNull
3936
int getMicroPercentUpperBound() {
4037
return microPercentUpperBound;
4138
}

0 commit comments

Comments
 (0)