diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/openssl.c b/src/openssl.c index c3ab69f..0760c35 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
@@ -3241,23 +3241,41 @@ static int pk_new(lua_State *L) { | |||
3241 | luaL_argcheck(L, type != NID_undef, 1, lua_pushfstring(L, "%s: invalid key type", id)); | 3241 | luaL_argcheck(L, type != NID_undef, 1, lua_pushfstring(L, "%s: invalid key type", id)); |
3242 | } | 3242 | } |
3243 | 3243 | ||
3244 | if (loadfield(L, 1, "bits", LUA_TNUMBER, &n)) { | 3244 | switch(type) { |
3245 | luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `bits' invalid", n)); | 3245 | case EVP_PKEY_RSA: |
3246 | bits = (unsigned)n; | 3246 | if (loadfield(L, 1, "bits", LUA_TNUMBER, &n)) { |
3247 | } | 3247 | luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `bits' invalid", n)); |
3248 | bits = (unsigned)n; | ||
3249 | } | ||
3248 | 3250 | ||
3249 | if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) { | 3251 | if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) { |
3250 | luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n)); | 3252 | luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n)); |
3251 | exp = (unsigned)n; | 3253 | exp = (unsigned)n; |
3252 | } | 3254 | } |
3255 | break; | ||
3256 | case EVP_PKEY_DH: | ||
3257 | /* dhparam field can contain a PEM encoded string. | ||
3258 | The "dhparam" field takes precedence over "bits" */ | ||
3259 | if (loadfield(L, 1, "dhparam", LUA_TSTRING, &dhparam)) | ||
3260 | break; | ||
3253 | 3261 | ||
3254 | if (loadfield(L, 1, "curve", LUA_TSTRING, &id)) { | 3262 | if (loadfield(L, 1, "bits", LUA_TNUMBER, &n)) { |
3255 | if (!auxS_txt2nid(&curve, id)) | 3263 | luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `bits' invalid", n)); |
3256 | luaL_argerror(L, 1, lua_pushfstring(L, "%s: invalid curve", id)); | 3264 | bits = (unsigned)n; |
3257 | } | 3265 | } |
3258 | 3266 | ||
3259 | /* dhparam field can contain a PEM encoded string. */ | 3267 | if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) { |
3260 | loadfield(L, 1, "dhparam", LUA_TSTRING, &dhparam); | 3268 | luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n)); |
3269 | exp = (unsigned)n; | ||
3270 | } | ||
3271 | break; | ||
3272 | case EVP_PKEY_EC: | ||
3273 | if (loadfield(L, 1, "curve", LUA_TSTRING, &id)) { | ||
3274 | if (!auxS_txt2nid(&curve, id)) | ||
3275 | luaL_argerror(L, 1, lua_pushfstring(L, "%s: invalid curve", id)); | ||
3276 | } | ||
3277 | break; | ||
3278 | } | ||
3261 | 3279 | ||
3262 | creat: | 3280 | creat: |
3263 | if (!(*ud = EVP_PKEY_new())) | 3281 | if (!(*ud = EVP_PKEY_new())) |