Skip to content

Commit 2d34e85

Browse files
committed
bn: make BN.pseudo_rand{,_range} an alias of BN.rand{,_range}
BN_pseudo_rand() and BN_pseudo_rand_range() are deprecated in OpenSSL 3.0. Since they are identical to their non-'pseudo' version anyway, let's make them alias.
1 parent d42bd7f commit 2d34e85

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

ext/openssl/ossl_bn.c

+2-16
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,6 @@ BIGNUM_SELF_SHIFT(rshift)
826826
*/
827827
BIGNUM_RAND(rand)
828828

829-
/*
830-
* Document-method: OpenSSL::BN.pseudo_rand
831-
* BN.pseudo_rand(bits [, fill [, odd]]) -> aBN
832-
*/
833-
BIGNUM_RAND(pseudo_rand)
834-
835829
#define BIGNUM_RAND_RANGE(func) \
836830
static VALUE \
837831
ossl_bn_s_##func##_range(VALUE klass, VALUE range) \
@@ -857,14 +851,6 @@ BIGNUM_RAND(pseudo_rand)
857851
*/
858852
BIGNUM_RAND_RANGE(rand)
859853

860-
/*
861-
* Document-method: OpenSSL::BN.pseudo_rand_range
862-
* call-seq:
863-
* BN.pseudo_rand_range(range) -> aBN
864-
*
865-
*/
866-
BIGNUM_RAND_RANGE(pseudo_rand)
867-
868854
/*
869855
* call-seq:
870856
* BN.generate_prime(bits, [, safe [, add [, rem]]]) => bn
@@ -1278,9 +1264,9 @@ Init_ossl_bn(void)
12781264
* get_word */
12791265

12801266
rb_define_singleton_method(cBN, "rand", ossl_bn_s_rand, -1);
1281-
rb_define_singleton_method(cBN, "pseudo_rand", ossl_bn_s_pseudo_rand, -1);
12821267
rb_define_singleton_method(cBN, "rand_range", ossl_bn_s_rand_range, 1);
1283-
rb_define_singleton_method(cBN, "pseudo_rand_range", ossl_bn_s_pseudo_rand_range, 1);
1268+
rb_define_alias(rb_singleton_class(cBN), "pseudo_rand", "rand");
1269+
rb_define_alias(rb_singleton_class(cBN), "pseudo_rand_range", "rand_range");
12841270

12851271
rb_define_singleton_method(cBN, "generate_prime", ossl_bn_s_generate_prime, -1);
12861272
rb_define_method(cBN, "prime?", ossl_bn_is_prime, -1);

test/openssl/test_bn.rb

+4
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ def test_random
248248
r5 = OpenSSL::BN.rand_range(256)
249249
assert_include(0..255, r5)
250250
}
251+
252+
# Aliases
253+
assert_include(128..255, OpenSSL::BN.pseudo_rand(8))
254+
assert_include(0..255, OpenSSL::BN.pseudo_rand_range(256))
251255
end
252256

253257
begin

0 commit comments

Comments
 (0)