Skip to content

Commit d603f5d

Browse files
authored
Merge pull request #2267 from ksss/openssl-raap
Fix type of `OpenSSL::BN` methods
2 parents 0ddf214 + ec4fc97 commit d603f5d

File tree

6 files changed

+96
-40
lines changed

6 files changed

+96
-40
lines changed

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ task :typecheck_test => :compile do
139139
end
140140

141141
task :raap => :compile do
142-
sh %q[ruby test/raap.rb | xargs bundle exec raap -r digest/bubblebabble --library digest --allow-private]
142+
sh "ruby test/raap/core.rb"
143+
sh "ruby test/raap/digest.rb"
144+
sh "ruby test/raap/openssl.rb"
143145
end
144146

145147
task :rubocop do

stdlib/openssl/0/openssl.rbs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,28 +1527,28 @@ module OpenSSL
15271527
# - bn % bn2 => aBN
15281528
# -->
15291529
#
1530-
def %: (int) -> instance
1530+
def %: (bn) -> instance
15311531

15321532
# <!--
15331533
# rdoc-file=ext/openssl/ossl_bn.c
15341534
# - bn * bn2 => aBN
15351535
# -->
15361536
#
1537-
def *: (int) -> instance
1537+
def *: (bn) -> instance
15381538

15391539
# <!--
15401540
# rdoc-file=ext/openssl/ossl_bn.c
15411541
# - bn ** bn2 => aBN
15421542
# -->
15431543
#
1544-
def **: (int) -> instance
1544+
def **: (bn) -> instance
15451545

15461546
# <!--
15471547
# rdoc-file=ext/openssl/ossl_bn.c
15481548
# - bn + bn2 => aBN
15491549
# -->
15501550
#
1551-
def +: (int) -> instance
1551+
def +: (bn) -> instance
15521552

15531553
# <!--
15541554
# rdoc-file=ext/openssl/ossl_bn.c
@@ -1562,7 +1562,7 @@ module OpenSSL
15621562
# - bn - bn2 => aBN
15631563
# -->
15641564
#
1565-
def -: (int) -> instance
1565+
def -: (bn) -> instance
15661566

15671567
# <!--
15681568
# rdoc-file=ext/openssl/ossl_bn.c
@@ -1577,7 +1577,7 @@ module OpenSSL
15771577
# -->
15781578
# Division of OpenSSL::BN instances
15791579
#
1580-
def /: (int) -> [ instance, instance ]
1580+
def /: (bn) -> [ instance, instance ]
15811581

15821582
# <!--
15831583
# rdoc-file=ext/openssl/ossl_bn.c
@@ -1635,7 +1635,7 @@ module OpenSSL
16351635
# - bn.cmp(bn2) => integer
16361636
# -->
16371637
#
1638-
def cmp: (Integer) -> Integer
1638+
def cmp: (bn) -> Integer
16391639

16401640
# <!--
16411641
# rdoc-file=ext/openssl/ossl_bn.c
@@ -1650,7 +1650,7 @@ module OpenSSL
16501650
# - copy(p1)
16511651
# -->
16521652
#
1653-
def copy: (int) -> instance
1653+
def copy: (bn) -> instance
16541654

16551655
# <!--
16561656
# rdoc-file=ext/openssl/ossl_bn.c
@@ -1666,7 +1666,7 @@ module OpenSSL
16661666
# - bn.gcd(bn2) => aBN
16671667
# -->
16681668
#
1669-
def gcd: (int) -> instance
1669+
def gcd: (bn) -> instance
16701670

16711671
# <!--
16721672
# rdoc-file=ext/openssl/ossl_bn.c
@@ -1692,42 +1692,42 @@ module OpenSSL
16921692
# - bn.mod_add(bn1, bn2) -> aBN
16931693
# -->
16941694
#
1695-
def mod_add: (int, int) -> instance
1695+
def mod_add: (bn, bn) -> instance
16961696

16971697
# <!--
16981698
# rdoc-file=ext/openssl/ossl_bn.c
16991699
# - bn.mod_exp(bn1, bn2) -> aBN
17001700
# -->
17011701
#
1702-
def mod_exp: (int, int) -> instance
1702+
def mod_exp: (bn, bn) -> instance
17031703

17041704
# <!--
17051705
# rdoc-file=ext/openssl/ossl_bn.c
17061706
# - bn.mod_inverse(bn2) => aBN
17071707
# -->
17081708
#
1709-
def mod_inverse: (int) -> instance
1709+
def mod_inverse: (bn) -> instance
17101710

17111711
# <!--
17121712
# rdoc-file=ext/openssl/ossl_bn.c
17131713
# - bn.mod_mul(bn1, bn2) -> aBN
17141714
# -->
17151715
#
1716-
def mod_mul: (int, int) -> instance
1716+
def mod_mul: (bn, bn) -> instance
17171717

17181718
# <!--
17191719
# rdoc-file=ext/openssl/ossl_bn.c
17201720
# - bn.mod_sqr(bn2) => aBN
17211721
# -->
17221722
#
1723-
def mod_sqr: (int) -> instance
1723+
def mod_sqr: (bn) -> instance
17241724

17251725
# <!--
17261726
# rdoc-file=ext/openssl/ossl_bn.c
17271727
# - bn.mod_sub(bn1, bn2) -> aBN
17281728
# -->
17291729
#
1730-
def mod_sub: (int, int) -> instance
1730+
def mod_sub: (bn, bn) -> instance
17311731

