src/x509.c

changeset 20
ad5eb4fd28f5
parent 18
2c6fbfe07883
child 22
c4452dfd6ade
--- 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