diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-29 04:16:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-29 04:16:17 +0000 |
commit | 2ff37a1a29c2f3c5950f56c905ca4b545726e1a2 (patch) | |
tree | b54148386a0cb65054b5d6f387254b2051c408ae /lib | |
parent | a7c3322f66438a67bc3b42cdeb1c3d8579a02bdb (diff) | |
download | ruby-2ff37a1a29c2f3c5950f56c905ca4b545726e1a2.tar.gz ruby-2ff37a1a29c2f3c5950f56c905ca4b545726e1a2.tar.xz ruby-2ff37a1a29c2f3c5950f56c905ca4b545726e1a2.zip |
* lib/securerandom.rb (SecureRandom.uuid): uses unpacked array
instead of string, because String#[] returns one length string.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@21872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/securerandom.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb index 0582cee72..e317c4c45 100644 --- a/lib/securerandom.rb +++ b/lib/securerandom.rb @@ -169,11 +169,9 @@ module SecureRandom # 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 |