diff options
author | daurnimator <quae@daurnimator.com> | 2017-08-31 00:46:30 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-08-31 01:09:54 +1000 |
commit | 2b86d68fd92a387dcbc3c9c62fa380c8d2a2e4aa (patch) | |
tree | f671928d98836dbedf44483179fbdf273b705189 | |
parent | 93b158712b482d6fe7bebe6e2666937e86b80f79 (diff) | |
download | luaossl-2b86d68fd92a387dcbc3c9c62fa380c8d2a2e4aa.tar.gz luaossl-2b86d68fd92a387dcbc3c9c62fa380c8d2a2e4aa.tar.bz2 luaossl-2b86d68fd92a387dcbc3c9c62fa380c8d2a2e4aa.zip |
Add branch for each key type in pk_new field marshalling
-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) { luaL_argcheck(L, type != NID_undef, 1, lua_pushfstring(L, "%s: invalid key type", id)); } - if (loadfield(L, 1, "bits", LUA_TNUMBER, &n)) { - luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `bits' invalid", n)); - bits = (unsigned)n; - } + switch(type) { + case EVP_PKEY_RSA: + if (loadfield(L, 1, "bits", LUA_TNUMBER, &n)) { + luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `bits' invalid", n)); + bits = (unsigned)n; + } - if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) { - luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n)); - exp = (unsigned)n; - } + if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) { + luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n)); + exp = (unsigned)n; + } + break; + case EVP_PKEY_DH: + /* dhparam field can contain a PEM encoded string. + The "dhparam" field takes precedence over "bits" */ + if (loadfield(L, 1, "dhparam", LUA_TSTRING, &dhparam)) + break; - if (loadfield(L, 1, "curve", LUA_TSTRING, &id)) { - if (!auxS_txt2nid(&curve, id)) - luaL_argerror(L, 1, lua_pushfstring(L, "%s: invalid curve", id)); - } + if (loadfield(L, 1, "bits", LUA_TNUMBER, &n)) { + luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `bits' invalid", n)); + bits = (unsigned)n; + } - /* dhparam field can contain a PEM encoded string. */ - loadfield(L, 1, "dhparam", LUA_TSTRING, &dhparam); + if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) { + luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n)); + exp = (unsigned)n; + } + break; + case EVP_PKEY_EC: + if (loadfield(L, 1, "curve", LUA_TSTRING, &id)) { + if (!auxS_txt2nid(&curve, id)) + luaL_argerror(L, 1, lua_pushfstring(L, "%s: invalid curve", id)); + } + break; + } creat: if (!(*ud = EVP_PKEY_new())) |