* lib/securerandom.rb: Refactor conditions by Rafal Chmiel
[Fixes GH-326] https://github.com/ruby/ruby/pull/326 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
973d855391
commit
84247a63ce
@ -1,3 +1,8 @@
|
|||||||
|
Thu Jul 11 13:00:34 2013 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
|
* lib/securerandom.rb: Refactor conditions by Rafal Chmiel
|
||||||
|
[Fixes GH-326] https://github.com/ruby/ruby/pull/326
|
||||||
|
|
||||||
Thu Jul 11 12:04:47 2013 Tanaka Akira <akr@fsij.org>
|
Thu Jul 11 12:04:47 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c: Don't use toom3 after once karatsuba is choosen.
|
* bignum.c: Don't use toom3 after once karatsuba is choosen.
|
||||||
|
@ -51,9 +51,9 @@ module SecureRandom
|
|||||||
n = n ? n.to_int : 16
|
n = n ? n.to_int : 16
|
||||||
|
|
||||||
if defined? OpenSSL::Random
|
if defined? OpenSSL::Random
|
||||||
@pid = 0 if !defined?(@pid)
|
@pid = 0 unless defined?(@pid)
|
||||||
pid = $$
|
pid = $$
|
||||||
if @pid != pid
|
unless @pid == pid
|
||||||
now = Time.now
|
now = Time.now
|
||||||
ary = [now.to_i, now.nsec, @pid, pid]
|
ary = [now.to_i, now.nsec, @pid, pid]
|
||||||
OpenSSL::Random.random_add(ary.join("").to_s, 0.0)
|
OpenSSL::Random.random_add(ary.join("").to_s, 0.0)
|
||||||
@ -73,7 +73,7 @@ module SecureRandom
|
|||||||
end
|
end
|
||||||
@has_urandom = true
|
@has_urandom = true
|
||||||
ret = f.read(n)
|
ret = f.read(n)
|
||||||
if ret.length != n
|
unless ret.length == n
|
||||||
raise NotImplementedError, "Unexpected partial read from random device: only #{ret.length} for #{n} bytes"
|
raise NotImplementedError, "Unexpected partial read from random device: only #{ret.length} for #{n} bytes"
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
@ -83,7 +83,7 @@ module SecureRandom
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !defined?(@has_win32)
|
unless defined?(@has_win32)
|
||||||
begin
|
begin
|
||||||
require 'Win32API'
|
require 'Win32API'
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ module SecureRandom
|
|||||||
s = [random_bytes(n)].pack("m*")
|
s = [random_bytes(n)].pack("m*")
|
||||||
s.delete!("\n")
|
s.delete!("\n")
|
||||||
s.tr!("+/", "-_")
|
s.tr!("+/", "-_")
|
||||||
s.delete!("=") if !padding
|
s.delete!("=") unless padding
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user