Tidy up KDM generation from CPLs a bit.
authorCarl Hetherington <cth@carlh.net>
Sun, 20 Jul 2014 14:11:57 +0000 (15:11 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 20 Jul 2014 14:11:57 +0000 (15:11 +0100)
17 files changed:
src/cpl.cc
src/cpl.h
src/decrypted_kdm.cc
src/decrypted_kdm.h
src/exceptions.h
src/mxf.h
src/picture_mxf.cc
src/picture_mxf.h
src/reel_mxf_asset.h
src/reel_picture_asset.cc
src/reel_picture_asset.h
src/reel_sound_asset.cc
src/reel_sound_asset.h
src/sound_mxf.cc
src/sound_mxf.h
test/encryption_test.cc
test/round_trip_test.cc

index 535fd77f65d7ba2611d8a0915b5ec6631d94cde7..b76e827262354201f69c086a477e8277917ffee2 100644 (file)
@@ -153,20 +153,20 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
        set_file (file);
 }
 
-list<shared_ptr<const Content> >
-CPL::content () const
+list<shared_ptr<const ReelAsset> >
+CPL::reel_assets () const
 {
-       list<shared_ptr<const Content> > c;
+       list<shared_ptr<const ReelAsset> > c;
 
        for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
                if ((*i)->main_picture ()) {
-                       c.push_back ((*i)->main_picture()->mxf ());
+                       c.push_back ((*i)->main_picture());
                }
                if ((*i)->main_sound ()) {
-                       c.push_back ((*i)->main_sound()->mxf ());
+                       c.push_back ((*i)->main_sound());
                }
                if ((*i)->main_subtitle ()) {
-                       c.push_back ((*i)->main_subtitle()->subtitle_content ());
+                       c.push_back ((*i)->main_subtitle());
                }
        }
 
index 164ed734eb7f421e03a52d329466024821bdda0b..431aef7deb88c156ed15bdd031ef8d8006db64da 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -1,7 +1,7 @@
 /*
     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This program is free software; you -can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
@@ -38,7 +38,7 @@
 
 namespace dcp {
        
-class Content;
+class ReelAsset;
 class Reel;
 class XMLMetadata;
 class MXFMetadata;
@@ -95,10 +95,9 @@ public:
                return _reels;
        }
 
-       /** @return the Content in this CPL across all its reels
-        *  (Content is picture, sound and subtitles)
+       /** @return the ReelAssets in this CPL in all reels.
         */
-       std::list<boost::shared_ptr<const Content> > content () const;
+       std::list<boost::shared_ptr<const ReelAsset> > reel_assets () const;
 
        bool encrypted () const;
 
index 556cd9d54316e9f86d35f4490b54d441aeec2a39..62162346bf28849a7531d739a293dba3eae4e861 100644 (file)
@@ -20,6 +20,7 @@
 #include "decrypted_kdm.h"
 #include "decrypted_kdm_key.h"
 #include "encrypted_kdm.h"
+#include "reel_mxf_asset.h"
 #include "util.h"
 #include "exceptions.h"
 #include "cpl.h"
