149 } |
149 } |
150 lua_pop(L, 1); /* ret.extensions */ |
150 lua_pop(L, 1); /* ret.extensions */ |
151 return 1; |
151 return 1; |
152 } |
152 } |
153 |
153 |
|
154 int meth_pem(lua_State* L) |
|
155 { |
|
156 X509* cert = luasec_to_x509(L, 1); |
|
157 BIO *bio = BIO_new(BIO_s_mem()); |
|
158 char* data; long bytes; |
|
159 if(!PEM_write_bio_X509(bio, cert)) |
|
160 { |
|
161 lua_pushnil(L); |
|
162 return 1; |
|
163 } |
|
164 bytes = BIO_get_mem_data(bio, &data); |
|
165 if(bytes > 0) |
|
166 lua_pushlstring(L, data, bytes); |
|
167 else |
|
168 lua_pushnil(L); |
|
169 BIO_free(bio); |
|
170 return 1; |
|
171 } |
|
172 |
154 /** |
173 /** |
155 * Certificate metamethods |
174 * Certificate metamethods |
156 */ |
175 */ |
157 static luaL_Reg meta[] = { |
176 static luaL_Reg meta[] = { |
158 {"decode", meth_decode}, |
177 {"decode", meth_decode}, |
|
178 {"pem", meth_pem}, |
159 {NULL, NULL} |
179 {NULL, NULL} |
160 }; |
180 }; |
161 |
181 |
162 LUASEC_API int luaopen_ssl_x509(lua_State *L) |
182 LUASEC_API int luaopen_ssl_x509(lua_State *L) |
163 { |
183 { |