+ /* Find keys that have been added to imported, encrypted DCP content */
+ list<dcp::DecryptedKDMKey> imported_keys;
+ BOOST_FOREACH (shared_ptr<Content> i, content()) {
+ shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (i);
+ if (d && d->kdm()) {
+ dcp::DecryptedKDM kdm (d->kdm().get(), Config::instance()->decryption_chain()->key().get());
+ list<dcp::DecryptedKDMKey> keys = kdm.keys ();
+ copy (keys.begin(), keys.end(), back_inserter (imported_keys));
+ }
+ }
+
+ 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()) {
+ keys[mxf] = j.key();
+ done = true;
+ }
+ }
+
+ if (!done) {
+ /* No imported key; it must be an asset that we encrypted */
+ keys[mxf] = key();
+ }
+ }
+