@@ -184,6 +185,7 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
 
 DecryptedKDM::DecryptedKDM (
        boost::shared_ptr<const CPL> cpl,
+       Key key,
        LocalTime not_valid_before,
        LocalTime not_valid_after,
        string annotation_text,
@@ -197,15 +199,15 @@ DecryptedKDM::DecryptedKDM (
        , _issue_date (issue_date)
 {
        /* Create DecryptedKDMKey objects for each MXF asset */
-       list<shared_ptr<const Content> > content = cpl->content ();
-       for (list<shared_ptr<const Content> >::iterator i = content.begin(); i != content.end(); ++i) {
+       list<shared_ptr<const ReelAsset> > assets = cpl->reel_assets ();
+       for (list<shared_ptr<const ReelAsset> >::iterator i = assets.begin(); i != assets.end(); ++i) {
                /* XXX: do non-MXF assets need keys? */
-               shared_ptr<const MXF> mxf = boost::dynamic_pointer_cast<const MXF> (*i);
+               shared_ptr<const ReelMXFAsset> mxf = boost::dynamic_pointer_cast<const ReelMXFAsset> (*i);
                if (mxf) {
                        if (mxf->key_id().empty ()) {
-                               throw NotEncryptedError (mxf->file().string ());
+                               throw NotEncryptedError (mxf->id());
                        }
-                       _keys.push_back (DecryptedKDMKey (mxf->key_type(), mxf->key_id(), mxf->key().get (), cpl->id ()));
+                       _keys.push_back (DecryptedKDMKey (mxf->key_type(), mxf->key_id(), key, cpl->id ()));
                }
        }
 }
index 4c46c74a80a4b19c07c4afb36a2c2ee2a5519a9b..88cbc1e68e9c4ee1ab8d6a7bbc6bd468d51c3010 100644 (file)
@@ -57,11 +57,13 @@ public:
 
        /** Construct a DecryptedKDM.
         *  @param cpl CPL that the keys are for.
+        *  @param key Key that was used to encrypt the MXFs.
         *  @param not_valid_before Start time for the KDM.
         *  @param not_valid_after End time for the KDM.
         */
        DecryptedKDM (
                boost::shared_ptr<const CPL> cpl,
+               Key key,
                LocalTime not_valid_before,
                LocalTime not_valid_after,
                std::string annotation_text,
@@ -69,13 +71,6 @@ public:
                std::string issue_date
                );
 
-       /** Add a key to this KDM.
-        *  @param type Key type (MDIK, MDAK etc.)
-        *  @param id Key id.
-        *  @param key the key itself (which has been used to encrypt a MXF).
-        */
-       void add_key (std::string type, std::string id, Key key);
-
        /** Encrypt this KDM's keys and sign the whole KDM.
         *  @param signer Signer.
         *  @param recipient Certificate of the projector/server which should receive this KDM's keys.
index be87c40bc3f8dd6e42688360d9333be6653f4649..fd7c7618b3fa2c65a905ceecf9cf9502820052b9 100644 (file)
@@ -162,7 +162,7 @@ public:
 class NotEncryptedError : public StringError
 {
 public:
-       NotEncryptedError (std::string const & asset_filename);
+       NotEncryptedError (std::string const & what);
        ~NotEncryptedError () throw () {}
 };
        
index 4fbc14952a17d1a893e5adaa9f8ed04605246f46..6985342b8d0bc56b5a66bea367018419bc0ed1eb 100644 (file)
--- a/src/mxf.h
+++ b/src/mxf.h
@@ -49,9 +49,6 @@ public:
        MXF (boost::filesystem::path file);
        ~MXF ();
 
-       /** @return the 4-character key type for this MXF (MDIK, MDAK, etc.) */
-       virtual std::string key_type () const = 0;
-       
        bool equals (
                boost::shared_ptr<const Content> other,
                EqualityOptions opt,
index e3a43e378171f461815d269d7d16947eb60b5f9d..1f863eb1272030cfdfaecf7b9e4df09690742437 100644 (file)
@@ -184,9 +184,3 @@ PictureMXF::frame_buffer_equals (
 
        return true;
 }
-
-string
-PictureMXF::key_type () const
-{
-       return "MDIK";
-}
index 1ce2e7de08836d061a6f1af42bc70824be8f458d..5b76c116c836580d188155fc6de082416cd4ff52 100644 (file)
@@ -102,7 +102,6 @@ protected:
        Fraction _screen_aspect_ratio;
 
 private:
-       std::string key_type () const;
        std::string asdcp_kind () const {
                return "Picture";
        }
index 21116d28bee6d0398a15bb1cdb69365fd047540c..9d98cd7109bd6068f3a778cf044a2490666966f0 100644 (file)
@@ -33,6 +33,9 @@ public:
        ReelMXFAsset (boost::shared_ptr<MXF> mxf, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point);
        ReelMXFAsset (boost::shared_ptr<const cxml::Node>);
 
+       /** @return the 4-character key type for this MXF (MDIK, MDAK, etc.) */
+       virtual std::string key_type () const = 0;
+       
        void write_to_cpl (xmlpp::Node* node, Standard standard) const;
        
        /** @return true if a KeyId is specified for this asset, implying
index c8556b4c35faf3b0e2d2616e5d90b7aa4cdfcccf..4f737a910205d9452cb9323bfb7fb00725f64ade 100644 (file)
@@ -90,3 +90,9 @@ ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
                        );
        }
 }
+
+string
+ReelPictureAsset::key_type () const
+{
+       return "MDIK";
+}
index e635e850eda3568802c4128331a6640883c8190e..7ab92228f369eadd209d9f5be5b62342c697aa24 100644 (file)
@@ -54,6 +54,8 @@ public:
        }
 
 private:
+       std::string key_type () const;
+       
        Fraction _frame_rate;
        Fraction _screen_aspect_ratio;
 };
index ee308fa0f6c669a53784929bda266b2050a531f2..55167d827b3e7c704e6062f882a31883b7699392 100644 (file)
@@ -46,3 +46,9 @@ ReelSoundAsset::cpl_node_name () const
 {
        return "MainSound";
 }
+
+string
+ReelSoundAsset::key_type () const
+{
+       return "MDAK";
+}
index af898b463aecccca8839ac9c02b29836d40f7ea2..0e27f380e299ac4be657bcd9140d026fd66aacd0 100644 (file)
@@ -46,6 +46,7 @@ public:
        }
        
 private:
+       std::string key_type () const;
        std::string cpl_node_name () const;
 };
 
index ff2167d9f54b4d2b3cd50ff9568276de10ac9694..89f1ee60b0218244827557589eb7cfddfffedf66 100644 (file)
@@ -170,9 +170,3 @@ SoundMXF::start_write (boost::filesystem::path file, Standard standard)
        /* XXX: can't we use a shared_ptr here? */
        return shared_ptr<SoundMXFWriter> (new SoundMXFWriter (this, file, standard));
 }
-
-string
-SoundMXF::key_type () const
-{
-       return "MDAK";
-}
index 50d109570e0c02b5f1af4995f89b6d6a61c06d7e..d444ad28653fab8c0dcf08aa9c12bcb01f5aa689 100644 (file)
@@ -64,7 +64,6 @@ public:
        }
 
 private:
-       std::string key_type () const;
        std::string asdcp_kind () const {
                return "Sound";
        }
index e096c5fd9428898ed70b94c57769286b94852761..e5acdbcedc81d50d919ab24984aa61c8b1b81918 100644 (file)
@@ -127,6 +127,7 @@ BOOST_AUTO_TEST_CASE (encryption_test)
 
        dcp::DecryptedKDM kdm (
                cpl,
+               key,
                dcp::LocalTime ("2013-01-01T00:00:00+00:00"),
                dcp::LocalTime ("2017-01-08T00:00:00+00:00"),
                "libdcp",
index 7ba501e60edffd0c042731c161ecd48dc529555d..b059493118e86ed481d8f52c808d9547f08dc4c6 100644 (file)
@@ -67,6 +67,7 @@ BOOST_AUTO_TEST_CASE (round_trip_test)
        /* A KDM using our certificate chain's leaf key pair */
        dcp::DecryptedKDM kdm_A (
                cpl,
+               key,
                dcp::LocalTime ("2013-01-01T00:00:00+00:00"),
                dcp::LocalTime ("2013-01-08T00:00:00+00:00"),
                "libdcp",