Skip to content

Commit 46dc6e0

Browse files
authored
Merge pull request #12 from RUB-NDS/fixedRandom
Add a fixed random class for testing purposes [BadFixedRandom]
2 parents 2819933 + 0eb1488 commit 46dc6e0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2016 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.modifiablevariable.util;
10+
11+
import java.util.Random;
12+
13+
/**
14+
* A fake random number generator for testing.
15+
* This generator will always return the byte "retVal" passed to the constructor.
16+
*
17+
*/
18+
public class BadFixedRandom extends Random {
19+
20+
byte retVal;
21+
22+
public BadFixedRandom(byte retVal) {
23+
this.retVal = retVal;
24+
}
25+
26+
/**
27+
* Fills a user-supplied byte array with the fixed byte given at object initialization.
28+
* The number of "random" bytes produced is equal to the length of the byte array.
29+
*/
30+
@Override
31+
public void nextBytes(byte[] bytes) {
32+
for (int i = 0, len = bytes.length; i < len;)
33+
bytes[i++] = retVal;
34+
}
35+
36+
}

0 commit comments

Comments
 (0)