module(... or "uuid", package.seeall) require("bin") require("stdnse") UUID = { new = function(self, uuid_str) local o = {} setmetatable(o, self) self.__index = self o.uuid_str = uuid_str or "01234567-89ab-cdef-0123-456789abcdef" return o end, set = function(self, uuid_str) self.uuid_str = uuid_str end , get = function(self) return self.uuid_str end , --[[ 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | time_low | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | time_mid | time_hi_and_version | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |clk_seq_hi_res | clk_seq_low | node (0-1) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | node (2-5) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ]]-- getRaw = function(self) local uuid_raw = strtoraw(self.uuid_str) return uuid_raw end } function strtoraw(uuid_str) local uuid_raw local time_low_str, time_mid_str, time_hi_and_version_str, clk_seq_hi_res_low_str, node_str = unpack(stdnse.strsplit("-", uuid_str)) local node_raw = bin.pack("CCCCCC", tonumber("0x" .. string.sub(node_str,1,2)), tonumber("0x" .. string.sub(node_str,3,4)), tonumber("0x" .. string.sub(node_str,5,6)), tonumber("0x" .. string.sub(node_str,7,8)), tonumber("0x" .. string.sub(node_str,9,10)), tonumber("0x" .. string.sub(node_str,11,12)) ) uuid_raw = bin.pack("=ISSCCA", tonumber("0x" .. time_low_str), tonumber("0x" .. time_mid_str), tonumber("0x" .. time_hi_and_version_str), tonumber("0x" .. string.sub(clk_seq_hi_res_low_str, 1, 2)), tonumber("0x" .. string.sub(clk_seq_hi_res_low_str, 3, 4)), node_raw ) return uuid_raw end