aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-29 15:24:39 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-29 15:24:39 +0100
commitea9d518099d0ccef9d1bba73d6e270200398bc58 (patch)
tree030075b46f5ebd67e867f11185a09618fbbae285 /test
parenta78961b4277306675c59a3fbc6da836cfdde41b2 (diff)
downloadrspamd-ea9d518099d0ccef9d1bba73d6e270200398bc58.tar.gz
rspamd-ea9d518099d0ccef9d1bba73d6e270200398bc58.zip
[Fix] Fix lua RSA verify and its tests
Diffstat (limited to 'test')
-rw-r--r--test/lua/unit/rsa.lua18
1 files changed, 13 insertions, 5 deletions
diff --git a/test/lua/unit/rsa.lua b/test/lua/unit/rsa.lua
index caf017118..962077242 100644
--- a/test/lua/unit/rsa.lua
+++ b/test/lua/unit/rsa.lua
@@ -5,6 +5,7 @@ context("RSA signature verification test", function()
local rsa_pubkey = require "rspamd_rsa_pubkey"
local rsa_signature = require "rspamd_rsa_signature"
local rsa = require "rspamd_rsa"
+ local hash = require "rspamd_cryptobox_hash"
local pubkey = 'testkey.pub'
local privkey = 'testkey'
local data = 'test.data'
@@ -14,19 +15,26 @@ context("RSA signature verification test", function()
test("RSA sign", function()
-- Signing test
- local rsa_key = rsa_privkey.load(string.format('%s/%s', test_dir, privkey))
+ rsa_key = rsa_privkey.load_file(string.format('%s/%s', test_dir, privkey))
assert_not_nil(rsa_key)
- local rsa_sig = rsa.sign_file(rsa_key, string.format('%s/%s', test_dir, data))
- assert_not_nil(rsa_sig)
- rsa_sig:save(string.format('%s/%s', test_dir, signature), true)
+
+ local h = hash.create_specific('sha256')
+ local d = io.open(string.format('%s/%s', test_dir, data), "rb"):read "*a"
+ h:update(d)
+ local sig = rsa.sign_memory(rsa_key, h:bin())
+ assert_not_nil(sig)
+ sig:save(string.format('%s/%s', test_dir, signature), true)
end)
test("RSA verify", function()
-- Verifying test
+ local h = hash.create_specific('sha256')
+ local d = io.open(string.format('%s/%s', test_dir, data), "rb"):read "*a"
+ h:update(d)
rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey))
assert_not_nil(rsa_key)
rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature))
assert_not_nil(rsa_sig)
- assert_true(rsa.verify_file(rsa_key, rsa_sig, string.format('%s/%s', test_dir, data)))
+ assert_true(rsa.verify_memory(rsa_key, rsa_sig, h:bin()))
end)
end)