[前][次][番号順一覧][スレッド一覧]

ruby-changes:29862

From: zzak <ko1@a...>
Date: Thu, 11 Jul 2013 13:01:57 +0900 (JST)
Subject: [ruby-changes:29862] zzak:r41914 (trunk): * lib/securerandom.rb: Refactor conditions by Rafal Chmiel

zzak	2013-07-11 13:01:47 +0900 (Thu, 11 Jul 2013)

  New Revision: 41914

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41914

  Log:
    * lib/securerandom.rb: Refactor conditions by Rafal Chmiel
      [Fixes GH-326] https://github.com/ruby/ruby/pull/326

  Modified files:
    trunk/ChangeLog
    trunk/lib/securerandom.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41913)
+++ ChangeLog	(revision 41914)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jul 11 13:00:34 2013  Zachary Scott  <e@z...>
+
+	* 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@f...>
 
 	* bignum.c: Don't use toom3 after once karatsuba is choosen.
Index: lib/securerandom.rb
===================================================================
--- lib/securerandom.rb	(revision 41913)
+++ lib/securerandom.rb	(revision 41914)
@@ -51,9 +51,9 @@ module SecureRandom https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb#L51
     n = n ? n.to_int : 16
 
     if defined? OpenSSL::Random
-      @pid = 0 if !defined?(@pid)
+      @pid = 0 unless defined?(@pid)
       pid = $$
-      if @pid != pid
+      unless @pid == pid
         now = Time.now
         ary = [now.to_i, now.nsec, @pid, pid]
         OpenSSL::Random.random_add(ary.join("").to_s, 0.0)
@@ -73,7 +73,7 @@ module SecureRandom https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb#L73
           end
           @has_urandom = true
           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"
           end
           return ret
@@ -83,7 +83,7 @@ module SecureRandom https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb#L83
       end
     end
 
-    if !defined?(@has_win32)
+    unless defined?(@has_win32)
       begin
         require 'Win32API'
 
@@ -186,7 +186,7 @@ module SecureRandom https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb#L186
     s = [random_bytes(n)].pack("m*")
     s.delete!("\n")
     s.tr!("+/", "-_")
-    s.delete!("=") if !padding
+    s.delete!("=") unless padding
     s
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]