1rspamd_config:register_symbol({
2  name = 'TEST_HASHES',
3  score = 1.0,
4  callback = function()
5    local hash = require 'rspamd_cryptobox_hash'
6    local logger = require 'rspamd_logger'
7
8    local worry = {}
9    local test_data = {
10      {
11        ['str'] = 'asdf.qwerty.123',
12        ['hex'] = 'bf22dd95750034b9af93f0e4e5954aca3506bbcdbc051d91bd9af2d1a8fc294e848626b1c1751e58b44c4d3ea69dec5efa5a214dc59c77b1a9ca3bde3babac9d',
13      },
14      {
15        ['specific'] = 'md5',
16        ['str'] = 'asdf.qwerty.123',
17        ['hex'] = 'cf25ddc406c50de0c13de2b79d127646',
18      },
19      {
20        ['init'] = 'asdf.qwerty.123',
21        ['str'] = 'asdf.qwerty.123',
22        ['hex'] = 'bf22dd95750034b9af93f0e4e5954aca3506bbcdbc051d91bd9af2d1a8fc294e848626b1c1751e58b44c4d3ea69dec5efa5a214dc59c77b1a9ca3bde3babac9d',
23        ['reset'] = true,
24      },
25      {
26        ['init'] = 'asdf.qwerty.123',
27        ['str'] = 'asdf.qwerty.123',
28        ['hex'] = 'e445046aa21a705dcce1343795630f88bc0196a0070011fdce789d5a2a349a8f85349834ade555ca21439f65fdc4dbcf82dcff7fcc559ef11c508507515c1532',
29      },
30      {
31        ['init'] = 'asdf.qwerty.123',
32        ['specific'] = 'md5',
33        ['str'] = 'asdf.qwerty.123',
34        ['hex'] = '9ef941c4d050e43b1e665300f4fbe054',
35      },
36      {
37        ['init'] = 'asdf.qwerty.123',
38        ['specific'] = 'md5',
39        ['str'] = 'asdf.qwerty.123',
40        ['hex'] = 'cf25ddc406c50de0c13de2b79d127646',
41        ['reset'] = true,
42      },
43      {
44        ['init'] = 'hello',
45        ['specific'] = 'xxh3',
46        ['str'] = 'hello',
47        ['hex'] = 'c1156ae6cb7ff175',
48      }
49    }
50
51    for _, t in ipairs(test_data) do
52      local h
53      if not t['specific'] then
54        h = hash.create(t['init'])
55      else
56        h = hash.create_specific(t['specific'], t['init'])
57      end
58      if t['reset'] then
59        h:reset()
60      end
61      h:update(t['str'])
62      if not (h:hex() == t['hex']) then
63        t['error'] = 'sum mismatch: ' .. h:hex()
64        table.insert(worry, logger.slog('%1', t))
65      end
66    end
67
68    if (#worry == 0) then
69      return true, "no worry"
70    else
71      return true, table.concat(worry, ",")
72    end
73  end
74})
75