diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-10-31 00:03:49 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-11-05 00:43:19 +0100 |
| commit | e8ce097ce705446c27b51199a321a9918deaa0db (patch) | |
| tree | 0a52cbc9c52791d453fa4bd478609aedde98c831 /test/encryption_test.cc | |
| parent | ef65a179e8c907029d0d9254863d4884581f3d60 (diff) | |
Allow specification of which parts of the DCP to encrypt (#3099).
Diffstat (limited to 'test/encryption_test.cc')
| -rw-r--r-- | test/encryption_test.cc | 106 |
1 files changed, 105 insertions, 1 deletions
diff --git a/test/encryption_test.cc b/test/encryption_test.cc index 97359cd44..31e31d53c 100644 --- a/test/encryption_test.cc +++ b/test/encryption_test.cc @@ -27,9 +27,16 @@ #include "test.h" #include <dcp/cpl.h> #include <dcp/dcp.h> +#include <dcp/j2k_transcode.h> +#include <dcp/mono_j2k_picture_asset.h> +#include <dcp/reel.h> +#include <dcp/reel_picture_asset.h> +#include <dcp/reel_sound_asset.h> +#include <dcp/reel_text_asset.h> #include <boost/test/unit_test.hpp> +using std::dynamic_pointer_cast; using std::make_shared; @@ -38,7 +45,9 @@ BOOST_AUTO_TEST_CASE (smpte_dcp_with_subtitles_can_be_decrypted) auto content = content_factory("test/data/15s.srt"); auto film = new_test_film("smpte_dcp_with_subtitles_can_be_decrypted", content); film->set_interop (false); - film->set_encrypted (true); + film->set_encrypt_picture(true); + film->set_encrypt_sound(true); + film->set_encrypt_text(true); make_and_verify_dcp ( film, { @@ -67,3 +76,98 @@ BOOST_AUTO_TEST_CASE (smpte_dcp_with_subtitles_can_be_decrypted) BOOST_CHECK (examiner.kdm_valid()); } + +BOOST_AUTO_TEST_CASE(encrypt_only_picture) +{ + auto picture = content_factory("test/data/flat_red.png")[0]; + auto text = content_factory("test/data/15s.srt")[0]; + auto film = new_test_film("encrypt_only_picture", { picture, text }); + film->set_encrypt_picture(true); + film->set_encrypt_sound(false); + film->set_encrypt_text(false); + /* clairmeta says "Encrypted is not coherent for all reels" */ + make_and_verify_dcp( + film, + { + dcp::VerificationNote::Code::MISSING_CPL_METADATA, + dcp::VerificationNote::Code::MISSED_CHECK_OF_ENCRYPTED, + dcp::VerificationNote::Code::PARTIALLY_ENCRYPTED, + dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE, + dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME, + }, true, false); + + dcp::DCP dcp(film->dir(film->dcp_name())); + dcp.read(); + BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U); + auto cpl = dcp.cpls()[0]; + BOOST_REQUIRE(cpl->file()); + + auto dcp_picture = dynamic_pointer_cast<dcp::MonoJ2KPictureAsset>(cpl->reels()[0]->main_picture()->asset()); + auto reader = dcp_picture->start_read(); + auto frame = reader->get_frame(0); + BOOST_CHECK_THROW(dcp::decompress_j2k(frame->data(), frame->size(), 0), dcp::J2KDecompressionError); +} + + +BOOST_AUTO_TEST_CASE(encrypt_only_sound) +{ + auto picture = content_factory("test/data/flat_red.png")[0]; + auto text = content_factory("test/data/15s.srt")[0]; + auto film = new_test_film("encrypt_only_picture", { picture, text }); + film->set_encrypt_picture(false); + film->set_encrypt_sound(true); + film->set_encrypt_text(false); + /* clairmeta says "Encrypted is not coherent for all reels" */ + make_and_verify_dcp( + film, + { + dcp::VerificationNote::Code::MISSING_CPL_METADATA, + dcp::VerificationNote::Code::MISSED_CHECK_OF_ENCRYPTED, + dcp::VerificationNote::Code::PARTIALLY_ENCRYPTED, + dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE, + dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME, + }, true, false); + + dcp::DCP dcp(film->dir(film->dcp_name())); + dcp.read(); + BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U); + auto cpl = dcp.cpls()[0]; + BOOST_REQUIRE(cpl->file()); + + auto dcp_sound = dynamic_pointer_cast<dcp::SoundAsset>(cpl->reels()[0]->main_sound()->asset()); + auto reader = dcp_sound->start_read(); + auto frame = reader->get_frame(0); + int zeros = 0; + for (int i = 0; i < 1024; ++i) { + zeros += frame->data()[i] == 0; + } + BOOST_CHECK(zeros != 1024); +} + + +BOOST_AUTO_TEST_CASE(encrypt_only_text) +{ + auto picture = content_factory("test/data/flat_red.png")[0]; + auto text = content_factory("test/data/15s.srt")[0]; + auto film = new_test_film("encrypt_only_picture", { picture, text }); + film->set_encrypt_picture(false); + film->set_encrypt_sound(false); + film->set_encrypt_text(true); + make_and_verify_dcp( + film, + { + dcp::VerificationNote::Code::MISSING_CPL_METADATA, + dcp::VerificationNote::Code::MISSED_CHECK_OF_ENCRYPTED, + dcp::VerificationNote::Code::PARTIALLY_ENCRYPTED, + }); + + dcp::DCP dcp(film->dir(film->dcp_name())); + dcp.read(); + BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U); + auto cpl = dcp.cpls()[0]; + BOOST_REQUIRE(cpl->file()); + + auto dcp_subtitle = dynamic_pointer_cast<dcp::TextAsset>(cpl->reels()[0]->main_subtitle()->asset()); + BOOST_CHECK_THROW(dcp_subtitle->xml_as_string(), dcp::ProgrammingError); +} + |
