File: hashes.lua

package info (click to toggle)
rspamd 1.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 23,572 kB
  • sloc: ansic: 348,610; asm: 12,457; perl: 2,869; pascal: 1,532; cpp: 738; python: 653; java: 433; sh: 331; sql: 312; xml: 116; makefile: 111
file content (68 lines) | stat: -rw-r--r-- 2,030 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
rspamd_config:register_symbol({
  name = 'TEST_HASHES',
  score = 1.0,
  callback = function()
    local hash = require 'rspamd_cryptobox_hash'
    local logger = require 'rspamd_logger'

    local worry = {}
    local test_data = {
      {
        ['str'] = 'asdf.qwerty.123',
        ['hex'] = 'bf22dd95750034b9af93f0e4e5954aca3506bbcdbc051d91bd9af2d1a8fc294e848626b1c1751e58b44c4d3ea69dec5efa5a214dc59c77b1a9ca3bde3babac9d',
      },
      {
        ['specific'] = 'md5',
        ['str'] = 'asdf.qwerty.123',
        ['hex'] = 'cf25ddc406c50de0c13de2b79d127646',
      },
      {
        ['init'] = 'asdf.qwerty.123',
        ['str'] = 'asdf.qwerty.123',
        ['hex'] = 'bf22dd95750034b9af93f0e4e5954aca3506bbcdbc051d91bd9af2d1a8fc294e848626b1c1751e58b44c4d3ea69dec5efa5a214dc59c77b1a9ca3bde3babac9d',
        ['reset'] = true,
      },
      {
        ['init'] = 'asdf.qwerty.123',
        ['str'] = 'asdf.qwerty.123',
        ['hex'] = 'e445046aa21a705dcce1343795630f88bc0196a0070011fdce789d5a2a349a8f85349834ade555ca21439f65fdc4dbcf82dcff7fcc559ef11c508507515c1532',
      },
      {
        ['init'] = 'asdf.qwerty.123',
        ['specific'] = 'md5',
        ['str'] = 'asdf.qwerty.123',
        ['hex'] = '9ef941c4d050e43b1e665300f4fbe054',
      },
      {
        ['init'] = 'asdf.qwerty.123',
        ['specific'] = 'md5',
        ['str'] = 'asdf.qwerty.123',
        ['hex'] = 'cf25ddc406c50de0c13de2b79d127646',
        ['reset'] = true,
      },
    }

    for _, t in ipairs(test_data) do
      local h
      if not t['specific'] then
        h = hash.create(t['init'])
      else
        h = hash.create_specific(t['specific'], t['init'])
      end
      if t['reset'] then
        h:reset()
      end
      h:update(t['str'])
      if not (h:hex() == t['hex']) then
        t['error'] = 'sum mismatch: ' .. h:hex()
        table.insert(worry, logger.slog('%1', t))
      end
    end

    if (#worry == 0) then
      return true, "no worry"
    else
      return true, table.concat(worry, ",")
    end
  end
})