Rename encrypted() to any_encrypted() and add all_encrypted().
authorCarl Hetherington <cth@carlh.net>
Mon, 18 Jan 2021 23:32:53 +0000 (00:32 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 18 Jan 2021 23:32:53 +0000 (00:32 +0100)
examples/read_dcp.cc
src/cpl.cc
src/cpl.h
src/dcp.cc
src/dcp.h
src/reel.cc
src/reel.h
src/verify.cc
test/decryption_test.cc

index 9c6c307af19570dc1aa74134bf1f6d0cfb6f8be7..4664fea4f1c5db5ce94c8efaf4f7861a8036b34b 100644 (file)
@@ -51,8 +51,10 @@ main ()
        /* Read the DCP to find out about it */
        dcp.read ();
 
-       if (dcp.encrypted ()) {
+       if (dcp.all_encrypted()) {
                std::cout << "DCP is encrypted.\n";
+       } else if (dcp.any_encrypted()) {
+               std::cout << "DCP is partially encrypted.\n";
        } else {
                std::cout << "DCP is not encrypted.\n";
        }
index 76f6002bb12661455c5e732c8709fd0822123b89..a976e0723709d7d3a867502fc0a9a6637bea20a8 100644 (file)
@@ -584,10 +584,10 @@ CPL::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler not
 
 /** @return true if we have any encrypted content */
 bool
-CPL::encrypted () const
+CPL::any_encrypted () const
 {
        for (auto i: _reels) {
-               if (i->encrypted ()) {
+               if (i->any_encrypted()) {
                        return true;
                }
        }
@@ -595,6 +595,21 @@ CPL::encrypted () const
        return false;
 }
 
+
+/** @return true if we have all our encryptable content is encrypted */
+bool
+CPL::all_encrypted () const
+{
+       for (auto i: _reels) {
+               if (!i->all_encrypted()) {
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+
 /** Add a KDM to this CPL.  If the KDM is for any of this CPLs assets it will be used
  *  to decrypt those assets.
  *  @param kdm KDM.
index d96181e5b07bc9817ad373584ae37a24c13db23e..5d087c039da724e76d3bc9a6d606487b276f06fb 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -93,7 +93,8 @@ public:
        std::vector<std::shared_ptr<const ReelMXF>> reel_mxfs () const;
        std::vector<std::shared_ptr<ReelMXF>> reel_mxfs ();
 
-       bool encrypted () const;
+       bool any_encrypted () const;
+       bool all_encrypted () const;
 
        void write_xml (
                boost::filesystem::path file,
index ca7313a535cee7784d923a39b5d4099010de9daf..ee1a64ed6211907d34799eb1d08730863910a08e 100644 (file)
@@ -316,11 +316,12 @@ DCP::add (std::shared_ptr<CPL> cpl)
        _cpls.push_back (cpl);
 }
 
+
 bool
-DCP::encrypted () const
+DCP::any_encrypted () const
 {
        for (auto i: cpls()) {
-               if (i->encrypted()) {
+               if (i->any_encrypted()) {
                        return true;
                }
        }
@@ -328,6 +329,20 @@ DCP::encrypted () const
        return false;
 }
 
+
+bool
+DCP::all_encrypted () const
+{
+       for (auto i: cpls()) {
+               if (!i->all_encrypted()) {
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+
 /** Add a KDM to decrypt this DCP.  This method must be called after DCP::read()
  *  or the KDM you specify will be ignored.
  *  @param kdm KDM to use.
index 73f154c707a78c1f60da06a7255c9d0b7dffa926..7323de9a33f114b6a5219fa111ec71f399dedb39 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -106,7 +106,8 @@ public:
        std::vector<std::shared_ptr<CPL>> cpls () const;
        std::vector<std::shared_ptr<Asset>> assets (bool ignore_unresolved = false) const;
 
-       bool encrypted () const;
+       bool any_encrypted () const;
+       bool all_encrypted () const;
 
        void add (DecryptedKDM const &);
 
index 89056cffef26f68db9b81a4bde791597ba999112..a05a7b36d0c32c6017673e2c6d5b2a265883aa99 100644 (file)
@@ -223,7 +223,7 @@ Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandle
 }
 
 bool
-Reel::encrypted () const
+Reel::any_encrypted () const
 {
        auto ecc = false;
        for (auto i: _closed_captions) {
@@ -233,14 +233,34 @@ Reel::encrypted () const
        }
 
        return (
-               (_main_picture && _main_picture->encrypted ()) ||
-               (_main_sound && _main_sound->encrypted ()) ||
-               (_main_subtitle && _main_subtitle->encrypted ()) ||
+               (_main_picture && _main_picture->encrypted()) ||
+               (_main_sound && _main_sound->encrypted()) ||
+               (_main_subtitle && _main_subtitle->encrypted()) ||
                ecc ||
-               (_atmos && _atmos->encrypted ())
+               (_atmos && _atmos->encrypted())
                );
 }
 
+
+bool
+Reel::all_encrypted () const
+{
+       auto ecc = true;
+       for (auto i: _closed_captions) {
+               if (!i->encrypted()) {
+                       ecc = false;
+               }
+       }
+
+       return (
+               (!_main_picture || _main_picture->encrypted()) &&
+               (!_main_sound || _main_sound->encrypted()) &&
+               (!_main_subtitle || _main_subtitle->encrypted()) &&
+               ecc &&
+               (!_atmos || _atmos->encrypted())
+              );
+}
+
 void
 Reel::add (DecryptedKDM const & kdm)
 {
index 083ecd0e8f5a7c814e154d8f6bdaf3709abb0611..14d599ea5677dbfb670635faa8241930ed5150c5 100644 (file)
@@ -114,7 +114,8 @@ public:
 
        xmlpp::Element* write_to_cpl (xmlpp::Element* node, Standard standard) const;
 
-       bool encrypted () const;
+       bool any_encrypted () const;
+       bool all_encrypted () const;
 
        bool equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandler notes) const;
 
index 26173a5b46b547574396a7c2f830e439bb6b4bad..3b0fb7c9c34d7cd864cdc30b0edbbf58473b7d28 100644 (file)
@@ -1352,7 +1352,7 @@ dcp::verify (
 
                                check_extension_metadata (cpl, notes);
 
-                               if (cpl->encrypted()) {
+                               if (cpl->any_encrypted()) {
                                        cxml::Document doc ("CompositionPlaylist");
                                        DCP_ASSERT (cpl->file());
                                        doc.read_file (cpl->file().get());
index 6a7dde9da9e170e6eb1c2051d0eca53cbcad1909..3c4c0d6120dfc7f00ea48e63784e7a7afe106481 100644 (file)
@@ -77,13 +77,13 @@ BOOST_AUTO_TEST_CASE (decryption_test)
        plaintext_path /= "TONEPLATES-SMPTE-PLAINTEXT_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV";
        dcp::DCP plaintext (plaintext_path.string ());
        plaintext.read ();
-       BOOST_CHECK_EQUAL (plaintext.encrypted (), false);
+       BOOST_CHECK_EQUAL (plaintext.any_encrypted(), false);
 
        boost::filesystem::path encrypted_path = private_test;
        encrypted_path /= "TONEPLATES-SMPTE-ENCRYPTED_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV";
        dcp::DCP encrypted (encrypted_path.string ());
        encrypted.read ();
-       BOOST_CHECK_EQUAL (encrypted.encrypted (), true);
+       BOOST_CHECK_EQUAL (encrypted.any_encrypted(), true);
 
        dcp::DecryptedKDM kdm (
                dcp::EncryptedKDM (