diff options
| author | william <william+macosx@25thandclement.com> | 2015-06-04 19:23:00 -0700 |
|---|---|---|
| committer | william <william+macosx@25thandclement.com> | 2015-06-04 19:23:00 -0700 |
| commit | 6fbdef8c580d553e6cd109e649272c98399145c2 (patch) | |
| tree | c2261eca5f308ea25de50821089ecc4c83b4b3ba /src | |
| parent | 0d7b80596ca242ec7476a27c0c3f1bc045f3e016 (diff) | |
| download | luaossl-6fbdef8c580d553e6cd109e649272c98399145c2.tar.gz luaossl-6fbdef8c580d553e6cd109e649272c98399145c2.tar.bz2 luaossl-6fbdef8c580d553e6cd109e649272c98399145c2.zip | |
add extension:text metho
Diffstat (limited to 'src')
| -rw-r--r-- | src/openssl.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/openssl.c b/src/openssl.c index 108ae3d..2390be0 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -694,6 +694,13 @@ static auxL_Integer (auxL_checkinteger)(lua_State *L, int index, auxL_Integer mi | |||
| 694 | return i; | 694 | return i; |
| 695 | } /* auxL_checkinteger() */ | 695 | } /* auxL_checkinteger() */ |
| 696 | 696 | ||
| 697 | #define auxL_optinteger_(a, b, c, d, e, ...) auxL_optinteger((a), (b), (c), (d), (e)) | ||
| 698 | #define auxL_optinteger(...) auxL_optinteger_(__VA_ARGS__, auxL_IntegerMin, auxL_IntegerMax, 0) | ||
| 699 | |||
| 700 | static auxL_Integer (auxL_optinteger)(lua_State *L, int index, auxL_Integer def, auxL_Integer min, auxL_Integer max) { | ||
| 701 | return (lua_isnoneornil(L, index))? def : auxL_checkinteger(L, index, min, max); | ||
| 702 | } /* auxL_optinteger() */ | ||
| 703 | |||
| 697 | #define auxL_checkunsigned_(a, b, c, d, ...) auxL_checkunsigned((a), (b), (c), (d)) | 704 | #define auxL_checkunsigned_(a, b, c, d, ...) auxL_checkunsigned((a), (b), (c), (d)) |
| 698 | #define auxL_checkunsigned(...) auxL_checkunsigned_(__VA_ARGS__, auxL_UnsignedMin, auxL_UnsignedMax, 0) | 705 | #define auxL_checkunsigned(...) auxL_checkunsigned_(__VA_ARGS__, auxL_UnsignedMin, auxL_UnsignedMax, 0) |
| 699 | 706 | ||
| @@ -714,6 +721,13 @@ static auxL_Unsigned (auxL_checkunsigned)(lua_State *L, int index, auxL_Unsigned | |||
| 714 | return i; | 721 | return i; |
| 715 | } /* auxL_checkunsigned() */ | 722 | } /* auxL_checkunsigned() */ |
| 716 | 723 | ||
| 724 | #define auxL_optunsigned_(a, b, c, d, e, ...) auxL_optunsigned((a), (b), (c), (d), (e)) | ||
| 725 | #define auxL_optunsigned(...) auxL_optunsigned_(__VA_ARGS__, auxL_UnsignedMin, auxL_UnsignedMax, 0) | ||
| 726 | |||
| 727 | static auxL_Unsigned (auxL_optunsigned)(lua_State *L, int index, auxL_Unsigned def, auxL_Unsigned min, auxL_Unsigned max) { | ||
| 728 | return (lua_isnoneornil(L, index))? def : auxL_checkunsigned(L, index, min, max); | ||
| 729 | } /* auxL_optunsigned() */ | ||
| 730 | |||
| 717 | typedef struct { | 731 | typedef struct { |
| 718 | const char *name; | 732 | const char *name; |
| 719 | auxL_Integer value; | 733 | auxL_Integer value; |
| @@ -3135,6 +3149,25 @@ static int xe_getCritical(lua_State *L) { | |||
| 3135 | } /* xe_getCritical() */ | 3149 | } /* xe_getCritical() */ |
| 3136 | 3150 | ||
| 3137 | 3151 | ||
| 3152 | static int xe_text(lua_State *L) { | ||
| 3153 | X509_EXTENSION *ext = checksimple(L, 1, X509_EXT_CLASS); | ||
| 3154 | unsigned long flags = auxL_optunsigned(L, 2, 0, 0, ULONG_MAX); | ||
| 3155 | int indent = auxL_optinteger(L, 3, 0, 0, INT_MAX); | ||
| 3156 | BIO *bio = getbio(L); | ||
| 3157 | char *data; | ||
| 3158 | size_t len; | ||
| 3159 | |||
| 3160 | if (!X509V3_EXT_print(bio, ext, flags, indent)) | ||
| 3161 | return auxL_error(L, auxL_EOPENSSL, "x509.extension.text"); | ||
| 3162 | |||
| 3163 | len = BIO_get_mem_data(bio, &data); | ||
| 3164 | |||
| 3165 | lua_pushlstring(L, data, len); | ||
| 3166 | |||
| 3167 | return 1; | ||
| 3168 | } /* xe_text() */ | ||
| 3169 | |||
| 3170 | |||
| 3138 | static int xe__gc(lua_State *L) { | 3171 | static int xe__gc(lua_State *L) { |
| 3139 | X509_EXTENSION **ud = luaL_checkudata(L, 1, X509_EXT_CLASS); | 3172 | X509_EXTENSION **ud = luaL_checkudata(L, 1, X509_EXT_CLASS); |
| 3140 | 3173 | ||
| @@ -3154,6 +3187,7 @@ static const luaL_Reg xe_methods[] = { | |||
| 3154 | { "getLongName", &xe_getLongName }, | 3187 | { "getLongName", &xe_getLongName }, |
| 3155 | { "getData", &xe_getData }, | 3188 | { "getData", &xe_getData }, |
| 3156 | { "getCritical", &xe_getCritical }, | 3189 | { "getCritical", &xe_getCritical }, |
| 3190 | { "text", &xe_text }, | ||
| 3157 | { NULL, NULL }, | 3191 | { NULL, NULL }, |
| 3158 | }; | 3192 | }; |
| 3159 | 3193 | ||
| @@ -3169,10 +3203,19 @@ static const luaL_Reg xe_globals[] = { | |||
| 3169 | { NULL, NULL }, | 3203 | { NULL, NULL }, |
| 3170 | }; | 3204 | }; |
| 3171 | 3205 | ||
| 3206 | static const auxL_IntegerReg xe_textopts[] = { | ||
| 3207 | { "UNKNOWN_MASK", X509V3_EXT_UNKNOWN_MASK }, | ||
| 3208 | { "DEFAULT", X509V3_EXT_DEFAULT }, | ||
| 3209 | { "ERROR_UNKNOWN", X509V3_EXT_ERROR_UNKNOWN }, | ||
| 3210 | { "PARSE_UNKNOWN", X509V3_EXT_PARSE_UNKNOWN }, | ||
| 3211 | { "DUMP_UNKNOWN", X509V3_EXT_DUMP_UNKNOWN }, | ||
| 3212 | }; | ||
| 3213 | |||
| 3172 | int luaopen__openssl_x509_extension(lua_State *L) { | 3214 | int luaopen__openssl_x509_extension(lua_State *L) { |
| 3173 | initall(L); | 3215 | initall(L); |
| 3174 | 3216 | ||
| 3175 | luaL_newlib(L, xe_globals); | 3217 | luaL_newlib(L, xe_globals); |
| 3218 | auxL_setintegers(L, xe_textopts); | ||
| 3176 | 3219 | ||
| 3177 | return 1; | 3220 | return 1; |
| 3178 | } /* luaopen__openssl_x509_extension() */ | 3221 | } /* luaopen__openssl_x509_extension() */ |
| @@ -6672,7 +6715,7 @@ static void randL_checkpid(struct randL_state *st) { | |||
| 6672 | 6715 | ||
| 6673 | 6716 | ||
| 6674 | static int rand_stir(lua_State *L) { | 6717 | static int rand_stir(lua_State *L) { |
| 6675 | int error = randL_stir(randL_getstate(L), luaL_optunsigned(L, 1, 16)); | 6718 | int error = randL_stir(randL_getstate(L), auxL_optunsigned(L, 1, 16, 0, UINT_MAX)); |
| 6676 | 6719 | ||
| 6677 | if (error) { | 6720 | if (error) { |
| 6678 | lua_pushboolean(L, 0); | 6721 | lua_pushboolean(L, 0); |
