bunkerweb/examples/perf/test_pkey_codec.lua
Théophile Diot a280059882 Squashed 'src/deps/src/lua-resty-openssl/' content from commit b23c072a4
git-subtree-dir: src/deps/src/lua-resty-openssl
git-subtree-split: b23c072a405b749ac60d21e3946cbf57a959b780
2023-06-30 15:38:47 -04:00

33 lines
1 KiB
Lua

local path = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
package.path = path .. "/?.lua;" .. package.path
local test = require "framework".test
local pkey = require "resty.openssl.pkey"
local example_pkey = assert(pkey.new())
for _, op in ipairs({"load", "export"}) do
for _, t in ipairs({"PEM", "DER", "JWK"}) do
for _, p in ipairs({"public", "private"}) do
if op == "load" then
local txt = assert(example_pkey:tostring(p, t))
local opts = {
format = t,
}
if t ~= "JWK" then
opts.type = p == "public" and "pu" or "pr"
end
test("load " .. t .. " " .. p .. " key", function()
return pkey.new(txt, opts)
end)
else
test("export " .. t .. " " .. p .. " key", function()
return example_pkey:tostring(p, t)
end)
end
end
end
end