[ruby-cvs:67018] mame:r59840 (trunk): lib/securerandom.rb: test one byte to determine urandom or openssl

mame at ruby-lang.org mame at ruby-lang.org
Mon Sep 11 21:44:52 JST 2017


mame	2017-09-11 21:44:51 +0900 (Mon, 11 Sep 2017)

  New Revision: 59840

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59840

  Log:
    lib/securerandom.rb: test one byte to determine urandom or openssl
    
    `SecureRandom#gen_random` determines whether urandom is available or not
    by trying `Random.urandom(n)`.  But, when n = 0, `Random.urandom(0)`
    always succeeds even if urandom is not available, which leads to a wrong
    decision.
    
    When failed, `Random.urandom` returns nil instead of returning a shorter
    string than required.  So the check for `ret.length != n` is not needed.

  Modified files:
    trunk/lib/securerandom.rb


More information about the ruby-cvs mailing list