Skip to content

Commit 819559a

Browse files
committed
refactor naming of "get"-ers returning random values/integers
1 parent 64bb86f commit 819559a

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/main/java/org/jruby/ext/openssl/BN.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -794,28 +794,28 @@ public static BigInteger getRandomBI(int bits, int top, boolean bottom, Random r
794794

795795
@JRubyMethod(name = "rand_range", meta = true)
796796
public static IRubyObject rand_range(IRubyObject recv, IRubyObject arg) {
797-
return getRandomBNInRange(recv.getRuntime(), getBigInteger(arg), getSecureRandom());
797+
return randomValueInRange(recv.getRuntime(), getBigInteger(arg), getSecureRandom());
798798
}
799799

800800
@JRubyMethod(name = "pseudo_rand_range", meta = true)
801801
public static IRubyObject pseudo_rand_range(IRubyObject recv, IRubyObject arg) {
802-
return getRandomBNInRange(recv.getRuntime(), getBigInteger(arg), getRandom());
802+
return randomValueInRange(recv.getRuntime(), getBigInteger(arg), getRandom());
803803
}
804804

805-
private static BN getRandomBNInRange(Ruby runtime, BigInteger limit, Random random) {
805+
private static BN randomValueInRange(Ruby runtime, BigInteger limit, Random random) {
806806
BigInteger value;
807807
try {
808-
value = getRandomBIInRange(limit, random);
808+
value = randomIntegerInRange(limit, random);
809809
}
810810
catch (IllegalArgumentException e) {
811-
throw newBNError(runtime, "illegal range");
811+
throw newBNError(runtime, e.getMessage());
812812
}
813-
return newBN(runtime, value);
813+
return newInstance(runtime, value);
814814
}
815815

816-
public static BigInteger getRandomBIInRange(BigInteger limit, Random random) {
816+
public static BigInteger randomIntegerInRange(BigInteger limit, Random random) {
817817
if (limit.signum() < 0) {
818-
throw new IllegalArgumentException("illegal range");
818+
throw new IllegalArgumentException("illegal range: " + limit);
819819
}
820820
int bits = limit.bitLength();
821821
BigInteger value;

src/main/java/org/jruby/ext/openssl/PKeyDH.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import org.jruby.util.ByteList;
6161
import org.jruby.runtime.Visibility;
6262

63-
import static org.jruby.ext.openssl.PKey._PKey;
6463
import static org.jruby.ext.openssl.OpenSSL.bcExceptionMessage;
6564

6665
/**
@@ -209,9 +208,9 @@ public static BigInteger generateX(BigInteger p, int limit) {
209208
// subject to Miller-Rabin [certainty = 0], but is subject to other constraints)
210209
// see also [ossl]/crypto/dh/dh_key.c #generate_key
211210
if (limit == 0) {
212-
BigInteger pSub2 = p.subtract(TWO);
211+
final BigInteger pSub2 = p.subtract(TWO);
213212
do {
214-
x = BN.getRandomBIInRange(pSub2, secureRandom);
213+
x = BN.randomIntegerInRange(pSub2, secureRandom);
215214
} while (x.equals(BigInteger.ZERO));
216215
} else {
217216
do {

0 commit comments

Comments
 (0)