Cleanup: extract encrypt() call from Film::make_kdm().
[dcpomatic.git] / src / tools / dcpomatic.cc
index deaa15afd05343ce438ce2247f912c74c09fc92c..1923a12a3f4305e964d53e6718ff6e1936680a85 100644 (file)
@@ -944,34 +944,30 @@ private:
                dcp::LocalTime to (Config::instance()->signer_chain()->leaf().not_after());
                to.add_days (-1);
 
-               optional<dcp::EncryptedKDM> kdm;
-               try {
-                       kdm = _film->make_kdm (
-                               Config::instance()->decryption_chain()->leaf(),
-                               vector<string>(),
-                               dialog.cpl(),
-                               from, to,
-                               dcp::Formulation::MODIFIED_TRANSITIONAL_1,
-                               true,
-                               0
-                               );
-               } catch (dcp::NotEncryptedError& e) {
-                       error_dialog (this, _("CPL's content is not encrypted."));
-               } catch (exception& e) {
-                       error_dialog (this, e.what ());
-               } catch (...) {
-                       error_dialog (this, _("An unknown exception occurred."));
+               auto signer = Config::instance()->signer_chain();
+               if (!signer->valid()) {
+                       error_dialog(this, _("The certificate chain for signing is invalid"));
+                       return;
                }
 
-               if (kdm) {
+               optional<dcp::EncryptedKDM> kdm;
+               try {
+                       auto const decrypted_kdm = _film->make_kdm(dialog.cpl(), from, to);
+                       auto const kdm = decrypted_kdm.encrypt(signer, Config::instance()->decryption_chain()->leaf(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, true, 0);
                        if (dialog.internal()) {
                                auto dkdms = Config::instance()->dkdms();
-                               dkdms->add (make_shared<DKDM>(kdm.get()));
+                               dkdms->add(make_shared<DKDM>(kdm));
                                Config::instance()->changed ();
                        } else {
                                auto path = dialog.directory() / (_film->dcp_name(false) + "_DKDM.xml");
-                               kdm->as_xml (path);
+                               kdm.as_xml(path);
                        }
+               } catch (dcp::NotEncryptedError& e) {
+                       error_dialog (this, _("CPL's content is not encrypted."));
+               } catch (exception& e) {
+                       error_dialog (this, e.what ());
+               } catch (...) {
+                       error_dialog (this, _("An unknown exception occurred."));
                }
        }