Use kdm_for_screen also in dcpomatic_kdm
authorCarl Hetherington <cth@carlh.net>
Sat, 28 Jan 2023 23:59:48 +0000 (00:59 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 11 Feb 2023 21:26:38 +0000 (22:26 +0100)
src/tools/dcpomatic_kdm.cc

index 0d79d67a88245c02f75420bc0e485b5ad2b0e3f5..2e28b548abb96b0e2b99e396f858c1c6ef4ca564 100644 (file)
@@ -377,46 +377,40 @@ private:
 
                        vector<KDMCertificatePeriod> period_checks;
 
-                       for (auto i: _screens->screens()) {
-
-                               if (!i->recipient) {
-                                       continue;
-                               }
-
-                               dcp::LocalTime begin(_timing->from(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
-                               dcp::LocalTime end(_timing->until(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
-
-                               period_checks.push_back(check_kdm_and_certificate_validity_periods(*i->recipient, begin, end));
-
+                       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [decrypted, title](dcp::LocalTime begin, dcp::LocalTime end) {
                                /* Make an empty KDM */
                                dcp::DecryptedKDM kdm (
                                        begin,
                                        end,
-                                       decrypted.annotation_text().get_value_or (""),
+                                       decrypted.annotation_text().get_value_or(""),
                                        title,
                                        dcp::LocalTime().as_string()
                                        );
 
                                /* Add keys from the DKDM */
                                for (auto const& j: decrypted.keys()) {
-                                       kdm.add_key (j);
+                                       kdm.add_key(j);
                                }
 
-                               auto const encrypted = kdm.encrypt(
-                                               signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
-                                               !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
-                                               );
-
-                               dcp::NameFormat::Map name_values;
-                               name_values['c'] = i->cinema->name;
-                               name_values['s'] = i->name;
-                               name_values['f'] = title;
-                               name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
-                               name_values['e'] = end.date() + " " + end.time_of_day(true, false);
-                               name_values['i'] = encrypted.cpl_id ();
-
-                               /* Encrypt */
-                               kdms.push_back (make_shared<KDMWithMetadata>(name_values, i->cinema.get(), i->cinema->emails, encrypted));
+                               return kdm;
+                       };
+
+                       for (auto i: _screens->screens()) {
+
+                               auto kdm = kdm_for_screen(
+                                       make_kdm,
+                                       i,
+                                       _timing->from(),
+                                       _timing->until(),
+                                       _output->formulation(),
+                                       !_output->forensic_mark_video(),
+                                       _output->forensic_mark_audio() ? boost::optional<int>() : 0,
+                                       period_checks
+                                       );
+
+                               if (kdm) {
+                                       kdms.push_back(kdm);
+                               }
                        }
 
                        if (kdms.empty()) {