зеркало из https://github.com/github/ruby.git
* lib/securerandom.rb (SecureRandom.uuid): uses unpacked array
instead of string, because String#[] returns one length string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
f226c38630
Коммит
f10e2af1e6
|
@ -1,3 +1,8 @@
|
|||
Thu Jan 29 13:16:11 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* lib/rake.rb (FileUtils#rake_system): no longer needs workaround
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче