summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwilliam <william@25tandclement.com>2014-03-27 22:48:59 -0700
committerwilliam <william@25tandclement.com>2014-03-27 22:48:59 -0700
commit8e755dcc092f0f46e7ff847d9672bfa7dde834c5 (patch)
tree142f296ade0e14b2706411aa899cd4b9b3659b47
parentca15b450d7dec0d24f56a5d8247cd7bc67e1ac4b (diff)
downloadluaossl-8e755dcc092f0f46e7ff847d9672bfa7dde834c5.tar.gz
luaossl-8e755dcc092f0f46e7ff847d9672bfa7dde834c5.tar.bz2
luaossl-8e755dcc092f0f46e7ff847d9672bfa7dde834c5.zip
rename openssl.pubkey identifiers to openssl.pkey
-rw-r--r--src/openssl.c98
-rw-r--r--src/openssl.pubkey.lua4
2 files changed, 55 insertions, 47 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 7a03c97..5fcf76d 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -64,7 +64,7 @@
64#endif 64#endif
65 65
66#define BIGNUM_CLASS "BIGNUM*" 66#define BIGNUM_CLASS "BIGNUM*"
67#define PUBKEY_CLASS "EVP_PKEY*" 67#define PKEY_CLASS "EVP_PKEY*"
68#define X509_NAME_CLASS "X509_NAME*" 68#define X509_NAME_CLASS "X509_NAME*"
69#define X509_GENS_CLASS "GENERAL_NAMES*" 69#define X509_GENS_CLASS "GENERAL_NAMES*"
70#define X509_CERT_CLASS "X509*" 70#define X509_CERT_CLASS "X509*"
@@ -706,7 +706,7 @@ int luaopen__openssl_bignum(lua_State *L) {
706 706
707 707
708/* 708/*
709 * EVP_PKEY - openssl.pubkey 709 * EVP_PKEY - openssl.pkey
710 * 710 *
711 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 711 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
712 712
@@ -753,7 +753,7 @@ static int pk_new(lua_State *L) {
753 /* #1 table or key; if key, #2 format and #3 type */ 753 /* #1 table or key; if key, #2 format and #3 type */
754 lua_settop(L, 3); 754 lua_settop(L, 3);
755 755
756 ud = prepsimple(L, PUBKEY_CLASS); 756 ud = prepsimple(L, PKEY_CLASS);
757 757
758 if (lua_istable(L, 1) || lua_isnil(L, 1)) { 758 if (lua_istable(L, 1) || lua_isnil(L, 1)) {
759 int type = EVP_PKEY_RSA; 759 int type = EVP_PKEY_RSA;
@@ -806,14 +806,14 @@ static int pk_new(lua_State *L) {
806 806
807creat: 807creat:
808 if (!(*ud = EVP_PKEY_new())) 808 if (!(*ud = EVP_PKEY_new()))
809 return throwssl(L, "pubkey.new"); 809 return throwssl(L, "pkey.new");
810 810
811 switch (EVP_PKEY_type(type)) { 811 switch (EVP_PKEY_type(type)) {
812 case EVP_PKEY_RSA: { 812 case EVP_PKEY_RSA: {
813 RSA *rsa; 813 RSA *rsa;
814 814
815 if (!(rsa = RSA_generate_key(bits, exp, 0, 0))) 815 if (!(rsa = RSA_generate_key(bits, exp, 0, 0)))
816 return throwssl(L, "pubkey.new"); 816 return throwssl(L, "pkey.new");
817 817
818 EVP_PKEY_set1_RSA(*ud, rsa); 818 EVP_PKEY_set1_RSA(*ud, rsa);
819 819
@@ -825,11 +825,11 @@ creat:
825 DSA *dsa; 825 DSA *dsa;
826 826
827 if (!(dsa = DSA_generate_parameters(bits, 0, 0, 0, 0, 0, 0))) 827 if (!(dsa = DSA_generate_parameters(bits, 0, 0, 0, 0, 0, 0)))
828 return throwssl(L, "pubkey.new"); 828 return throwssl(L, "pkey.new");
829 829
830 if (!DSA_generate_key(dsa)) { 830 if (!DSA_generate_key(dsa)) {
831 DSA_free(dsa); 831 DSA_free(dsa);
832 return throwssl(L, "pubkey.new"); 832 return throwssl(L, "pkey.new");
833 } 833 }
834 834
835 EVP_PKEY_set1_DSA(*ud, dsa); 835 EVP_PKEY_set1_DSA(*ud, dsa);
@@ -842,11 +842,11 @@ creat:
842 DH *dh; 842 DH *dh;
843 843
844 if (!(dh = DH_generate_parameters(bits, exp, 0, 0))) 844 if (!(dh = DH_generate_parameters(bits, exp, 0, 0)))
845 return throwssl(L, "pubkey.new"); 845 return throwssl(L, "pkey.new");
846 846
847 if (!DH_generate_key(dh)) { 847 if (!DH_generate_key(dh)) {
848 DH_free(dh); 848 DH_free(dh);
849 return throwssl(L, "pubkey.new"); 849 return throwssl(L, "pkey.new");
850 } 850 }
851 851
852 EVP_PKEY_set1_DH(*ud, dh); 852 EVP_PKEY_set1_DH(*ud, dh);
@@ -861,7 +861,7 @@ creat:
861 EC_KEY *key; 861 EC_KEY *key;
862 862
863 if (!(grp = EC_GROUP_new_by_curve_name(curve))) 863 if (!(grp = EC_GROUP_new_by_curve_name(curve)))
864 return throwssl(L, "pubkey.new"); 864 return throwssl(L, "pkey.new");
865 865
866 EC_GROUP_set_asn1_flag(grp, OPENSSL_EC_NAMED_CURVE); 866 EC_GROUP_set_asn1_flag(grp, OPENSSL_EC_NAMED_CURVE);
867 867
@@ -870,7 +870,7 @@ creat:
870 870
871 if (!(key = EC_KEY_new())) { 871 if (!(key = EC_KEY_new())) {
872 EC_GROUP_free(grp); 872 EC_GROUP_free(grp);
873 return throwssl(L, "pubkey.new"); 873 return throwssl(L, "pkey.new");
874 } 874 }
875 875
876 EC_KEY_set_group(key, grp); 876 EC_KEY_set_group(key, grp);
@@ -879,7 +879,7 @@ creat:
879 879
880 if (!EC_KEY_generate_key(key)) { 880 if (!EC_KEY_generate_key(key)) {
881 EC_KEY_free(key); 881 EC_KEY_free(key);
882 return throwssl(L, "pubkey.new"); 882 return throwssl(L, "pkey.new");
883 } 883 }
884 884
885 EVP_PKEY_set1_EC_KEY(*ud, key); 885 EVP_PKEY_set1_EC_KEY(*ud, key);
@@ -914,7 +914,7 @@ creat:
914 data = luaL_checklstring(L, 1, &len); 914 data = luaL_checklstring(L, 1, &len);
915 915
916 if (!(bio = BIO_new_mem_buf((void *)data, len))) 916 if (!(bio = BIO_new_mem_buf((void *)data, len)))
917 return throwssl(L, "pubkey.new"); 917 return throwssl(L, "pkey.new");
918 918
919 if (type == X509_PEM || type == X509_ANY) { 919 if (type == X509_PEM || type == X509_ANY) {
920 if (ispub == 1 || ispub == -1) { 920 if (ispub == 1 || ispub == -1) {
@@ -952,7 +952,7 @@ done:
952 BIO_free(bio); 952 BIO_free(bio);
953 953
954 if (!ok) 954 if (!ok)
955 return throwssl(L, "pubkey.new"); 955 return throwssl(L, "pkey.new");
956 } else { 956 } else {
957 return luaL_error(L, "%s: unknown key initializer", lua_typename(L, lua_type(L, 1))); 957 return luaL_error(L, "%s: unknown key initializer", lua_typename(L, lua_type(L, 1)));
958 } 958 }
@@ -967,7 +967,7 @@ static int pk_interpose(lua_State *L) {
967 967
968 968
969static int pk_type(lua_State *L) { 969static int pk_type(lua_State *L) {
970 EVP_PKEY *key = checksimple(L, 1, PUBKEY_CLASS); 970 EVP_PKEY *key = checksimple(L, 1, PKEY_CLASS);
971 int nid = key->type; 971 int nid = key->type;
972 972
973 pushnid(L, nid); 973 pushnid(L, nid);
@@ -977,7 +977,7 @@ static int pk_type(lua_State *L) {
977 977
978 978
979static int pk_setPublicKey(lua_State *L) { 979static int pk_setPublicKey(lua_State *L) {
980 EVP_PKEY **key = luaL_checkudata(L, 1, PUBKEY_CLASS); 980 EVP_PKEY **key = luaL_checkudata(L, 1, PKEY_CLASS);
981 const char *data; 981 const char *data;
982 size_t len; 982 size_t len;
983 BIO *bio; 983 BIO *bio;
@@ -987,7 +987,7 @@ static int pk_setPublicKey(lua_State *L) {
987 type = optencoding(L, 3, "*", X509_ANY|X509_PEM|X509_DER); 987 type = optencoding(L, 3, "*", X509_ANY|X509_PEM|X509_DER);
988 988
989 if (!(bio = BIO_new_mem_buf((void *)data, len))) 989 if (!(bio = BIO_new_mem_buf((void *)data, len)))
990 return throwssl(L, "pubkey.new"); 990 return throwssl(L, "pkey.new");
991 991
992 if (type == X509_ANY || type == X509_PEM) { 992 if (type == X509_ANY || type == X509_PEM) {
993 ok = !!PEM_read_bio_PUBKEY(bio, key, 0, ""); 993 ok = !!PEM_read_bio_PUBKEY(bio, key, 0, "");
@@ -1000,7 +1000,7 @@ static int pk_setPublicKey(lua_State *L) {
1000 BIO_free(bio); 1000 BIO_free(bio);
1001 1001
1002 if (!ok) 1002 if (!ok)
1003 return throwssl(L, "pubkey.new"); 1003 return throwssl(L, "pkey.new");
1004 1004
1005 lua_pushboolean(L, 1); 1005 lua_pushboolean(L, 1);
1006 1006
@@ -1009,7 +1009,7 @@ static int pk_setPublicKey(lua_State *L) {
1009 1009
1010 1010
1011static int pk_setPrivateKey(lua_State *L) { 1011static int pk_setPrivateKey(lua_State *L) {
1012 EVP_PKEY **key = luaL_checkudata(L, 1, PUBKEY_CLASS); 1012 EVP_PKEY **key = luaL_checkudata(L, 1, PKEY_CLASS);
1013 const char *data; 1013 const char *data;
1014 size_t len; 1014 size_t len;
1015 BIO *bio; 1015 BIO *bio;
@@ -1019,7 +1019,7 @@ static int pk_setPrivateKey(lua_State *L) {
1019 type = optencoding(L, 3, "*", X509_ANY|X509_PEM|X509_DER); 1019 type = optencoding(L, 3, "*", X509_ANY|X509_PEM|X509_DER);
1020 1020
1021 if (!(bio = BIO_new_mem_buf((void *)data, len))) 1021 if (!(bio = BIO_new_mem_buf((void *)data, len)))
1022 return throwssl(L, "pubkey.new"); 1022 return throwssl(L, "pkey.new");
1023 1023
1024 if (type == X509_ANY || type == X509_PEM) { 1024 if (type == X509_ANY || type == X509_PEM) {
1025 ok = !!PEM_read_bio_PrivateKey(bio, key, 0, ""); 1025 ok = !!PEM_read_bio_PrivateKey(bio, key, 0, "");
@@ -1032,7 +1032,7 @@ static int pk_setPrivateKey(lua_State *L) {
1032 BIO_free(bio); 1032 BIO_free(bio);
1033 1033
1034 if (!ok) 1034 if (!ok)
1035 return throwssl(L, "pubkey.new"); 1035 return throwssl(L, "pkey.new");
1036 1036
1037 lua_pushboolean(L, 1); 1037 lua_pushboolean(L, 1);
1038 1038
@@ -1041,19 +1041,19 @@ static int pk_setPrivateKey(lua_State *L) {
1041 1041
1042 1042
1043static int pk_sign(lua_State *L) { 1043static int pk_sign(lua_State *L) {
1044 EVP_PKEY *key = checksimple(L, 1, PUBKEY_CLASS); 1044 EVP_PKEY *key = checksimple(L, 1, PKEY_CLASS);
1045 EVP_MD_CTX *md = luaL_checkudata(L, 2, DIGEST_CLASS); 1045 EVP_MD_CTX *md = luaL_checkudata(L, 2, DIGEST_CLASS);
1046 luaL_Buffer B; 1046 luaL_Buffer B;
1047 unsigned n; 1047 unsigned n;
1048 1048
1049 if (LUAL_BUFFERSIZE < EVP_PKEY_size(key)) 1049 if (LUAL_BUFFERSIZE < EVP_PKEY_size(key))
1050 return luaL_error(L, "pubkey:sign: LUAL_BUFFERSIZE(%u) < EVP_PKEY_size(%u)", (unsigned)LUAL_BUFFERSIZE, (unsigned)EVP_PKEY_size(key)); 1050 return luaL_error(L, "pkey:sign: LUAL_BUFFERSIZE(%u) < EVP_PKEY_size(%u)", (unsigned)LUAL_BUFFERSIZE, (unsigned)EVP_PKEY_size(key));
1051 1051
1052 luaL_buffinit(L, &B); 1052 luaL_buffinit(L, &B);
1053 n = LUAL_BUFFERSIZE; 1053 n = LUAL_BUFFERSIZE;
1054 1054
1055 if (!EVP_SignFinal(md, (void *)luaL_prepbuffer(&B), &n, key)) 1055 if (!EVP_SignFinal(md, (void *)luaL_prepbuffer(&B), &n, key))
1056 return throwssl(L, "pubkey:sign"); 1056 return throwssl(L, "pkey:sign");
1057 1057
1058 luaL_addsize(&B, n); 1058 luaL_addsize(&B, n);
1059 luaL_pushresult(&B); 1059 luaL_pushresult(&B);
@@ -1063,7 +1063,7 @@ static int pk_sign(lua_State *L) {
1063 1063
1064 1064
1065static int pk_verify(lua_State *L) { 1065static int pk_verify(lua_State *L) {
1066 EVP_PKEY *key = checksimple(L, 1, PUBKEY_CLASS); 1066 EVP_PKEY *key = checksimple(L, 1, PKEY_CLASS);
1067 size_t len; 1067 size_t len;
1068 const void *sig = luaL_checklstring(L, 2, &len); 1068 const void *sig = luaL_checklstring(L, 2, &len);
1069 EVP_MD_CTX *md = luaL_checkudata(L, 3, DIGEST_CLASS); 1069 EVP_MD_CTX *md = luaL_checkudata(L, 3, DIGEST_CLASS);
@@ -1079,7 +1079,7 @@ static int pk_verify(lua_State *L) {
1079 1079
1080 break; 1080 break;
1081 default: 1081 default:
1082 return throwssl(L, "pubkey:verify"); 1082 return throwssl(L, "pkey:verify");
1083 } 1083 }
1084 1084
1085 return 1; 1085 return 1;
@@ -1087,7 +1087,7 @@ static int pk_verify(lua_State *L) {
1087 1087
1088 1088
1089static int pk_toPEM(lua_State *L) { 1089static int pk_toPEM(lua_State *L) {
1090 EVP_PKEY *key = checksimple(L, 1, PUBKEY_CLASS); 1090 EVP_PKEY *key = checksimple(L, 1, PKEY_CLASS);
1091 int top, i, ok; 1091 int top, i, ok;
1092 BIO *bio; 1092 BIO *bio;
1093 char *pem; 1093 char *pem;
@@ -1111,7 +1111,7 @@ static int pk_toPEM(lua_State *L) {
1111 switch (checkoption(L, i, NULL, opts)) { 1111 switch (checkoption(L, i, NULL, opts)) {
1112 case 0: case 1: /* public, PublicKey */ 1112 case 0: case 1: /* public, PublicKey */
1113 if (!PEM_write_bio_PUBKEY(bio, key)) 1113 if (!PEM_write_bio_PUBKEY(bio, key))
1114 return throwssl(L, "pubkey:__tostring"); 1114 return throwssl(L, "pkey:__tostring");
1115 1115
1116 len = BIO_get_mem_data(bio, &pem); 1116 len = BIO_get_mem_data(bio, &pem);
1117 lua_pushlstring(L, pem, len); 1117 lua_pushlstring(L, pem, len);
@@ -1120,7 +1120,7 @@ static int pk_toPEM(lua_State *L) {
1120 break; 1120 break;
1121 case 2: case 3: /* private, PrivateKey */ 1121 case 2: case 3: /* private, PrivateKey */
1122 if (!PEM_write_bio_PrivateKey(bio, key, 0, 0, 0, 0, 0)) 1122 if (!PEM_write_bio_PrivateKey(bio, key, 0, 0, 0, 0, 0))
1123 throwssl(L, "pubkey:__tostring"); 1123 throwssl(L, "pkey:__tostring");
1124 1124
1125 len = BIO_get_mem_data(bio, &pem); 1125 len = BIO_get_mem_data(bio, &pem);
1126 lua_pushlstring(L, pem, len); 1126 lua_pushlstring(L, pem, len);
@@ -1140,7 +1140,7 @@ static int pk_toPEM(lua_State *L) {
1140 DSA_free(dsa); 1140 DSA_free(dsa);
1141 1141
1142 if (!ok) 1142 if (!ok)
1143 return throwssl(L, "pubkey:__tostring"); 1143 return throwssl(L, "pkey:__tostring");
1144 1144
1145 break; 1145 break;
1146 } 1146 }
@@ -1152,7 +1152,7 @@ static int pk_toPEM(lua_State *L) {
1152 DH_free(dh); 1152 DH_free(dh);
1153 1153
1154 if (!ok) 1154 if (!ok)
1155 return throwssl(L, "pubkey:__tostring"); 1155 return throwssl(L, "pkey:__tostring");
1156 1156
1157 break; 1157 break;
1158 } 1158 }
@@ -1166,7 +1166,7 @@ static int pk_toPEM(lua_State *L) {
1166 EC_KEY_free(ec); 1166 EC_KEY_free(ec);
1167 1167
1168 if (!ok) 1168 if (!ok)
1169 return throwssl(L, "pubkey:__tostring"); 1169 return throwssl(L, "pkey:__tostring");
1170 1170
1171 break; 1171 break;
1172 } 1172 }
@@ -1193,7 +1193,7 @@ static int pk_toPEM(lua_State *L) {
1193 1193
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, PKEY_CLASS);
1197 int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); 1197 int type = optencoding(L, 2, "pem", X509_PEM|X509_DER);
1198 BIO *bio = getbio(L); 1198 BIO *bio = getbio(L);
1199 char *data; 1199 char *data;
@@ -1203,11 +1203,11 @@ static int pk__tostring(lua_State *L) {
1203 switch (type) { 1203 switch (type) {
1204 case X509_PEM: 1204 case X509_PEM:
1205 if (!PEM_write_bio_PUBKEY(bio, key)) 1205 if (!PEM_write_bio_PUBKEY(bio, key))
1206 return throwssl(L, "pubkey:__tostring"); 1206 return throwssl(L, "pkey:__tostring");
1207 break; 1207 break;
1208 case X509_DER: 1208 case X509_DER:
1209 if (!i2d_PUBKEY_bio(bio, key)) 1209 if (!i2d_PUBKEY_bio(bio, key))
1210 return throwssl(L, "pubkey:__tostring"); 1210 return throwssl(L, "pkey:__tostring");
1211 break; 1211 break;
1212 } /* switch() */ 1212 } /* switch() */
1213 1213
@@ -1220,7 +1220,7 @@ static int pk__tostring(lua_State *L) {
1220 1220
1221 1221
1222static int pk__gc(lua_State *L) { 1222static int pk__gc(lua_State *L) {
1223 EVP_PKEY **ud = luaL_checkudata(L, 1, PUBKEY_CLASS); 1223 EVP_PKEY **ud = luaL_checkudata(L, 1, PKEY_CLASS);
1224 1224
1225 EVP_PKEY_free(*ud); 1225 EVP_PKEY_free(*ud);
1226 *ud = NULL; 1226 *ud = NULL;
@@ -1252,12 +1252,20 @@ static const luaL_Reg pk_globals[] = {
1252 { NULL, NULL }, 1252 { NULL, NULL },
1253}; 1253};
1254 1254
1255int luaopen__openssl_pubkey(lua_State *L) { 1255int luaopen__openssl_pkey(lua_State *L) {
1256 initall(L); 1256 initall(L);
1257 1257
1258 luaL_newlib(L, pk_globals); 1258 luaL_newlib(L, pk_globals);
1259 1259
1260 return 1; 1260 return 1;
1261} /* luaopen__openssl_pkey() */
1262
1263
1264/*
1265 * Deprecated module name.
1266 */
1267int luaopen__openssl_pubkey(lua_State *L) {
1268 return luaopen__openssl_pkey(L);
1261} /* luaopen__openssl_pubkey() */ 1269} /* luaopen__openssl_pubkey() */
1262 1270
1263 1271
@@ -2461,7 +2469,7 @@ done:
2461 2469
2462static int xc_getPublicKey(lua_State *L) { 2470static int xc_getPublicKey(lua_State *L) {
2463 X509 *crt = checksimple(L, 1, X509_CERT_CLASS); 2471 X509 *crt = checksimple(L, 1, X509_CERT_CLASS);
2464 EVP_PKEY **key = prepsimple(L, PUBKEY_CLASS); 2472 EVP_PKEY **key = prepsimple(L, PKEY_CLASS);
2465 2473
2466 if (!(*key = X509_get_pubkey(crt))) 2474 if (!(*key = X509_get_pubkey(crt)))
2467 return throwssl(L, "x509.cert:getPublicKey"); 2475 return throwssl(L, "x509.cert:getPublicKey");
@@ -2472,7 +2480,7 @@ static int xc_getPublicKey(lua_State *L) {
2472 2480
2473static int xc_setPublicKey(lua_State *L) { 2481static int xc_setPublicKey(lua_State *L) {
2474 X509 *crt = checksimple(L, 1, X509_CERT_CLASS); 2482 X509 *crt = checksimple(L, 1, X509_CERT_CLASS);
2475 EVP_PKEY *key = checksimple(L, 2, PUBKEY_CLASS); 2483 EVP_PKEY *key = checksimple(L, 2, PKEY_CLASS);
2476 2484
2477 if (!X509_set_pubkey(crt, key)) 2485 if (!X509_set_pubkey(crt, key))
2478 return throwssl(L, "x509.cert:setPublicKey"); 2486 return throwssl(L, "x509.cert:setPublicKey");
@@ -2504,7 +2512,7 @@ static const EVP_MD *xc_signature(lua_State *L, int index, EVP_PKEY *key) {
2504 2512
2505static int xc_sign(lua_State *L) { 2513static int xc_sign(lua_State *L) {
2506 X509 *crt = checksimple(L, 1, X509_CERT_CLASS); 2514 X509 *crt = checksimple(L, 1, X509_CERT_CLASS);
2507 EVP_PKEY *key = checksimple(L, 2, PUBKEY_CLASS); 2515 EVP_PKEY *key = checksimple(L, 2, PKEY_CLASS);
2508 2516
2509 if (!X509_sign(crt, key, xc_signature(L, 3, key))) 2517 if (!X509_sign(crt, key, xc_signature(L, 3, key)))
2510 return throwssl(L, "x509.cert:sign"); 2518 return throwssl(L, "x509.cert:sign");
@@ -2708,7 +2716,7 @@ static int xr_setSubject(lua_State *L) {
2708 2716
2709static int xr_getPublicKey(lua_State *L) { 2717static int xr_getPublicKey(lua_State *L) {
2710 X509_REQ *csr = checksimple(L, 1, X509_CSR_CLASS); 2718 X509_REQ *csr = checksimple(L, 1, X509_CSR_CLASS);
2711 EVP_PKEY **key = prepsimple(L, PUBKEY_CLASS); 2719 EVP_PKEY **key = prepsimple(L, PKEY_CLASS);
2712 2720
2713 if (!(*key = X509_REQ_get_pubkey(csr))) 2721 if (!(*key = X509_REQ_get_pubkey(csr)))
2714 return throwssl(L, "x509.cert:getPublicKey"); 2722 return throwssl(L, "x509.cert:getPublicKey");
@@ -2719,7 +2727,7 @@ static int xr_getPublicKey(lua_State *L) {
2719 2727
2720static int xr_setPublicKey(lua_State *L) { 2728static int xr_setPublicKey(lua_State *L) {
2721 X509_REQ *csr = checksimple(L, 1, X509_CSR_CLASS); 2729 X509_REQ *csr = checksimple(L, 1, X509_CSR_CLASS);
2722 EVP_PKEY *key = checksimple(L, 2, PUBKEY_CLASS); 2730 EVP_PKEY *key = checksimple(L, 2, PKEY_CLASS);
2723 2731
2724 if (!X509_REQ_set_pubkey(csr, key)) 2732 if (!X509_REQ_set_pubkey(csr, key))
2725 return throwssl(L, "x509.csr:setPublicKey"); 2733 return throwssl(L, "x509.csr:setPublicKey");
@@ -2732,7 +2740,7 @@ static int xr_setPublicKey(lua_State *L) {
2732 2740
2733static int xr_sign(lua_State *L) { 2741static int xr_sign(lua_State *L) {
2734 X509_REQ *csr = checksimple(L, 1, X509_CSR_CLASS); 2742 X509_REQ *csr = checksimple(L, 1, X509_CSR_CLASS);
2735 EVP_PKEY *key = checksimple(L, 2, PUBKEY_CLASS); 2743 EVP_PKEY *key = checksimple(L, 2, PKEY_CLASS);
2736 2744
2737 if (!X509_REQ_sign(csr, key, xc_signature(L, 3, key))) 2745 if (!X509_REQ_sign(csr, key, xc_signature(L, 3, key)))
2738 return throwssl(L, "x509.csr:sign"); 2746 return throwssl(L, "x509.csr:sign");
@@ -3309,7 +3317,7 @@ static int sx_setCertificate(lua_State *L) {
3309 3317
3310static int sx_setPrivateKey(lua_State *L) { 3318static int sx_setPrivateKey(lua_State *L) {
3311 SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); 3319 SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
3312 EVP_PKEY *key = checksimple(L, 2, PUBKEY_CLASS); 3320 EVP_PKEY *key = checksimple(L, 2, PKEY_CLASS);
3313 3321
3314 /* 3322 /*
3315 * NOTE: No easy way to dup the key, but a shared reference should 3323 * NOTE: No easy way to dup the key, but a shared reference should
@@ -4214,7 +4222,7 @@ static void initall(lua_State *L) {
4214 pthread_mutex_unlock(&mutex); 4222 pthread_mutex_unlock(&mutex);
4215 4223
4216 addclass(L, BIGNUM_CLASS, bn_methods, bn_metatable); 4224 addclass(L, BIGNUM_CLASS, bn_methods, bn_metatable);
4217 addclass(L, PUBKEY_CLASS, pk_methods, pk_metatable); 4225 addclass(L, PKEY_CLASS, pk_methods, pk_metatable);
4218 addclass(L, X509_NAME_CLASS, xn_methods, xn_metatable); 4226 addclass(L, X509_NAME_CLASS, xn_methods, xn_metatable);
4219 addclass(L, X509_GENS_CLASS, gn_methods, gn_metatable); 4227 addclass(L, X509_GENS_CLASS, gn_methods, gn_metatable);
4220 addclass(L, X509_CERT_CLASS, xc_methods, xc_metatable); 4228 addclass(L, X509_CERT_CLASS, xc_methods, xc_metatable);
diff --git a/src/openssl.pubkey.lua b/src/openssl.pubkey.lua
index 6dc5614..2cbd6d2 100644
--- a/src/openssl.pubkey.lua
+++ b/src/openssl.pubkey.lua
@@ -1,4 +1,4 @@
1local pubkey = require"_openssl.pubkey" 1local pkey = require"_openssl.pkey"
2 2
3return pubkey 3return pkey
4 4