From 87fe985f32a0d3d545d4a53b15c974d08f267be7 Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 7 Dec 2021 19:50:47 +0000 Subject: [PATCH] Move a reused function out to file scope --- nselib/stdnse.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index b67b475ef..399b51ff5 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -278,6 +278,9 @@ function tooctal(n) return format("%o", n) end +local tohex_helper = function(b) + return format("%02x", byte(b)) +end --- Encode a string or integer in hexadecimal (12 becomes "c", "AB" becomes -- "4142"). -- @@ -303,9 +306,7 @@ function tohex( s, options ) if type( s ) == "number" then hex = format("%x", s) elseif type( s ) == 'string' then - hex = gsub(s, ".", function(b) - return format("%02x", byte(b)) - end) + hex = gsub(s, ".", tohex_helper) else error( "Type not supported in tohex(): " .. type(s), 2 ) end