# HG changeset patch # User Paul Aurich # Date 1290312251 28800 # Node ID c47594a84f04842ef28048671d1c03040d3d52f7 # Parent 87625285de20832fd37d912ab0797210c0922f49 imported patch whitespace diff -r 87625285de20 -r c47594a84f04 src/x509.c --- a/src/x509.c Sat Nov 20 20:04:11 2010 -0800 +++ b/src/x509.c Sat Nov 20 20:04:11 2010 -0800 @@ -44,7 +44,7 @@ void luasec_push_asn1_string(lua_State* L, ASN1_STRING *string) { - if(string) + if (string) lua_pushlstring(L, (char*)ASN1_STRING_data(string), ASN1_STRING_length(string)); else lua_pushnil(L); @@ -53,22 +53,23 @@ int luasec_push_subtable(lua_State* L, int idx) { - lua_pushvalue(L, -1); - lua_gettable(L, idx-1); + 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); + 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; + lua_replace(L, -2); /* Replace key with table */ + return 1; + } + + lua_replace(L, -2); /* Replace key with table */ + return 0; } void luasec_push_x509_name(lua_State* L, X509_NAME *name) @@ -77,7 +78,7 @@ lua_newtable(L); n_entries = X509_NAME_entry_count(name); - for(i = 0; i < n_entries; i++) + for (i = 0; i < n_entries; i++) { X509_NAME_ENTRY *entry; ASN1_OBJECT *object; @@ -124,18 +125,18 @@ lua_newtable(L); /* ret */ i = -1; - while((i = X509_get_ext_by_NID(peer, NID_subject_alt_name, i)) != -1) + while ((i = X509_get_ext_by_NID(peer, NID_subject_alt_name, i)) != -1) { X509_EXTENSION *extension; STACK_OF(GENERAL_NAME) *values; int n_general_names; extension = X509_get_ext(peer, i); - if(extension == NULL) + if (extension == NULL) break; values = X509V3_EXT_d2i(extension); - if(values == NULL) + if (values == NULL) break; /* Push ret[oid] */ @@ -146,7 +147,7 @@ lua_setfield(L, -2, "name"); n_general_names = sk_GENERAL_NAME_num(values); - for(j = 0; j < n_general_names; j++) + for (j = 0; j < n_general_names; j++) { GENERAL_NAME *general_name; @@ -160,7 +161,7 @@ luasec_push_asn1_objname(L, otherName->type_id, 1); - if(luasec_push_subtable(L, -2)) + if (luasec_push_subtable(L, -2)) { luasec_push_asn1_objname(L, otherName->type_id, 0); lua_setfield(L, -2, "name"); @@ -175,7 +176,7 @@ case GEN_DNS: { lua_pushstring(L, "dNSName"); - luasec_push_subtable(L, -2); + luasec_push_subtable(L, -2); luasec_push_asn1_string(L, general_name->d.dNSName); lua_rawseti(L, -2, lua_objlen(L, -2)+1); lua_pop(L, 1); @@ -206,13 +207,13 @@ 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)) + if (!PEM_write_bio_X509(bio, cert)) { lua_pushnil(L); return 1; } bytes = BIO_get_mem_data(bio, &data); - if(bytes > 0) + if (bytes > 0) lua_pushlstring(L, data, bytes); else lua_pushnil(L); @@ -237,7 +238,7 @@ char hex_buffer[EVP_MAX_MD_SIZE*2]; const EVP_MD *digest; cert = luasec_to_x509(L, 1); - if(lua_gettop(L) < 2 || strcmp(luaL_checkstring(L, 1), "sha1") == 0) + if (lua_gettop(L) < 2 || strcmp(luaL_checkstring(L, 1), "sha1") == 0) { digest = EVP_sha1(); } @@ -247,7 +248,7 @@ lua_pushstring(L, "digest algorithm not supported"); return 2; } - if(!X509_digest(cert, digest, buffer, &bytes)) + if (!X509_digest(cert, digest, buffer, &bytes)) { lua_pushnil(L); lua_pushstring(L, "out of memory"); @@ -279,7 +280,7 @@ data = luaL_checklstring(L, 1, &bytes); BIO_write(bio, data, bytes); cert = PEM_read_bio_X509(bio, NULL, NULL, NULL); - if(cert) + if (cert) luasec_push_x509(L, cert); else lua_pushnil(L);