2 Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
24 #include <dcp/certificate.h>
25 #include <boost/optional.hpp>
32 using std::shared_ptr;
34 using boost::optional;
38 check_kdm_and_certificate_validity_periods(dcp::Certificate const& recipient, dcp::LocalTime kdm_from, dcp::LocalTime kdm_to)
40 auto overlaps = [](dcp::LocalTime from_a, dcp::LocalTime to_a, dcp::LocalTime from_b, dcp::LocalTime to_b) {
41 return std::max(from_a, from_b) < std::min(to_a, to_b);
44 auto contains = [](dcp::LocalTime bigger_from, dcp::LocalTime bigger_to, dcp::LocalTime smaller_from, dcp::LocalTime smaller_to) {
45 return bigger_from <= smaller_from && bigger_to >= smaller_to;
48 if (contains(recipient.not_before(), recipient.not_after(), kdm_from, kdm_to)) {
49 return KDMCertificatePeriod::KDM_WITHIN_CERTIFICATE;
52 if (overlaps(recipient.not_before(), recipient.not_after(), kdm_from, kdm_to)) {
53 /* The KDM overlaps the certificate validity: maybe not the end of the world */
54 return KDMCertificatePeriod::KDM_OVERLAPS_CERTIFICATE;
56 /* The KDM validity is totally outside the certificate validity: bad news */
57 return KDMCertificatePeriod::KDM_OUTSIDE_CERTIFICATE;