diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-28 00:11:56 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-28 00:11:56 +0000 |
commit | e4cc017c5d44c1046e6afdfc1e68d756c8748b6b (patch) | |
tree | 3e0be3b2b40f6ef509cd4d00f0e4d1166d575209 /test/lua/unit/rsa.lua | |
parent | f1752bac0b0c00717478bc6633e4afb527bd46da (diff) | |
download | rspamd-e4cc017c5d44c1046e6afdfc1e68d756c8748b6b.tar.gz rspamd-e4cc017c5d44c1046e6afdfc1e68d756c8748b6b.zip |
Rework lua tests one more time.
Diffstat (limited to 'test/lua/unit/rsa.lua')
-rw-r--r-- | test/lua/unit/rsa.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/lua/unit/rsa.lua b/test/lua/unit/rsa.lua new file mode 100644 index 000000000..75d07fd30 --- /dev/null +++ b/test/lua/unit/rsa.lua @@ -0,0 +1,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) |