From 1f284533185a798c0ed36669bd6c9729adf6ec5a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 19 Jan 2021 00:32:53 +0100 Subject: [PATCH] Rename encrypted() to any_encrypted() and add all_encrypted(). --- examples/read_dcp.cc | 4 +++- src/cpl.cc | 19 +++++++++++++++++-- src/cpl.h | 3 ++- src/dcp.cc | 19 +++++++++++++++++-- src/dcp.h | 3 ++- src/reel.cc | 30 +++++++++++++++++++++++++----- src/reel.h | 3 ++- src/verify.cc | 2 +- test/decryption_test.cc | 4 ++-- 9 files changed, 71 insertions(+), 16 deletions(-) diff --git a/examples/read_dcp.cc b/examples/read_dcp.cc index 9c6c307a..4664fea4 100644 --- a/examples/read_dcp.cc +++ b/examples/read_dcp.cc @@ -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"; } diff --git a/src/cpl.cc b/src/cpl.cc index 76f6002b..a976e072 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -584,10 +584,10 @@ CPL::equals (shared_ptr 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. diff --git a/src/cpl.h b/src/cpl.h index d96181e5..5d087c03 100644 --- a/src/cpl.h +++ b/src/cpl.h @@ -93,7 +93,8 @@ public: std::vector> reel_mxfs () const; std::vector> reel_mxfs (); - bool encrypted () const; + bool any_encrypted () const; + bool all_encrypted () const; void write_xml ( boost::filesystem::path file, diff --git a/src/dcp.cc b/src/dcp.cc index ca7313a5..ee1a64ed 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -316,11 +316,12 @@ DCP::add (std::shared_ptr 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. diff --git a/src/dcp.h b/src/dcp.h index 73f154c7..7323de9a 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -106,7 +106,8 @@ public: std::vector> cpls () const; std::vector> assets (bool ignore_unresolved = false) const; - bool encrypted () const; + bool any_encrypted () const; + bool all_encrypted () const; void add (DecryptedKDM const &); diff --git a/src/reel.cc b/src/reel.cc index 89056cff..a05a7b36 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -223,7 +223,7 @@ Reel::equals (std::shared_ptr 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) { diff --git a/src/reel.h b/src/reel.h index 083ecd0e..14d599ea 100644 --- a/src/reel.h +++ b/src/reel.h @@ -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 other, EqualityOptions opt, NoteHandler notes) const; diff --git a/src/verify.cc b/src/verify.cc index 26173a5b..3b0fb7c9 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -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()); diff --git a/test/decryption_test.cc b/test/decryption_test.cc index 6a7dde9d..3c4c0d61 100644 --- a/test/decryption_test.cc +++ b/test/decryption_test.cc @@ -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 ( -- 2.30.2