Skip to content

Commit

Permalink
non-mandatory dates due to NFC pcaket size
Browse files Browse the repository at this point in the history
  • Loading branch information
tbocek committed Aug 10, 2016
1 parent 9b0dd07 commit 480618b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public SignVerifyTO signVerify(@RequestBody SignVerifyTO request) {
final byte[] payeePubKey = request.payeePublicKey();
request.payeePublicKey(null);

final SignVerifyTO error = ToUtils.checkInput(request);
//NFC has a hard limit of 245, thus we have no space for the date yet.
final SignVerifyTO error = ToUtils.checkInput(request, false);
if (error != null) {
LOG.info("{} - clientPubKey={} - input error - type={}", tag, clientPubKeyHex, error.type());
return error;
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/com/coinblesk/server/utils/ToUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,35 @@ public static <K extends BaseTO> K newInstance(Class<? extends BaseTO> clazz, Ty
throw new RuntimeException("Cannot ceate instance", ex);
}
}

public static <K extends BaseTO> K checkInput(final K input) {
return checkInput(input, true);
}

public static <K extends BaseTO> K checkInput(final K input, boolean checkDate) {

if (!input.isInputSet()) {
return newInstance(input, Type.INPUT_MISMATCH);
}


//check if the client sent us a time which is way too old (1 day)
final Calendar fromClient = Calendar.getInstance();
fromClient.setTime(new Date(input.currentDate()));
if(checkDate) {
//check if the client sent us a time which is way too old (1 day)
final Calendar fromClient = Calendar.getInstance();
fromClient.setTime(new Date(input.currentDate()));

final Calendar fromServerDayBefore = Calendar.getInstance();
fromServerDayBefore.add(Calendar.DAY_OF_YEAR, -1);
final Calendar fromServerDayBefore = Calendar.getInstance();
fromServerDayBefore.add(Calendar.DAY_OF_YEAR, -1);

if (fromClient.before(fromServerDayBefore)) {
return newInstance(input, Type.TIME_MISMATCH);
}
if (fromClient.before(fromServerDayBefore)) {
return newInstance(input, Type.TIME_MISMATCH);
}

final Calendar fromServerDayAfter = Calendar.getInstance();
fromServerDayAfter.add(Calendar.DAY_OF_YEAR, 1);
final Calendar fromServerDayAfter = Calendar.getInstance();
fromServerDayAfter.add(Calendar.DAY_OF_YEAR, 1);

if (fromClient.after(fromServerDayAfter)) {
return newInstance(input, Type.TIME_MISMATCH);
if (fromClient.after(fromServerDayAfter)) {
return newInstance(input, Type.TIME_MISMATCH);
}
}


Expand Down

0 comments on commit 480618b

Please sign in to comment.