From b4a268f4ffb9917d7978bf2fc496cf22c8948236 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sat, 15 Jun 2019 07:34:36 +0100 Subject: [PATCH] Fixes #15 generator test uses random source --- src/test/java/com/codahale/shamir/GF256Test.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/codahale/shamir/GF256Test.java b/src/test/java/com/codahale/shamir/GF256Test.java index 079488c..bffc34d 100644 --- a/src/test/java/com/codahale/shamir/GF256Test.java +++ b/src/test/java/com/codahale/shamir/GF256Test.java @@ -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);