Fri, 05 Nov 2010 21:25:30 +0000
Add :pem() method to certificates
src/x509.c | file | annotate | diff | comparison | revisions |
--- a/src/x509.c Fri Nov 05 21:25:13 2010 +0000 +++ b/src/x509.c Fri Nov 05 21:25:30 2010 +0000 @@ -151,11 +151,31 @@ return 1; } +int meth_pem(lua_State* L) +{ + X509* cert = luasec_to_x509(L, 1); + BIO *bio = BIO_new(BIO_s_mem()); + char* data; long bytes; + if(!PEM_write_bio_X509(bio, cert)) + { + lua_pushnil(L); + return 1; + } + bytes = BIO_get_mem_data(bio, &data); + if(bytes > 0) + lua_pushlstring(L, data, bytes); + else + lua_pushnil(L); + BIO_free(bio); + return 1; +} + /** * Certificate metamethods */ static luaL_Reg meta[] = { {"decode", meth_decode}, + {"pem", meth_pem}, {NULL, NULL} };