Merge pull request #280 from saschazepter/fix/use-openssl-urandom

Fix missing urandom by using OpenSSL's random_bytes
This commit is contained in:
Evgenii Burmakin 2024-10-19 22:57:28 +02:00 committed by GitHub
commit 5accd16deb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,32 @@
# -*- coding: us-ascii -*-
# frozen_string_literal: true
class Random
class << self
private
# :stopdoc:
# Implementation using OpenSSL
def gen_random_openssl(n)
return OpenSSL::Random.random_bytes(n)
end
begin
# Check if Random.urandom is available
Random.urandom(1)
rescue RuntimeError
begin
require 'openssl'
rescue NoMethodError
raise NotImplementedError, "No random device"
else
alias urandom gen_random_openssl
end
end
public :urandom
end
end