Move asn1 Lua stack helpers to x509.c from ssl.c

Fri, 05 Nov 2010 23:12:50 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 05 Nov 2010 23:12:50 +0000
changeset 20
ad5eb4fd28f5
parent 19
45b7299e4746
child 21
c3755cb3d246

Move asn1 Lua stack helpers to x509.c from ssl.c

src/ssl.c file | annotate | diff | comparison | revisions
src/x509.c file | annotate | diff | comparison | revisions
--- a/src/ssl.c	Fri Nov 05 23:11:38 2010 +0000
+++ b/src/ssl.c	Fri Nov 05 23:12:50 2010 +0000
@@ -377,42 +377,6 @@
   }
 }
 
-void luasec_push_asn1_objname(lua_State* L, ASN1_OBJECT *object, int no_name)
-{
-  char buffer[256];
-  int len = OBJ_obj2txt(buffer, sizeof(buffer), object, no_name);
-  lua_pushlstring(L, buffer, min(sizeof(buffer),len));
-}
-
-void luasec_push_asn1_string(lua_State* L, ASN1_STRING *string)
-{
-  if(string)
-    lua_pushlstring(L, (char*)ASN1_STRING_data(string), ASN1_STRING_length(string));
-  else
-    lua_pushnil(L);
-}
-
-int luasec_push_subtable(lua_State* L, int idx)
-{
-
-        lua_pushvalue(L, -1);
-        lua_gettable(L, idx-1);
-
-        if(lua_isnil(L, -1))
-        {
-        	lua_pop(L, 1);
-        	lua_newtable(L);
-        	lua_pushvalue(L, -2);
-        	lua_pushvalue(L, -2);
-        	lua_settable(L, idx-3);
-
-        	lua_replace(L, -2); /* Replace key with table */
-        	return 1;
-        }
-       	lua_replace(L, -2); /* Replace key with table */
-        return 0;
-}
-
 /**
  * Return the peer certificate.
  */
--- a/src/x509.c	Fri Nov 05 23:11:38 2010 +0000
+++ b/src/x509.c	Fri Nov 05 23:12:50 2010 +0000
@@ -35,6 +35,42 @@
   return ((p_x509)luaL_checkudata(L, idx, "SSL:Certificate"))->cert;
 }
 
+void luasec_push_asn1_objname(lua_State* L, ASN1_OBJECT *object, int no_name)
+{
+  char buffer[256];
+  int len = OBJ_obj2txt(buffer, sizeof(buffer), object, no_name);
+  lua_pushlstring(L, buffer, min(sizeof(buffer),len));
+}
+
+void luasec_push_asn1_string(lua_State* L, ASN1_STRING *string)
+{
+  if(string)
+    lua_pushlstring(L, (char*)ASN1_STRING_data(string), ASN1_STRING_length(string));
+  else
+    lua_pushnil(L);
+}
+
+int luasec_push_subtable(lua_State* L, int idx)
+{
+
+        lua_pushvalue(L, -1);
+        lua_gettable(L, idx-1);
+
+        if(lua_isnil(L, -1))
+        {
+        	lua_pop(L, 1);
+        	lua_newtable(L);
+        	lua_pushvalue(L, -2);
+        	lua_pushvalue(L, -2);
+        	lua_settable(L, idx-3);
+
+        	lua_replace(L, -2); /* Replace key with table */
+        	return 1;
+        }
+       	lua_replace(L, -2); /* Replace key with table */
+        return 0;
+}
+
 int meth_decode(lua_State* L)
 {
   X509 *peer;

mercurial