1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
From 3f9c54caeb4b70c4e3a1776951b13daec3accf07 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 30 Apr 2018 13:19:28 +0300
Subject: [PATCH 1/5] pkey: getPrivateKey method
---
src/openssl.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/openssl.c b/src/openssl.c
index 5d757a2..0df6b61 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -4103,6 +4103,20 @@ static int pk_toPEM(lua_State *L) {
} /* pk_toPEM() */
+static int pk_getPrivateKey(lua_State *L) {
+ BIO *bio = getbio(L);
+ char *str;
+ long len;
+
+ if (!PEM_write_bio_PrivateKey(bio, checksimple(L, 1, PKEY_CLASS), 0, 0, 0, 0, 0))
+ return auxL_error(L, auxL_EOPENSSL, "pkey:getPrivateKey");
+ len = BIO_get_mem_data(bio, &str);
+ lua_pushlstring(L, str, len);
+
+ return 1;
+} /* pk_getPrivateKey() */
+
+
static int pk_getDefaultDigestName(lua_State *L) {
EVP_PKEY *key = checksimple(L, 1, PKEY_CLASS);
int nid;
@@ -4680,6 +4694,7 @@ static const auxL_Reg pk_methods[] = {
{ "toPEM", &pk_toPEM },
{ "tostring", &pk__tostring },
{ "verify", &pk_verify },
+ { "getPrivateKey", &pk_getPrivateKey },
{ NULL, NULL },
};
--
2.18.0
|