+ map<shared_ptr<const dcp::ReelMXF>, dcp::Key> keys;
+
+ BOOST_FOREACH(shared_ptr<const dcp::ReelAsset> i, cpl->reel_assets ()) {
+ shared_ptr<const dcp::ReelMXF> mxf = boost::dynamic_pointer_cast<const dcp::ReelMXF> (i);
+ if (!mxf || !mxf->key_id()) {
+ continue;
+ }
+
+ /* Get any imported key for this ID */
+ bool done = false;
+ BOOST_FOREACH (dcp::DecryptedKDMKey j, imported_keys) {
+ if (j.id() == mxf->key_id().get()) {
+ LOG_GENERAL ("Using imported key for %1", mxf->key_id().get());
+ keys[mxf] = j.key();
+ done = true;
+ }
+ }
+
+ if (!done) {
+ /* No imported key; it must be an asset that we encrypted */
+ LOG_GENERAL ("Using our own key for %1", mxf->key_id().get());
+ keys[mxf] = key();
+ }
+ }
+
+ return dcp::DecryptedKDM (
+ cpl->id(), keys, from, until, cpl->content_title_text(), cpl->content_title_text(), dcp::LocalTime().as_string()
+ ).encrypt (signer, recipient, trusted_devices, formulation, disable_forensic_marking_picture, disable_forensic_marking_audio);
+}
+
+/** @param screens Screens to make KDMs for.
+ * @param cpl_file Path to CPL to make KDMs for.
+ * @param from KDM from time expressed as a local time in the time zone of the Screen's Cinema.
+ * @param until KDM to time expressed as a local time in the time zone of the Screen's Cinema.
+ * @param formulation KDM formulation to use.
+ * @param disable_forensic_marking_picture true to disable forensic marking of picture.
+ * @param disable_forensic_marking_audio if not set, don't disable forensic marking of audio. If set to 0,
+ * disable all forensic marking; if set above 0, disable forensic marking above that channel.