Mentions légales du service

Skip to content
Snippets Groups Projects
Commit eec16fbc authored by Deniro StopCovid's avatar Deniro StopCovid
Browse files

Merge branch '10-lossy-conversion' into 'develop'

Resolve "Lossy conversion"

Closes #10

See merge request !15
parents 67519ec9 850a0bce
No related branches found
No related tags found
1 merge request!15Resolve "Lossy conversion"
......@@ -138,10 +138,6 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> {
* Robert Spec Step #5: check that the delta between tA (16 bits) & timeA (32 bits) [truncated to 16bits] is below threshold.
*/
private boolean step5CheckDeltaTaAndTimeABelowThreshold(HelloMessageDetail helloMessageDetail) {
// Cast values from int that is unsigned into a signed long
final long timeFromHelloNTPsec = Integer.toUnsignedLong(helloMessageDetail.getTimeFromHelloMessage());
final long timeFromDevice = helloMessageDetail.getTimeCollectedOnDevice();
// Process 16-bit values for sanity check
final long timeFromHelloNTPsecAs16bits = castIntegerToLong(helloMessageDetail.getTimeFromHelloMessage(), 2);
final long timeFromDeviceAs16bits = castLong(helloMessageDetail.getTimeCollectedOnDevice(), 2);
......@@ -160,10 +156,10 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> {
/**
* Robert Spec Step #6
*/
private boolean step6CheckTimeACorrespondsToEpochiA(byte[] epochId, int timeFromDevice) {
private boolean step6CheckTimeACorrespondsToEpochiA(byte[] epochId, long timeFromDevice) {
final int epochIdFromEBID = ByteUtils.convertEpoch24bitsToInt(epochId);
final long tpstStartNTPsec = this.serverConfigurationService.getServiceTimeStart();
long epochIdFromMessage = TimeUtils.getNumberOfEpochsBetween(tpstStartNTPsec, Integer.toUnsignedLong(timeFromDevice));
long epochIdFromMessage = TimeUtils.getNumberOfEpochsBetween(tpstStartNTPsec, timeFromDevice);
// Check if epochs match with a limited tolerance
if (Math.abs(epochIdFromMessage - epochIdFromEBID) > 1) {
......@@ -258,7 +254,7 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> {
byte[] epochId) {
final long timeFromDevice = helloMessageDetail.getTimeCollectedOnDevice();
if (!step5CheckDeltaTaAndTimeABelowThreshold(helloMessageDetail)
|| !step6CheckTimeACorrespondsToEpochiA(epochId, (int) timeFromDevice)
|| !step6CheckTimeACorrespondsToEpochiA(epochId, timeFromDevice)
// Step #7: retrieve from IDTable, KA, the key associated with idA
|| !step8VerifyMACIsValid(ebid, encryptedCodeCountry, helloMessageDetail, registration)) {
return false;
......
......@@ -214,7 +214,7 @@ public class ContactProcessorTest {
return HelloMessageDetail.builder()
.timeFromHelloMessage(timeHello)
.timeCollectedOnDevice((long)timeReceived)
.timeCollectedOnDevice(Integer.toUnsignedLong(timeReceived))
.rssiCalibrated(rssi)
.mac(mac)
.build();
......@@ -253,7 +253,8 @@ public class ContactProcessorTest {
// Setup id with an existing score below threshold
Registration registrationWithEE = this.registration.get();
registrationWithEE.setExposedEpochs(Arrays.asList(EpochExposition.builder()
registrationWithEE.setExposedEpochs(Arrays.asList(
EpochExposition.builder()
.epochId(previousEpoch)
.expositionScores(Arrays.asList(3.0))
.build(),
......
......@@ -243,7 +243,7 @@ public class RSSICalibratedScoringStrategyTest {
.build());
messages.add(HelloMessageDetail.builder()
.timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900 - 5))
.timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900L - 5L))
.rssiCalibrated(-78)
.build());
......@@ -289,7 +289,7 @@ public class RSSICalibratedScoringStrategyTest {
public void testScoreRiskOneMessageLateNotAtRisk() {
List<HelloMessageDetail> messages = new ArrayList<>();
messages.add(HelloMessageDetail.builder()
.timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900 - 5))
.timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900L - 5L))
.rssiCalibrated(-78)
.build());
......
......@@ -14,10 +14,18 @@ import lombok.ToString;
@Builder
public class HelloMessageDetail {
/**
* WARNING: Since Java does not support unsigned int, we are obligated to store the value coming from the JSON representation
* as a Long even though it should be used as an unsigned int.
*/
@NotNull
@ToString.Exclude
private Long timeCollectedOnDevice;
/**
* WARNING: Since Java does not support unsigned short, we are obligated to store the value coming from the JSON
* representation as an Integer even though it should be used as an unsigned short.
*/
@NotNull
@ToString.Exclude
private Integer timeFromHelloMessage;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment