diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/openssl.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/openssl.c b/src/openssl.c index 0a6c996..7d62796 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -1194,16 +1194,26 @@ static int pk_toPEM(lua_State *L) { | |||
| 1194 | 1194 | ||
| 1195 | static int pk__tostring(lua_State *L) { | 1195 | static int pk__tostring(lua_State *L) { |
| 1196 | EVP_PKEY *key = checksimple(L, 1, PUBKEY_CLASS); | 1196 | EVP_PKEY *key = checksimple(L, 1, PUBKEY_CLASS); |
| 1197 | int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); | ||
| 1197 | BIO *bio = getbio(L); | 1198 | BIO *bio = getbio(L); |
| 1198 | char *pem; | 1199 | char *data; |
| 1199 | long len; | 1200 | long len; |
| 1200 | int ok; | 1201 | int ok = 0; |
| 1201 | 1202 | ||
| 1202 | if (!PEM_write_bio_PUBKEY(bio, key)) | 1203 | switch (type) { |
| 1203 | return throwssl(L, "pubkey:__tostring"); | 1204 | case X509_PEM: |
| 1205 | if (!PEM_write_bio_PUBKEY(bio, key)) | ||
| 1206 | return throwssl(L, "pubkey:__tostring"); | ||
| 1207 | break; | ||
| 1208 | case X509_DER: | ||
| 1209 | if (!i2d_PUBKEY_bio(bio, key)) | ||
| 1210 | return throwssl(L, "pubkey:__tostring"); | ||
| 1211 | break; | ||
| 1212 | } /* switch() */ | ||
| 1204 | 1213 | ||
| 1205 | len = BIO_get_mem_data(bio, &pem); | 1214 | len = BIO_get_mem_data(bio, &data); |
| 1206 | lua_pushlstring(L, pem, len); | 1215 | |
| 1216 | lua_pushlstring(L, data, len); | ||
| 1207 | 1217 | ||
| 1208 | return 1; | 1218 | return 1; |
| 1209 | } /* pk__tostring() */ | 1219 | } /* pk__tostring() */ |
