Skip to content

Commit

Permalink
Fixes codahale#15 generator test uses random source
Browse files Browse the repository at this point in the history
  • Loading branch information
simbo1905 committed Jun 15, 2019
1 parent f44e1ce commit b4a268f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/test/java/com/codahale/shamir/GF256Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,22 @@ void eval() {
assertThat(GF256.eval(new byte[] {1, 0, 2, 3}, (byte) 2)).isEqualTo((byte) 17);
}

private static class ZeroLastByteFirstAttemptRandom extends SecureRandom {
private int counter = 2;

@Override
public void nextBytes(byte[] b) {
super.nextBytes(b);
if (counter > 0) {
b[b.length - 1] = 0;
counter--;
}
}
}

@Test
void generate() {
final SecureRandom random = new SecureRandom();
final SecureRandom random = new ZeroLastByteFirstAttemptRandom();
final byte[] p = GF256.generate(random, 5, (byte) 20);
assertThat(p[0]).isEqualTo((byte) 20);
assertThat(p.length).isEqualTo(6);
Expand Down

0 comments on commit b4a268f

Please sign in to comment.