static int nixio_tls_ctx_set_key(lua_State *L) {
SSL_CTX *ctx = nixio__checktlsctx(L);
const char *cert = luaL_checkstring(L, 2);
- const int ktype = SSL_FILETYPE_PEM;
+ const char *type = luaL_optstring(L, 3, "pem");
+ int ktype;
+
+ if (!strcmp(type, "pem")) {
+ ktype = SSL_FILETYPE_PEM;
+ } else if (!strcmp(type, "asn1")) {
+ ktype = SSL_FILETYPE_ASN1;
+ } else {
+ return luaL_argerror(L, 3, "supported values: pem, asn1");
+ }
+
return nixio__tls_pstatus(L, SSL_CTX_use_PrivateKey_file(ctx, cert, ktype));
}