aboutsummaryrefslogtreecommitdiffstats
path: root/regress
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-10-25 17:58:18 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-10-25 17:58:18 +1100
commita5f1a0f62186d0bfeb62c17a22f9ba9d0ef5de37 (patch)
treeda75384a6a59754ca35969e12318aa2d6c3d8fa7 /regress
parente4cdcc5eb020b937182b7a8660c644485a188531 (diff)
downloadluaossl-a5f1a0f62186d0bfeb62c17a22f9ba9d0ef5de37.tar.gz
luaossl-a5f1a0f62186d0bfeb62c17a22f9ba9d0ef5de37.tar.bz2
luaossl-a5f1a0f62186d0bfeb62c17a22f9ba9d0ef5de37.zip
regress/regress: Pull in some improvements from cqueues
Diffstat (limited to 'regress')
-rw-r--r--regress/regress.lua51
1 files changed, 47 insertions, 4 deletions
diff --git a/regress/regress.lua b/regress/regress.lua
index 4377db5..b89e996 100644
--- a/regress/regress.lua
+++ b/regress/regress.lua
@@ -1,3 +1,5 @@
+local require = require -- may be overloaded by regress.require
+
local regress = {
openssl = require"openssl",
bignum = require"openssl.bignum",
@@ -98,12 +100,20 @@ function regress.export(...)
return regress
end -- export
+function regress.require(modname)
+ local ok, module = pcall(require, modname)
+
+ regress.check(ok, "module %s required", modname)
+
+ return module
+end -- regress.require
+
local counter = 0
function regress.genkey(type, ca_key, ca_crt)
- local pkey = require"openssl.pkey"
- local x509 = require"openssl.x509"
- local name = require"openssl.x509.name"
- local altname = require"openssl.x509.altname"
+ local pkey = regress.require"openssl.pkey"
+ local x509 = regress.require"openssl.x509"
+ local name = regress.require"openssl.x509.name"
+ local altname = regress.require"openssl.x509.altname"
local key
type = string.upper(type or "RSA")
@@ -159,4 +169,37 @@ local function getsubtable(t, name, ...)
end
end -- getsubtable
+function regress.newsslctx(protocol, accept, keytype)
+ local context = regress.require"openssl.ssl.context"
+ local ctx = context.new(protocol, accept)
+
+ if keytype or keytype == nil then
+ local key, crt = regress.genkey(keytype)
+
+ ctx:setCertificate(crt)
+ ctx:setPrivateKey(key)
+ end
+
+ return ctx
+end -- require.newsslctx
+
+local ctxcache = {}
+
+function regress.getsslctx(protocol, accept, keytype)
+ local keycache = getsubtable(ctxcache, protocol, accept)
+
+ if keytype == nil then
+ keytype = "RSA"
+ end
+
+ local ctx = keycache[keytype]
+
+ if not ctx then
+ ctx = regress.newsslctx(protocol, accept, keytype)
+ keycache[keytype] = ctx
+ end
+
+ return ctx
+end -- regress.getsslctx
+
return regress