diff options
author | william <william@25tandclement.com> | 2014-03-26 20:10:43 -0700 |
---|---|---|
committer | william <william@25tandclement.com> | 2014-03-26 20:10:43 -0700 |
commit | 805a837b3e5476bad85116718d3be3a4c213ee20 (patch) | |
tree | 72cbd0880daad456f02d80bb6ad89fe270371d2a /src | |
parent | 24ed2644463f26eb84ac6d96d8305c8766e96acb (diff) | |
download | luaossl-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
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) { static int pk__tostring(lua_State *L) { EVP_PKEY *key = checksimple(L, 1, PUBKEY_CLASS); + int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); BIO *bio = getbio(L); - char *pem; + char *data; long len; - int ok; + int ok = 0; - if (!PEM_write_bio_PUBKEY(bio, key)) - return throwssl(L, "pubkey:__tostring"); + switch (type) { + case X509_PEM: + if (!PEM_write_bio_PUBKEY(bio, key)) + return throwssl(L, "pubkey:__tostring"); + break; + case X509_DER: + if (!i2d_PUBKEY_bio(bio, key)) + return throwssl(L, "pubkey:__tostring"); + break; + } /* switch() */ - len = BIO_get_mem_data(bio, &pem); - lua_pushlstring(L, pem, len); + len = BIO_get_mem_data(bio, &data); + + lua_pushlstring(L, data, len); return 1; } /* pk__tostring() */ |