src/x509.c

changeset 20
ad5eb4fd28f5
parent 18
2c6fbfe07883
child 22
c4452dfd6ade
equal deleted inserted replaced
19:45b7299e4746 20:ad5eb4fd28f5
31 } 31 }
32 32
33 X509* luasec_to_x509(lua_State* L, int idx) 33 X509* luasec_to_x509(lua_State* L, int idx)
34 { 34 {
35 return ((p_x509)luaL_checkudata(L, idx, "SSL:Certificate"))->cert; 35 return ((p_x509)luaL_checkudata(L, idx, "SSL:Certificate"))->cert;
36 }
37
38 void luasec_push_asn1_objname(lua_State* L, ASN1_OBJECT *object, int no_name)
39 {
40 char buffer[256];
41 int len = OBJ_obj2txt(buffer, sizeof(buffer), object, no_name);
42 lua_pushlstring(L, buffer, min(sizeof(buffer),len));
43 }
44
45 void luasec_push_asn1_string(lua_State* L, ASN1_STRING *string)
46 {
47 if(string)
48 lua_pushlstring(L, (char*)ASN1_STRING_data(string), ASN1_STRING_length(string));
49 else
50 lua_pushnil(L);
51 }
52
53 int luasec_push_subtable(lua_State* L, int idx)
54 {
55
56 lua_pushvalue(L, -1);
57 lua_gettable(L, idx-1);
58
59 if(lua_isnil(L, -1))
60 {
61 lua_pop(L, 1);
62 lua_newtable(L);
63 lua_pushvalue(L, -2);
64 lua_pushvalue(L, -2);
65 lua_settable(L, idx-3);
66
67 lua_replace(L, -2); /* Replace key with table */
68 return 1;
69 }
70 lua_replace(L, -2); /* Replace key with table */
71 return 0;
36 } 72 }
37 73
38 int meth_decode(lua_State* L) 74 int meth_decode(lua_State* L)
39 { 75 {
40 X509 *peer; 76 X509 *peer;

mercurial