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

ruby-changes:10328

From: nobu <ko1@a...>
Date: Thu, 29 Jan 2009 13:16:38 +0900 (JST)
Subject: [ruby-changes:10328] Ruby:r21872 (trunk): * lib/securerandom.rb (SecureRandom.uuid): uses unpacked array

nobu	2009-01-29 13:16:17 +0900 (Thu, 29 Jan 2009)

  New Revision: 21872

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

  Log:
    * lib/securerandom.rb (SecureRandom.uuid): uses unpacked array
      instead of string, because String#[] returns one length string.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21871)
+++ ChangeLog	(revision 21872)
@@ -1,3 +1,8 @@
+Thu Jan 29 13:16:11 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/securerandom.rb (SecureRandom.uuid): uses unpacked array
+	  instead of string, because String#[] returns one length string.
+
 Thu Jan 29 12:29:51 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/rake.rb (FileUtils#rake_system): no longer needs workaround
Index: lib/securerandom.rb
===================================================================
--- lib/securerandom.rb	(revision 21871)
+++ lib/securerandom.rb	(revision 21872)
@@ -169,11 +169,9 @@
 
   # SecureRandom.uuid generates a v4 random UUID.
   def self.uuid
-    str = self.random_bytes(16)
-    str[6] = (str[6] & 0x0f) | 0x40
-    str[8] = (str[8] & 0x3f) | 0x80
-
-    ary = str.unpack("NnnnnN")
+    ary = self.random_bytes(16).unpack("NnnnnN")
+    ary[2] = (ary[2] & 0x0fff) | 0x4000
+    ary[3] = (ary[3] & 0x3fff) | 0x8000
     "%08x-%04x-%04x-%04x-%04x%08x" % ary
   end
 

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

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