simple-sso/test/aes.utest.lua

26 lines
918 B
Lua

local lu = require("luaunit")
local aes = require("resty.openssl.cipher")
function test_aes()
local key1 = "0a123456789a123456789a1234567890"
local key2 = "0b123456789b123456789b1234567890"
local aes1 = aes.new(nil)
local aes2 = aes.new(nil)
local enc1 = assert(aes1:encrypt(key1, "iv", "test", nil, "test"))
local enc2 = assert(aes2:encrypt(key2, "iv", "other", nil, "test"))
local tag1 = aes1:get_aead_tag()
local tag2 = aes2:get_aead_tag()
local aes3 = aes.new(nil)
local aes4 = aes.new(nil)
lu.assertEquals(#tag1, 16)
lu.assertEquals(#tag2, 16)
lu.assertNotEquals(enc1, "test")
lu.assertNotEquals(enc2, "other")
lu.assertNotEquals(enc1 .. tag1, "test")
lu.assertNotEquals(enc2 .. tag2, "other")
lu.assertEquals(aes3:decrypt(key1, "iv", enc1, nil, "test", tag1), "test")
lu.assertEquals(aes4:decrypt(key2, "iv", enc2, nil, "test", tag2), "other")
end
os.exit(lu.LuaUnit.run())