From 08709b41dcff33c779c7440526c86b5ec3362dad Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 3 Dec 2014 04:15:08 +0000 Subject: [PATCH] Replace ipOps.hex_to_bin with a simpler implementation. --- nselib/ipOps.lua | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/nselib/ipOps.lua b/nselib/ipOps.lua index b7e9089e9..eb0e6b0c2 100644 --- a/nselib/ipOps.lua +++ b/nselib/ipOps.lua @@ -9,8 +9,7 @@ local stdnse = require "stdnse" local string = require "string" local table = require "table" local type = type -local table = table -local string = string +local select = select local ipairs = ipairs local tonumber = tonumber local unittest = require "unittest" @@ -635,8 +634,7 @@ end -- Converts a string of hexadecimal digits into the corresponding string of -- binary digits. -- --- Each hex digit results in four bits. This function is really just a wrapper --- around stdnse.tobinary. +-- Each hex digit results in four bits. -- @param hex String representing a hexadecimal number. -- @usage -- bin_string = ipOps.hex_to_bin( "F00D" ) @@ -649,13 +647,8 @@ hex_to_bin = function( hex ) return nil, "Error in ipOps.hex_to_bin: Expected string representing a hexadecimal number." end - local t, mask, binchar = {}, "0000" - for hexchar in string.gmatch( hex, "%x" ) do - binchar = stdnse.tobinary( tonumber( hexchar, 16 ) ) - t[#t+1] = mask:sub( 1, # mask - # binchar ) .. binchar - end - return table.concat( t ) - + local d = bin.pack("H", hex) + return select(2, bin.unpack("B" .. #d, d)) end --Ignore the rest if we are not testing.