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

Minor code prettification #612

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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