aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/unit/rsa.lua
blob: 75d07fd30a5481cd8bcbef0d82803d4823a06db6 (plain)
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
-- Test rsa signing

describe("rsa signarture test", function()
  local rsa_privkey = require "rspamd_rsa_privkey"
  local rsa_pubkey = require "rspamd_rsa_pubkey"
  local rsa_signature = require "rspamd_rsa_signature"
  local rsa = require "rspamd_rsa"
  local pubkey = 'testkey.pub'
  local privkey = 'testkey'
  local data = 'test.data'
  local signature = 'test.sig'

  -- Signing test
  local rsa_key = rsa_privkey.load(string.format('%s/%s', test_dir, privkey))

  if not rsa_key then
    return -1
  end

  local rsa_sig = rsa.sign_file(rsa_key, string.format('%s/%s', test_dir, data))

  if not rsa_sig then
    return -1
  end

  rsa_sig:save(string.format('%s/%s', test_dir, signature), true)

  -- Verifying test
  rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey))

  if not rsa_key then
    return -1
  end

  rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature))

  if not rsa_sig then
    return -1
  end

  if not rsa.verify_file(rsa_key, rsa_sig, string.format('%s/%s', test_dir, data)) then
    return -1
  end

end)