17321732
# <!--
17331733
# rdoc-file=ext/openssl/ossl_bn.c
@@ -1868,7 +1868,7 @@ module OpenSSL
18681868
# - bn.ucmp(bn2) => integer
18691869
# -->
18701870
#
1871-
def ucmp: (int bn2) -> ::Integer
1871+
def ucmp: (bn bn2) -> ::Integer
18721872

18731873
# <!--
18741874
# rdoc-file=ext/openssl/ossl_bn.c

test/raap/core.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'raap'
2+
3+
argv = [
4+
'--size-by', '2',
5+
'--allow-private'
6+
]
7+
8+
argv << 'Set[Integer]'
9+
argv << 'Enumerable[Integer]#to_set'
10+
11+
RaaP::CLI.new(argv).load.run

test/raap.rb renamed to test/raap/digest.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# Specify the class/module and method names to be executed by RaaP.
2-
# By prefixing with `!`, you can skip testing a method.
1+
require 'raap'
32

4-
puts 'Set[Integer]'
5-
puts 'Enumerable[Integer]#to_set'
3+
argv = [
4+
'-r', 'digest/bubblebabble',
5+
'--library', 'digest',
6+
'--size-by', '2',
7+
'--allow-private'
8+
]
69

710
%w[
811
MD5
@@ -18,7 +21,7 @@
1821
digest
1922
hexdigest
2023
].each do |singleton_method|
21-
puts "Digest::#{klass}.#{singleton_method}"
24+
argv << "Digest::#{klass}.#{singleton_method}"
2225
end
2326

2427
%w[
@@ -47,6 +50,8 @@
4750
finish
4851
initialize_copy
4952
].each do |instance_method|
50-
puts "Digest::#{klass}##{instance_method}"
53+
argv << "Digest::#{klass}##{instance_method}"
5154
end
5255
end
56+
57+
RaaP::CLI.new(argv).load.run

test/raap/openssl.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'raap'
2+
3+
RaaP::Type.register('OpenSSL::BN') do
4+
sized do |size|
5+
[:call, OpenSSL::BN, :new, [integer.pick(size: size)], {}, nil]
6+
end
7+
end
8+
9+
argv = [
10+
'--require', 'openssl',
11+
'--library', 'openssl',
12+
'--size-by', '2',
13+
'--log-level', 'info',
14+
]
15+
16+
%w[
17+
+
18+
-
19+
*
20+
/
21+
%
22+
**
23+
cmp
24+
copy
25+
gcd
26+
mod_add
27+
mod_exp
28+
mod_mul
29+
mod_sqr
30+
mod_sub
31+
ucmp
32+
].each do |instance_method|
33+
argv << "OpenSSL::BN##{instance_method}"
34+
end
35+
36+
RaaP::CLI.new(argv).load.run

test/stdlib/OpenSSL_test.rb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,25 @@ class OpenSSLBNTest < Test::Unit::TestCase
241241
library "openssl"
242242
testing "::OpenSSL::BN"
243243

244-
def test_operations
245-
assert_send_type "(::Integer) -> OpenSSL::BN",
246-
OpenSSL::BN.new(2), :%, 2
247-
assert_send_type "(::Integer) -> OpenSSL::BN",
248-
OpenSSL::BN.new(2), :*, 2
249-
assert_send_type "(::Integer) -> OpenSSL::BN",
250-
OpenSSL::BN.new(2), :**, 2
251-
assert_send_type "(::Integer) -> OpenSSL::BN",
252-
OpenSSL::BN.new(2), :+, 2
253-
assert_send_type "(::Integer) -> OpenSSL::BN",
254-
OpenSSL::BN.new(2), :-, 2
255-
assert_send_type "(::Integer) -> [OpenSSL::BN, OpenSSL::BN]",
256-
OpenSSL::BN.new(2), :/, 2
257-
assert_send_type "(::Integer) -> OpenSSL::BN",
258-
OpenSSL::BN.new(2), :<<, 2
259-
assert_send_type "(::Integer) -> OpenSSL::BN",
260-
OpenSSL::BN.new(2), :>>, 2
244+
def test_mod_inverse
245+
assert_send_type "(OpenSSL::BN) -> OpenSSL::BN",
246+
OpenSSL::BN.new(3), :mod_inverse, OpenSSL::BN.new(5)
247+
assert_send_type "(Integer) -> OpenSSL::BN",
248+
OpenSSL::BN.new(3), :mod_inverse, 5
249+
end
250+
251+
def test_lshift
252+
assert_send_type "(Integer) -> OpenSSL::BN",
253+
OpenSSL::BN.new(3), :<<, 1
254+
assert_send_type "(_ToInt) -> OpenSSL::BN",
255+
OpenSSL::BN.new(3), :<<, ToInt.new(1)
256+
end
257+
258+
def test_rshift
259+
assert_send_type "(Integer) -> OpenSSL::BN",
260+
OpenSSL::BN.new(3), :>>, 1
261+
assert_send_type "(_ToInt) -> OpenSSL::BN",
262+
OpenSSL::BN.new(3), :>>, ToInt.new(1)
261263
end
262264
end
263265

0 commit comments

Comments
 (0)