mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/securerandom.rb: new method SecureRandom#uuid
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
68db4a3464
commit
7dd1a098a6
2 changed files with 14 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Jan 29 12:18:54 2009 Technorama Ltd. <oss-ruby@technorama.net>
|
||||
|
||||
* lib/securerandom.rb: new method SecureRandom#uuid
|
||||
|
||||
Thu Jan 29 11:22:19 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* ext/socket/raddrinfo.c (inspect_sockaddr): if defined AF_INET6,
|
||||
|
|
|
@ -167,6 +167,16 @@ module SecureRandom
|
|||
end
|
||||
end
|
||||
|
||||
# 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")
|
||||
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
||||
end
|
||||
|
||||
# Following code is based on David Garamond's GUID library for Ruby.
|
||||
def self.lastWin32ErrorMessage # :nodoc:
|
||||
get_last_error = Win32API.new("kernel32", "GetLastError", '', 'L')
|
||||
|
|
Loading…
Add table
Reference in a new issue