Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Minor code prettification (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
pithumke authored Jun 22, 2020
1 parent 3d58c8f commit 1ec2f35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,20 @@ private List<DiagnosisKey> padDiagnosisKeys(List<DiagnosisKey> diagnosisKeys) {
diagnosisKeys.forEach(diagnosisKey -> {
paddedDiagnosisKeys.add(diagnosisKey);
IntStream.range(1, randomKeyPaddingMultiplier)
.mapToObj(index -> {
byte[] randomKeyData = new byte[16];
new SecureRandom().nextBytes(randomKeyData);
return DiagnosisKey.builder()
.withKeyData(randomKeyData)
.withRollingStartIntervalNumber(diagnosisKey.getRollingStartIntervalNumber())
.withTransmissionRiskLevel(diagnosisKey.getTransmissionRiskLevel())
.withRollingPeriod(diagnosisKey.getRollingPeriod())
.build();
})
.mapToObj(index -> DiagnosisKey.builder()
.withKeyData(generateRandomKeyData())
.withRollingStartIntervalNumber(diagnosisKey.getRollingStartIntervalNumber())
.withTransmissionRiskLevel(diagnosisKey.getTransmissionRiskLevel())
.withRollingPeriod(diagnosisKey.getRollingPeriod())
.build())
.forEach(paddedDiagnosisKeys::add);
});
return paddedDiagnosisKeys;
}

private static byte[] generateRandomKeyData() {
byte[] randomKeyData = new byte[16];
new SecureRandom().nextBytes(randomKeyData);
return randomKeyData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private void assertElementsCorrespondToEachOther(Collection<TemporaryExposureKey
.map(submittedDiagnosisKey -> DiagnosisKey.builder().fromProtoBuf(submittedDiagnosisKey).build())
.collect(Collectors.toSet());

assertThat(savedDiagnosisKeys).hasSize(submittedDiagnosisKeys.size() * 10);
assertThat(savedDiagnosisKeys).hasSize(submittedDiagnosisKeys.size() * config.getRandomKeyPaddingMultiplier());
assertThat(savedDiagnosisKeys).containsAll(submittedDiagnosisKeys);

submittedDiagnosisKeys.forEach(submittedDiagnosisKey -> {
Expand All @@ -272,7 +272,7 @@ private void assertElementsCorrespondToEachOther(Collection<TemporaryExposureKey
submittedDiagnosisKey.getRollingStartIntervalNumber())
.collect(Collectors.toList());

assertThat(savedKeysForSingleSubmittedKey).hasSize(10);
assertThat(savedKeysForSingleSubmittedKey).hasSize(config.getRandomKeyPaddingMultiplier());
assertThat(savedKeysForSingleSubmittedKey.stream().filter(savedKey ->
Arrays.equals(savedKey.getKeyData(), submittedDiagnosisKey.getKeyData()))).hasSize(1);
assertThat(savedKeysForSingleSubmittedKey).allMatch(
Expand Down

0 comments on commit 1ec2f35

Please sign in to comment.