mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Fix missing urandom by using OpenSSL's random_bytes
This commit is contained in:
parent
0727bed62f
commit
5de7bd65a3
1 changed files with 32 additions and 0 deletions
32
config/initializers/00_random.rb
Normal file
32
config/initializers/00_random.rb
Normal 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
|
||||
Loading…
Reference in a new issue