# HG changeset patch # User Matthew Wild # Date 1288998770 0 # Node ID ad5eb4fd28f5f5fc7f0a17f8f1a65f828449a0eb # Parent 45b7299e4746f8315c8a7a932517151b0a3a48cf Move asn1 Lua stack helpers to x509.c from ssl.c diff -r 45b7299e4746 -r ad5eb4fd28f5 src/ssl.c --- 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. */ diff -r 45b7299e4746 -r ad5eb4fd28f5 src/x509.c --- 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;