From 8f5b133c60ed0064a081a8222a110f4fb09a73db Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 6 Oct 2013 23:17:05 +0200 Subject: util.sasl.scram: Remove unused function and import --- util/sasl/scram.lua | 9 --------- 1 file changed, 9 deletions(-) diff --git a/util/sasl/scram.lua b/util/sasl/scram.lua index 9dd7fdf8..d89eb872 100644 --- a/util/sasl/scram.lua +++ b/util/sasl/scram.lua @@ -13,7 +13,6 @@ local s_match = string.match; local type = type -local tostring = tostring; local base64 = require "util.encodings".base64; local hmac_sha1 = require "util.hashes".hmac_sha1; local sha1 = require "util.hashes".sha1; @@ -47,14 +46,6 @@ Supported Channel Binding Backends local default_i = 4096 -local function bp( b ) - local result = "" - for i=1, b:len() do - result = result.."\\"..b:byte(i) - end - return result -end - local xor_map = {0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;1;0;3;2;5;4;7;6;9;8;11;10;13;12;15;14;2;3;0;1;6;7;4;5;10;11;8;9;14;15;12;13;3;2;1;0;7;6;5;4;11;10;9;8;15;14;13;12;4;5;6;7;0;1;2;3;12;13;14;15;8;9;10;11;5;4;7;6;1;0;3;2;13;12;15;14;9;8;11;10;6;7;4;5;2;3;0;1;14;15;12;13;10;11;8;9;7;6;5;4;3;2;1;0;15;14;13;12;11;10;9;8;8;9;10;11;12;13;14;15;0;1;2;3;4;5;6;7;9;8;11;10;13;12;15;14;1;0;3;2;5;4;7;6;10;11;8;9;14;15;12;13;2;3;0;1;6;7;4;5;11;10;9;8;15;14;13;12;3;2;1;0;7;6;5;4;12;13;14;15;8;9;10;11;4;5;6;7;0;1;2;3;13;12;15;14;9;8;11;10;5;4;7;6;1;0;3;2;14;15;12;13;10;11;8;9;6;7;4;5;2;3;0;1;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;}; local result = {}; -- cgit v1.2.3 From 04699a3aa4f2f86e841941ad49a02d2f5f21f8fc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 6 Oct 2013 23:18:54 +0200 Subject: util.array: Improve array:reverse() and make it work as both method and non-mutating function --- util/array.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/util/array.lua b/util/array.lua index 9bf215af..6f2abe04 100644 --- a/util/array.lua +++ b/util/array.lua @@ -11,6 +11,7 @@ local t_insert, t_sort, t_remove, t_concat local setmetatable = setmetatable; local math_random = math.random; +local math_floor = math.floor; local pairs, ipairs = pairs, ipairs; local tostring = tostring; @@ -84,6 +85,25 @@ function array_base.pluck(outa, ina, key) return outa; end +function array_base.reverse(outa, ina) + local len = #ina; + if ina == outa then + local middle = math_floor(len/2); + len = len + 1; + local o; -- opposite + for i = 1, middle do + o = len - i; + outa[i], outa[o] = outa[o], outa[i]; + end + else + local off = len + 1; + for i = 1, len do + outa[i] = ina[off - i]; + end + end + return outa; +end + --- These methods only mutate the array function array_methods:shuffle(outa, ina) local len = #self; @@ -94,15 +114,6 @@ function array_methods:shuffle(outa, ina) return self; end -function array_methods:reverse() - local len = #self-1; - for i=len,1,-1 do - self:push(self[i]); - self:pop(i); - end - return self; -end - function array_methods:append(array) local len,len2 = #self, #array; for i=1,len2 do -- cgit v1.2.3