summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwilliam <william@25tandclement.com>2014-05-09 19:13:17 -0700
committerwilliam <william@25tandclement.com>2014-05-09 19:13:17 -0700
commit74a0cb8873f5760f12c9e96e03dee26c126a84c2 (patch)
treea644405da8d0abb74ef88b2fe139a3f21a2643ed
parentd8839927530dcb8ea8ceb6a874146cb13d2c33a5 (diff)
downloadluaossl-74a0cb8873f5760f12c9e96e03dee26c126a84c2.tar.gz
luaossl-74a0cb8873f5760f12c9e96e03dee26c126a84c2.tar.bz2
luaossl-74a0cb8873f5760f12c9e96e03dee26c126a84c2.zip
replace getUpdateTimes/setUpdateTimes with getLastUpdate/setLastUpdate and getNextUpdate/setNextUpdate, because the semantics don't quite match that of crt:getLifetime, which it was copied from
-rw-r--r--src/openssl.c107
1 files changed, 64 insertions, 43 deletions
diff --git a/src/openssl.c b/src/openssl.c
index ef5515e..f2166f5 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -2894,7 +2894,9 @@ static int xx_new(lua_State *L) {
2894 X509_CRL **ud; 2894 X509_CRL **ud;
2895 2895
2896 ud = prepsimple(L, X509_CRL_CLASS); 2896 ud = prepsimple(L, X509_CRL_CLASS);
2897 if (!(*ud = X509_CRL_new())) throwssl(L, "x509.crl.new"); 2897
2898 if (!(*ud = X509_CRL_new()))
2899 return throwssl(L, "x509.crl.new");
2898 2900
2899 X509_gmtime_adj(X509_CRL_get_lastUpdate(*ud), 0); 2901 X509_gmtime_adj(X509_CRL_get_lastUpdate(*ud), 0);
2900 2902
@@ -2926,71 +2928,88 @@ static int xx_setVersion(lua_State *L) {
2926 lua_pushboolean(L, 1); 2928 lua_pushboolean(L, 1);
2927 2929
2928 return 1; 2930 return 1;
2929} /* xr_setVersion() */ 2931} /* xx_setVersion() */
2930 2932
2931 2933
2932static int xx_getUpdateTimes(lua_State *L) { 2934static int xx_getLastUpdate(lua_State *L) {
2933 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); 2935 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS);
2934 double begin = INFINITY, end = INFINITY; 2936 double updated = INFINITY;
2935 ASN1_TIME *time; 2937 ASN1_TIME *time;
2936 2938
2937 if ((time = X509_CRL_get_lastUpdate(crl))) 2939 if ((time = X509_CRL_get_lastUpdate(crl)))
2938 begin = timeutc(time); 2940 updated = timeutc(time);
2939
2940 if ((time = X509_CRL_get_nextUpdate(crl)))
2941 end = timeutc(time);
2942 2941
2943 if (isfinite(begin)) 2942 if (isfinite(updated))
2944 lua_pushnumber(L, begin); 2943 lua_pushnumber(L, 1);
2945 else 2944 else
2946 lua_pushnil(L); 2945 lua_pushnil(L);
2947 2946
2948 if (isfinite(end)) 2947 return 1;
2949 lua_pushnumber(L, end); 2948} /* xx_getLastUpdate() */
2950 else
2951 lua_pushnil(L);
2952 2949
2953 if (isfinite(begin) && isfinite(end) && begin <= end)
2954 lua_pushnumber(L, fabs(end - begin));
2955 else
2956 lua_pushnumber(L, 0.0);
2957 2950
2958 return 3; 2951static int xx_setLastUpdate(lua_State *L) {
2959} /* xx_getUpdateTimes() */ 2952 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS);
2953 double updated = luaL_checknumber(L, 2);
2954 ASN1_TIME *time = NULL;
2960 2955
2956 /* lastUpdate always present */
2957 if (!ASN1_TIME_set(X509_CRL_get_lastUpdate(crl), updated))
2958 return throwssl(L, "x509.crl:setLastUpdate");
2961 2959
2962static int xx_setUpdateTimes(lua_State *L) { 2960 lua_pushboolean(L, 1);
2963 int ok = 1; 2961
2962 return 1;
2963} /* xx_setLastUpdate() */
2964 2964
2965
2966static int xx_getNextUpdate(lua_State *L) {
2965 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); 2967 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS);
2966 double ut; 2968 double updateby = INFINITY;
2969 ASN1_TIME *time;
2970
2971 if ((time = X509_CRL_get_nextUpdate(crl)))
2972 updateby = timeutc(time);
2973
2974 if (isfinite(updateby))
2975 lua_pushnumber(L, 1);
2976 else
2977 lua_pushnil(L);
2978
2979 return 1;
2980} /* xx_getNextUpdate() */
2981
2982
2983static int xx_setNextUpdate(lua_State *L) {
2984 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS);
2985 double updateby = luaL_checknumber(L, 2);
2967 ASN1_TIME *time = NULL; 2986 ASN1_TIME *time = NULL;
2968 2987
2969 lua_settop(L, 3); 2988 if (X509_CRL_get_nextUpdate(crl)) {
2989 if (!ASN1_TIME_set(X509_CRL_get_nextUpdate(crl), updateby))
2990 goto error;
2991 } else {
2992 if (!(time = ASN1_TIME_new()))
2993 goto error;
2970 2994
2971 if (!lua_isnil(L, 2)) { 2995 if (!(ASN1_TIME_set(time, updateby)))
2972 ut = lua_tonumber(L, 2);
2973 if (!ASN1_TIME_set(X509_CRL_get_lastUpdate(crl), ut))
2974 goto error; 2996 goto error;
2975 }
2976 2997
2977 if (!lua_isnil(L, 3)) { 2998 if (!X509_CRL_set_nextUpdate(crl, time))
2978 ut = lua_tonumber(L, 3); 2999 goto error;
2979 if (!(time = ASN1_TIME_new())) goto error;
2980 if (!ASN1_TIME_set(time, ut)) goto error;
2981 if (!X509_CRL_set_nextUpdate(crl, time)) goto error;
2982 }
2983 3000
2984 goto done; 3001 time = NULL;
3002 }
2985 3003
2986 error: 3004 lua_pushboolean(L, 1);
2987 ok = 0;
2988 3005
2989 done: 3006 return 1;
2990 if (time) ASN1_TIME_free(time); 3007error:
3008 if (time)
3009 ASN1_TIME_free(time);
2991 3010
2992 return ok ? 0 : throwssl(L, "x509.crl:setUpdateTimes"); 3011 return throwssl(L, "x509.crl:setNextUpdate");
2993} /* xx_setUpdateTimes() */ 3012} /* xx_setNextUpdate() */
2994 3013
2995 3014
2996static int xx_getIssuer(lua_State *L) { 3015static int xx_getIssuer(lua_State *L) {
@@ -3107,8 +3126,10 @@ static int xx__gc(lua_State *L) {
3107static const luaL_Reg xx_methods[] = { 3126static const luaL_Reg xx_methods[] = {
3108 { "getVersion", &xx_getVersion }, 3127 { "getVersion", &xx_getVersion },
3109 { "setVersion", &xx_setVersion }, 3128 { "setVersion", &xx_setVersion },
3110 { "getUpdateTimes", &xx_getUpdateTimes }, 3129 { "getLastUpdate", &xx_getLastUpdate },
3111 { "setUpdateTimes", &xx_setUpdateTimes }, 3130 { "setLastUpdate", &xx_setLastUpdate },
3131 { "getNextUpdate", &xx_getNextUpdate },
3132 { "setNextUpdate", &xx_setNextUpdate },
3112 { "getIssuer", &xx_getIssuer }, 3133 { "getIssuer", &xx_getIssuer },
3113 { "setIssuer", &xx_setIssuer }, 3134 { "setIssuer", &xx_setIssuer },
3114 { "add", &xx_add }, 3135 { "add", &xx_add },