diff options
author | William Ahern <william@Williams-MacBook-Air.local> | 2012-10-05 23:43:18 -0700 |
---|---|---|
committer | William Ahern <william@Williams-MacBook-Air.local> | 2012-10-05 23:43:18 -0700 |
commit | 7b0c50d597493f0baf5f1384bedbecf130610fce (patch) | |
tree | bbd6c9f09ab32c55d39cfd833dac3fc0e9bfdf55 /openssl.c | |
parent | 9b87f5309071f52e85438ca26ff224f9e9abc879 (diff) | |
download | luaossl-7b0c50d597493f0baf5f1384bedbecf130610fce.tar.gz luaossl-7b0c50d597493f0baf5f1384bedbecf130610fce.tar.bz2 luaossl-7b0c50d597493f0baf5f1384bedbecf130610fce.zip |
-n
some tweaks
Diffstat (limited to 'openssl.c')
-rw-r--r-- | openssl.c | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -126,7 +126,11 @@ static int throwssl(lua_State *L, const char *fun) { | |||
126 | 126 | ||
127 | static int interpose(lua_State *L, const char *mt) { | 127 | static int interpose(lua_State *L, const char *mt) { |
128 | luaL_getmetatable(L, mt); | 128 | luaL_getmetatable(L, mt); |
129 | lua_getfield(L, -1, "__index"); | 129 | |
130 | if (!strncmp("__", luaL_checkstring(L, 1), 2)) | ||
131 | lua_pushvalue(L, -1); | ||
132 | else | ||
133 | lua_getfield(L, -1, "__index"); | ||
130 | 134 | ||
131 | lua_pushvalue(L, -4); /* push method name */ | 135 | lua_pushvalue(L, -4); /* push method name */ |
132 | lua_gettable(L, -2); /* push old method */ | 136 | lua_gettable(L, -2); /* push old method */ |
@@ -150,6 +154,19 @@ static void addclass(lua_State *L, const char *name, const luaL_Reg *methods, co | |||
150 | } /* addclass() */ | 154 | } /* addclass() */ |
151 | 155 | ||
152 | 156 | ||
157 | static int checkoption(struct lua_State *L, int index, const char *def, const char *opts[]) { | ||
158 | const char *opt = (def)? luaL_optstring(L, index, def) : luaL_checkstring(L, index); | ||
159 | int i; | ||
160 | |||
161 | for (i = 0; opts[i]; i++) { | ||
162 | if (strieq(opts[i], opt)) | ||
163 | return i; | ||
164 | } | ||
165 | |||
166 | return luaL_argerror(L, index, lua_pushfstring(L, "invalid option %s", opt)); | ||
167 | } /* checkoption() */ | ||
168 | |||
169 | |||
153 | static void initall(lua_State *L); | 170 | static void initall(lua_State *L); |
154 | 171 | ||
155 | 172 | ||
@@ -821,7 +838,7 @@ static int gn__next(lua_State *L) { | |||
821 | 838 | ||
822 | switch (name->type) { | 839 | switch (name->type) { |
823 | case GEN_EMAIL: | 840 | case GEN_EMAIL: |
824 | tag = "RFC822"; | 841 | tag = "email"; |
825 | txt = (char *)M_ASN1_STRING_data(name->d.rfc822Name); | 842 | txt = (char *)M_ASN1_STRING_data(name->d.rfc822Name); |
826 | len = M_ASN1_STRING_length(name->d.rfc822Name); | 843 | len = M_ASN1_STRING_length(name->d.rfc822Name); |
827 | 844 | ||
@@ -1474,7 +1491,7 @@ static int xc_getBasicConstraint(lua_State *L) { | |||
1474 | int n = 0, i, top; | 1491 | int n = 0, i, top; |
1475 | 1492 | ||
1476 | for (i = 2, top = lua_gettop(L); i <= top; i++) { | 1493 | for (i = 2, top = lua_gettop(L); i <= top; i++) { |
1477 | switch (luaL_checkoption(L, i, 0, (const char *[]){ "CA", "pathLen", "pathLenConstraint", 0 })) { | 1494 | switch (checkoption(L, i, 0, (const char *[]){ "CA", "pathLen", "pathLenConstraint", 0 })) { |
1478 | case 0: | 1495 | case 0: |
1479 | lua_pushboolean(L, CA); | 1496 | lua_pushboolean(L, CA); |
1480 | n++; | 1497 | n++; |
@@ -1530,7 +1547,7 @@ static int xc_setBasicConstraint(lua_State *L) { | |||
1530 | } else { | 1547 | } else { |
1531 | lua_settop(L, 3); | 1548 | lua_settop(L, 3); |
1532 | 1549 | ||
1533 | switch (luaL_checkoption(L, 2, 0, (const char *[]){ "CA", "pathLen", "pathLenConstraint", 0 })) { | 1550 | switch (checkoption(L, 2, 0, (const char *[]){ "CA", "pathLen", "pathLenConstraint", 0 })) { |
1534 | case 0: | 1551 | case 0: |
1535 | luaL_checktype(L, 3, LUA_TBOOLEAN); | 1552 | luaL_checktype(L, 3, LUA_TBOOLEAN); |
1536 | CA = lua_toboolean(L, 3); | 1553 | CA = lua_toboolean(L, 3); |
@@ -1602,7 +1619,7 @@ static int xc_setBasicConstraintsCritical(lua_State *L) { | |||
1602 | 1619 | ||
1603 | static int xc__tostring(lua_State *L) { | 1620 | static int xc__tostring(lua_State *L) { |
1604 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); | 1621 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); |
1605 | int fmt = luaL_checkoption(L, 2, "pem", (const char *[]){ "pem", 0 }); | 1622 | int fmt = checkoption(L, 2, "pem", (const char *[]){ "pem", 0 }); |
1606 | BIO *tmp; | 1623 | BIO *tmp; |
1607 | char *pem; | 1624 | char *pem; |
1608 | long len; | 1625 | long len; |