summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-12-01 23:13:25 +0100
committerCarl Hetherington <cth@carlh.net>2019-12-01 23:13:25 +0100
commit9a5809be580c1a12864d751a710f6783363d3de7 (patch)
tree2039fc251ed6bb5abcfe2fd6daa2fe572fac144e /src/util.cc
parentc78523806e89e4c43015816fcd20db2549992464 (diff)
Check that KDM validity periods are safely within the validity periods
of the signing certificate chain. This does cause problems when you try to create a KDM for a certificate you just made (due to the fact that certificates always have a start-valid time of "now") but hopefully this can be fixed up in another commit.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index d5b6cb9f..c6313b4c 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -376,3 +376,37 @@ dcp::indent (xmlpp::Element* element, int initial)
element->add_child_text (last, "\n" + spaces(initial));
}
}
+
+/** @return true if the day represented by \ref a is less than or
+ * equal to the one represented by \ref b, ignoring the time parts.
+ */
+bool
+dcp::day_less_than_or_equal (struct tm a, LocalTime b)
+{
+ if ((a.tm_year + 1900) != b.year()) {
+ return (a.tm_year + 1900) < b.year();
+ }
+
+ if ((a.tm_mon + 1) != b.month()) {
+ return (a.tm_mon + 1) < b.month();
+ }
+
+ return a.tm_mday <= b.day();
+}
+
+/** @return true if the day represented by \ref a is greater than or
+ * equal to the one represented by \ref b, ignoring the time parts.
+ */
+bool
+dcp::day_greater_than_or_equal (struct tm a, LocalTime b)
+{
+ if ((a.tm_year + 1900) != b.year()) {
+ return (a.tm_year + 1900) > b.year();
+ }
+
+ if ((a.tm_mon + 1) != b.month()) {
+ return (a.tm_mon + 1) > b.month();
+ }
+
+ return a.tm_mday >= b.day();
+}