Skip to content
Permalink
Browse files

feat(*) add iterater and helpers for stack-like objects

  • Loading branch information
fffonion committed Jan 9, 2020
1 parent bf455ff commit 46bb7237028a16e67878d8310c25e908ceece009
@@ -11,7 +11,6 @@ local stack_lib = require "resty.openssl.stack"
local altname_macro = require "resty.openssl.include.x509.altname"

local _M = {}
local mt

local general_names_ptr_ct = ffi.typeof("GENERAL_NAMES*")

@@ -45,7 +44,7 @@ end
-- shared with info_access
_M.gn_decode = gn_decode

mt = stack_lib.mt_of(STACK, gn_decode, _M)
local mt = stack_lib.mt_of(STACK, gn_decode, _M)
local mt__pairs = mt.__pairs
mt.__pairs = function(tbl)
local f = mt__pairs(tbl)
@@ -158,18 +157,22 @@ function _M:add(typ, value)
return self
end

_M.all = function(stack)
_M.all = function(self)
local ret = {}
local _next = mt.__ipairs(stack)
local _next = mt.__pairs(self)
while true do
local i, e = _next()
if i then
ret[i] = e
local k, v = _next()
if k then
ret[k] = v
else
break
end
end
return ret
end

_M.each = mt.__pairs
_M.index = mt.__index
_M.count = mt.__len

return _M
@@ -11,12 +11,10 @@ local _M = {}
local stack_ptr_ct = ffi.typeof("OPENSSL_STACK*")

local STACK = "X509"
local mt = stack_lib.mt_of(STACK, x509_lib.dup, _M)
local gc = stack_lib.gc_of(STACK)
local new = stack_lib.new_of(STACK)
local add = stack_lib.add_of(STACK)

_M.all = stack_lib.all_func(mt)
local mt = stack_lib.mt_of(STACK, x509_lib.dup, _M)

function _M.new()
local raw = new()
@@ -70,4 +68,9 @@ function _M:add(x509)
return true
end

_M.all = stack_lib.all_func(mt)
_M.each = mt.__ipairs
_M.index = mt.__index
_M.count = mt.__len

return _M
@@ -1,15 +1,11 @@
local ffi = require "ffi"
local C = ffi.C
local ffi_cast = ffi.cast
local ffi_str = ffi.string

require "resty.openssl.include.x509"
require "resty.openssl.include.x509v3"
local altname_lib = require "resty.openssl.x509.altname"
local stack_lib = require "resty.openssl.stack"

local _M = {}
local mt

local stack_ptr_ct = ffi.typeof("OPENSSL_STACK*")

@@ -22,7 +18,7 @@ local cdp_decode_fullname = function(ctx)
return altname_lib.dup(ctx.distpoint.name.fullname)
end

mt = stack_lib.mt_of(STACK, cdp_decode_fullname, _M)
local mt = stack_lib.mt_of(STACK, cdp_decode_fullname, _M)

function _M.new()
local ctx = new()
@@ -70,4 +66,8 @@ _M.all = function(stack)
return ret
end

_M.each = mt.__ipairs
_M.index = mt.__index
_M.count = mt.__len

return _M
@@ -9,7 +9,6 @@ local altname_lib = require "resty.openssl.x509.altname"
local stack_lib = require "resty.openssl.stack"

local _M = {}
local mt

local authority_info_access_ptr_ct = ffi.typeof("AUTHORITY_INFO_ACCESS*")

@@ -18,14 +17,13 @@ local new = stack_lib.new_of(STACK)
local add = stack_lib.add_of(STACK)
local dup = stack_lib.dup_of(STACK)


local aia_decode = function(ctx)
local nid = C.OBJ_obj2nid(ctx.method)
local gn = altname_lib.gn_decode(ctx.location)
return { nid, unpack(gn) }
end

mt = stack_lib.mt_of(STACK, aia_decode, _M)
local mt = stack_lib.mt_of(STACK, aia_decode, _M)
local mt__pairs = mt.__pairs
mt.__pairs = function(tbl)
local f = mt__pairs(tbl)
@@ -127,4 +125,8 @@ _M.all = function(stack)
return ret
end

_M.each = mt.__ipairs
_M.index = mt.__index
_M.count = mt.__len

return _M

0 comments on commit 46bb723

Please sign in to comment.
You can’t perform that action at this time.