aboutsummaryrefslogtreecommitdiffstats
path: root/rules/bitcoin.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-08-07 11:41:28 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-08-07 11:41:28 +0100
commit662145d0554de5e769b92dab2d41173a98adcee5 (patch)
treeec28311a0bce6181f248ba7b50304293ad764e44 /rules/bitcoin.lua
parentbbd88232db43d18f5e0de5a6502848d4074621c5 (diff)
downloadrspamd-662145d0554de5e769b92dab2d41173a98adcee5.tar.gz
rspamd-662145d0554de5e769b92dab2d41173a98adcee5.zip
[Minor] Reformat all Lua code, no functional changes
Diffstat (limited to 'rules/bitcoin.lua')
-rw-r--r--rules/bitcoin.lua25
1 files changed, 14 insertions, 11 deletions
diff --git a/rules/bitcoin.lua b/rules/bitcoin.lua
index 1c902e93e..6a70721f8 100644
--- a/rules/bitcoin.lua
+++ b/rules/bitcoin.lua
@@ -26,7 +26,7 @@ local off = 0
local base58_dec = fun.tomap(fun.map(
function(c)
off = off + 1
- return c,(off - 1)
+ return c, (off - 1)
end,
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"))
@@ -34,11 +34,13 @@ local function is_traditional_btc_address(word)
local hash = require "rspamd_cryptobox_hash"
local bytes = {}
- for i=1,25 do bytes[i] = 0 end
+ for i = 1, 25 do
+ bytes[i] = 0
+ end
-- Base58 decode loop
fun.each(function(ch)
local acc = base58_dec[ch] or 0
- for i=25,1,-1 do
+ for i = 25, 1, -1 do
acc = acc + (58 * bytes[i]);
bytes[i] = acc % 256
acc = math.floor(acc / 256);
@@ -46,14 +48,14 @@ local function is_traditional_btc_address(word)
end, word)
-- Now create a validation tag
local sha256 = hash.create_specific('sha256')
- for i=1,21 do
+ for i = 1, 21 do
sha256:update(string.char(bytes[i]))
end
sha256 = hash.create_specific('sha256', sha256:bin()):bin()
-- Compare tags
local valid = true
- for i=1,4 do
+ for i = 1, 4 do
if string.sub(sha256, i, i) ~= string.char(bytes[21 + i]) then
valid = false
end
@@ -65,13 +67,13 @@ end
-- Beach32 checksum combiner
local function polymod(...)
local chk = 1;
- local gen = {0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3};
- for _,t in ipairs({...}) do
- for _,v in ipairs(t) do
+ local gen = { 0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3 };
+ for _, t in ipairs({ ... }) do
+ for _, v in ipairs(t) do
local top = bit.rshift(chk, 25)
chk = bit.bxor(bit.lshift(bit.band(chk, 0x1ffffff), 5), v)
- for i=1,5 do
+ for i = 1, 5 do
if bit.band(bit.rshift(top, i - 1), 0x1) ~= 0 then
chk = bit.bxor(chk, gen[i])
end
@@ -100,7 +102,6 @@ local function verify_beach32_cksum(hrp, elts)
return polymod(hrpExpand(hrp), elts) == 1
end
-
local function gen_bleach32_table(input)
local d = {}
local i = 1
@@ -167,7 +168,9 @@ local function is_segwit_bech32_address(task, word)
-- For semicolon
table.insert(polymod_tbl, 0)
- fun.each(function(byte) table.insert(polymod_tbl, byte) end, decoded)
+ fun.each(function(byte)
+ table.insert(polymod_tbl, byte)
+ end, decoded)
lua_util.debugm(N, task, 'final polymod table: %s', polymod_tbl)
return rspamd_util.btc_polymod(polymod_tbl)