return -1;
}
- if (not_before_p) *not_before_p = fr_unix_time_from_sec(not_before);
- if (not_after_p) *not_after_p = fr_unix_time_from_sec(not_after);
+ if (not_before_p) *not_before_p = fr_unix_time_from_time(not_before);
+ if (not_after_p) *not_after_p = fr_unix_time_from_time(not_after);
/*
* Check the cert hasn't expired
if (fr_time_from_sec(not_after) < now) {
fr_strerror_printf("Certificate has expired. "
"Validity period (notAfter) ends %pV, current time is %pV",
- fr_box_date(fr_unix_time_from_sec(not_before)), fr_box_date(now));
+ fr_box_date(fr_unix_time_from_time(not_before)), fr_box_date(now));
return -2;
}
if (fr_time_from_sec(not_before) > now) {
fr_strerror_printf("Certificate is not yet valid. "
"Validity period (notBefore) starts %pV, current time is %pV",
- fr_box_date(fr_unix_time_from_sec(not_before)), fr_box_date(now));
+ fr_box_date(fr_unix_time_from_time(not_before)), fr_box_date(now));
return -3;
}
}
MEM(fr_pair_append_by_da(ctx, &vp, pair_list, attr_tls_certificate_not_before) == 0);
- vp->vp_date = fr_unix_time_from_sec(time);
+ vp->vp_date = fr_unix_time_from_time(time);
/*
* Not valid after
}
MEM(fr_pair_append_by_da(ctx, &vp, pair_list, attr_tls_certificate_not_after) == 0);
- vp->vp_date = fr_unix_time_from_sec(time);
+ vp->vp_date = fr_unix_time_from_time(time);
/*
* Get the RFC822 Subject Alternative Name
/*
* Need cast because of difference in sign
*/
-#define fr_unix_time_from_nsec(_x) ((_x) < 0 ? 0 : (fr_unix_time_t)(_x))
-#define fr_unix_time_from_usec(_x) ((_x) < 0 ? 0 : (fr_unix_time_t)fr_time_delta_from_usec((fr_time_delta_t)(_x)))
-#define fr_unix_time_from_msec(_x) ((_x) < 0 ? 0 : (fr_unix_time_t)fr_time_delta_from_msec((fr_time_delta_t)(_x)))
-#define fr_unix_time_from_sec(_x) ((_x) < 0 ? 0 : (fr_unix_time_t)fr_time_delta_from_sec((fr_time_delta_t)(_x)))
+#define fr_unix_time_from_nsec(_x) (fr_unix_time_t)(_x)
+#define fr_unix_time_from_usec(_x) (fr_unix_time_t)fr_time_delta_from_usec((fr_time_delta_t)(_x))
+#define fr_unix_time_from_msec(_x) (fr_unix_time_t)fr_time_delta_from_msec((fr_time_delta_t)(_x))
+#define fr_unix_time_from_sec(_x) (fr_unix_time_t)fr_time_delta_from_sec((fr_time_delta_t)(_x))
+
+/** Covert a time_t into out internal fr_unix_time_t
+ *
+ * Our internal unix time representation is unsigned and in nanoseconds which
+ * is different from time_t which is signed and has seconds resolution.
+ *
+ * If time is negative we return 0.
+ *
+ * @param[in] time to convert.
+ * @return Unix time in seconds.
+ */
+static inline CC_HINT(nonnull) fr_unix_time_t fr_unix_time_from_time(time_t time)
+{
+ if (time < 0) return 0;
+
+ return (time * NSEC);
+}
#define fr_unix_time_to_nsec(_x) (uint64_t)(_x)
#define fr_unix_time_to_usec(_x) (uint64_t)fr_time_delta_to_usec(_x)