summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwilliam <william@25tandclement.com>2014-03-26 20:10:43 -0700
committerwilliam <william@25tandclement.com>2014-03-26 20:10:43 -0700
commit805a837b3e5476bad85116718d3be3a4c213ee20 (patch)
tree72cbd0880daad456f02d80bb6ad89fe270371d2a
parent24ed2644463f26eb84ac6d96d8305c8766e96acb (diff)
downloadluaossl-805a837b3e5476bad85116718d3be3a4c213ee20.tar.gz
luaossl-805a837b3e5476bad85116718d3be3a4c213ee20.tar.bz2
luaossl-805a837b3e5476bad85116718d3be3a4c213ee20.zip
add DER parameter to pk__tostring for symmetry, but we still need to refactor stringification APIs because it's unuseable as-is
-rw-r--r--src/openssl.c22
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
1195static int pk__tostring(lua_State *L) { 1195static 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() */