From 943fe2340ea7b3177c4ecb4fd9a53b5a0cbbb2b0 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Thu, 20 Aug 2026 01:22:33 +0900 Subject: [PATCH] bn: support marshalling This fixes tests with Ruby master, where unshareable T_DATA is copied across Ractor via Marshal. --- lib/openssl/bn.rb | 8 ++++++++ test/openssl/test_bn.rb | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/openssl/bn.rb b/lib/openssl/bn.rb index e4889a140..3c3299d7d 100644 --- a/lib/openssl/bn.rb +++ b/lib/openssl/bn.rb @@ -23,6 +23,14 @@ def pretty_print(q) q.text to_i.to_s } end + + def marshal_dump # :nodoc: + to_i + end + + def marshal_load(integer) # :nodoc: + initialize(integer) + end end # BN end # OpenSSL diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb index f663102d4..4e565f090 100644 --- a/test/openssl/test_bn.rb +++ b/test/openssl/test_bn.rb @@ -315,6 +315,14 @@ def test_comparison assert_instance_of(String, @e1.hash.to_s) end + def test_marshal + assert_equal(@e1, Marshal.load(Marshal.dump(@e1))) + assert_equal(@e2, Marshal.load(Marshal.dump(@e2))) + + obj = Marshal.load("\x04\x08U:\x10OpenSSL::BNi\xfe\x01\x00") + assert_equal(-0xffff, obj) + end + def test_argument_error bug15760 = '[ruby-core:92231] [Bug #15760]' assert_raise(ArgumentError, bug15760) { OpenSSL::BN.new(nil, 2) }