aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2021-04-15 23:38:18 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-04-15 23:39:40 +0900
commitc790ce51bb12c38673774cd58c063e486ce612bd (patch)
tree969b03ca07f4a6edd0593dbe5c8b04fb1e592501
parentd172036b4a3e137107a35f2f7818e01b9b4d630d (diff)
downloadruby-openssl-ky/bn-inspect.tar.gz
bn: add OpenSSL::BN#inspectky/bn-inspect
-rw-r--r--lib/openssl/bn.rb5
-rw-r--r--test/openssl/test_bn.rb5
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/openssl/bn.rb b/lib/openssl/bn.rb
index 0a5e11b4..aff99f8a 100644
--- a/lib/openssl/bn.rb
+++ b/lib/openssl/bn.rb
@@ -17,10 +17,15 @@ module OpenSSL
class BN
include Comparable
+ def inspect
+ "#<%s %s (%d bit)>" % [self.class, to_s(16), num_bits]
+ end
+
def pretty_print(q)
q.object_group(self) {
q.text ' '
q.text to_i.to_s
+ q.text " (#{num_bits} bit)"
}
end
end # BN
diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb
index 1ed4bbee..a365b86e 100644
--- a/test/openssl/test_bn.rb
+++ b/test/openssl/test_bn.rb
@@ -2,6 +2,7 @@
# frozen_string_literal: true
require_relative 'utils'
require "prime"
+require "pp"
if defined?(OpenSSL)
@@ -73,6 +74,10 @@ class OpenSSL::TestBN < OpenSSL::TestCase
assert_equal("\x00\x00\x00\x0e\x87\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", @e4.to_s(0))
end
+ def test_inspect
+ assert_equal("#<OpenSSL::BN 04D2 (11 bit)>", 1234.to_bn.inspect)
+ end
+
def test_to_int
assert_equal(999, @e1.to_i)
assert_equal(-999, @e2.to_i)