Skip to content

Commit

Permalink
lightsail-network#410: removed unnecessary guard check on hint length…
Browse files Browse the repository at this point in the history
… and cleaned up byte expressions in test
  • Loading branch information
sreuland authored and Vincent Amouret committed Apr 30, 2022
1 parent ee3b7ba commit e091847
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/stellar/sdk/KeyPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public DecoratedSignature signPayloadDecorated(byte[] signerPayload) {

//XOR the new hint with this keypair's public key hint
for (int i = 0; i < hint.length; i++) {
hint[i] ^= (i < payloadSignature.getHint().getSignatureHint().length ? payloadSignature.getHint().getSignatureHint()[i] : 0);
hint[i] ^= payloadSignature.getHint().getSignatureHint()[i];
}
payloadSignature.getHint().setSignatureHint(hint);
return payloadSignature;
Expand Down
13 changes: 2 additions & 11 deletions src/test/java/org/stellar/sdk/KeyPairTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ public void testSignPayloadSigner() {

byte[] payload = new byte[]{1,2,3,4,5};
DecoratedSignature sig = keypair.signPayloadDecorated(payload);
Assert.assertArrayEquals(sig.getHint().getSignatureHint(), new byte[]{
(byte)(0xFF & 252),
(byte)(0xFF & 65),
(byte)(0),
(byte)(0xFF & 50)});
Assert.assertArrayEquals(sig.getHint().getSignatureHint(), new byte[]{(byte)(0xFF & 252), 65, 0, 50});

}

Expand All @@ -114,11 +110,6 @@ public void testSignPayloadSignerLessThanHint() {
byte[] payload = new byte[]{1,2,3};
DecoratedSignature sig = keypair.signPayloadDecorated(payload);
// the hint could only be derived off of 3 bytes from payload
Assert.assertArrayEquals(sig.getHint().getSignatureHint(), new byte[]{
(byte)(255),
(byte)(0xFF & 64),
(byte)(0xFF & 7),
(byte)(0xFF & 55)});

Assert.assertArrayEquals(sig.getHint().getSignatureHint(), new byte[]{(byte)(255), 64, 7, 55});
}
}

0 comments on commit e091847

Please sign in to comment.