summaryrefslogtreecommitdiff
path: root/openssl.c
diff options
context:
space:
mode:
Diffstat (limited to 'openssl.c')
-rw-r--r--openssl.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/openssl.c b/openssl.c
index c2396ee..a3103b0 100644
--- a/openssl.c
+++ b/openssl.c
@@ -659,6 +659,57 @@ static int xn_all(lua_State *L) {
659} /* xn_all() */ 659} /* xn_all() */
660 660
661 661
662static int xn__next(lua_State *L) {
663 X509_NAME *name = checksimple(L, lua_upvalueindex(1), X509_NAME_CLASS);
664 X509_NAME_ENTRY *entry;
665 ASN1_OBJECT *obj;
666 const char *id;
667 char txt[256];
668 int i, n, nid, len;
669
670 lua_settop(L, 0);
671
672 i = lua_tointeger(L, lua_upvalueindex(2));
673 n = X509_NAME_entry_count(name);
674
675 while (i < n) {
676 if (!(entry = X509_NAME_get_entry(name, i++)))
677 continue;
678
679 obj = X509_NAME_ENTRY_get_object(entry);
680 nid = OBJ_obj2nid(obj);
681
682 if (nid != NID_undef && ((id = OBJ_nid2sn(nid)) || (id = OBJ_nid2ln(nid)))) {
683 lua_pushstring(L, id);
684 } else {
685 if (0 > (len = OBJ_obj2txt(txt, sizeof txt, obj, 1)))
686 return throwssl(L, "x509.name:__pairs");
687
688 lua_pushlstring(L, txt, len);
689 }
690
691 len = ASN1_STRING_length(X509_NAME_ENTRY_get_data(entry));
692 lua_pushlstring(L, (char *)ASN1_STRING_data(X509_NAME_ENTRY_get_data(entry)), len);
693
694 break;
695 }
696
697 lua_pushinteger(L, i);
698 lua_replace(L, lua_upvalueindex(2));
699
700 return lua_gettop(L);
701} /* xn__next() */
702
703static int xn__pairs(lua_State *L) {
704 lua_settop(L, 1);
705 lua_pushinteger(L, 0);
706
707 lua_pushcclosure(L, &xn__next, 2);
708
709 return 1;
710} /* xn__pairs() */
711
712
662static int xn__gc(lua_State *L) { 713static int xn__gc(lua_State *L) {
663 X509_NAME **ud = luaL_checkudata(L, 1, X509_NAME_CLASS); 714 X509_NAME **ud = luaL_checkudata(L, 1, X509_NAME_CLASS);
664 715
@@ -689,6 +740,7 @@ static const luaL_Reg xn_methods[] = {
689}; 740};
690 741
691static const luaL_Reg xn_metatable[] = { 742static const luaL_Reg xn_metatable[] = {
743 { "__pairs", &xn__pairs },
692 { "__gc", &xn__gc }, 744 { "__gc", &xn__gc },
693 { "__tostring", &xn__tostring }, 745 { "__tostring", &xn__tostring },
694 { NULL, NULL }, 746 { NULL, NULL },