1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/core/uuid.rb

23 lines
No EOL
458 B
Ruby

require 'securerandom'
module Fog
class UUID
class << self
def uuid
if supported?
SecureRandom.uuid
else
ary = SecureRandom.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
end
def supported?
SecureRandom.respond_to?(:uuid)
end
end
end
end