From 793ad7474878eca9e689864746e0e4f940dc90d9 Mon Sep 17 00:00:00 2001 From: etcusrvar Date: Thu, 19 Jun 2025 10:25:25 -0500 Subject: [PATCH 1/2] use openssl when urandom fails --- lib/tmpdir.rb | 12 +++++++++++- tmpdir.gemspec | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index f78fd72..723befe 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -149,7 +149,17 @@ class << RANDOM # :nodoc: # Returns new random string upto 6 bytes def next - (::Random.urandom(4).unpack1("L")%MAX).to_s(36) + begin + (::Random.urandom(4).unpack1("L")%MAX).to_s(36) + rescue RuntimeError + begin + require 'openssl' + rescue NoMethodError + raise NotImplementedError, "No random device" + else + (OpenSSL::Random.random_bytes(4).unpack1("L")%MAX).to_s(36) + end + end end end RANDOM.freeze diff --git a/tmpdir.gemspec b/tmpdir.gemspec index 4935d1c..ebe8fe4 100644 --- a/tmpdir.gemspec +++ b/tmpdir.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = "tmpdir" - spec.version = "0.3.1" + spec.version = "0.3.2" spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] From c2215dc6a056903890817a3471a96d222b967447 Mon Sep 17 00:00:00 2001 From: etcusrvar Date: Thu, 19 Jun 2025 18:13:48 -0500 Subject: [PATCH 2/2] don't bump version --- tmpdir.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpdir.gemspec b/tmpdir.gemspec index ebe8fe4..4935d1c 100644 --- a/tmpdir.gemspec +++ b/tmpdir.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = "tmpdir" - spec.version = "0.3.2" + spec.version = "0.3.1" spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"]