Added hash checker / removed redundant setters for safety

This commit is contained in:
Marcin Kostrzewski 2020-10-28 17:25:08 +01:00
parent 0cbdd1a10a
commit 3dd55f3a32

View File

@ -52,6 +52,22 @@ public class Commitment {
public Commitment() {
}
public boolean checkHash() {
boolean result = false;
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(this.sequenceA);
digest.update(this.sequenceB);
digest.update(this.message.getBytes(StandardCharsets.UTF_8));
result = this.hash == digest.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return result;
}
public String getMessage() {
return message;
}
@ -72,15 +88,8 @@ public class Commitment {
this.message = message;
}
public void setSequenceA(byte[] sequenceA) {
this.sequenceA = sequenceA;
}
public void setSequenceB(byte[] sequenceB) {
this.sequenceB = sequenceB;
}
public void setHash(byte[] hash) {
this.hash = hash;
}
}