2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/config.h"
23 #include "lib/content_factory.h"
24 #include "lib/dcp_content.h"
25 #include "lib/dcp_digest_file.h"
30 #include <boost/algorithm/string.hpp>
31 #include <boost/test/unit_test.hpp>
35 using std::make_shared;
37 using boost::optional;
40 BOOST_AUTO_TEST_CASE (dcp_digest_file_test)
42 dcp::DCP dcp("test/data/dcp_digest_test_dcp");
44 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
46 write_dcp_digest_file ("build/test/digest.xml", dcp.cpls()[0], "e684e49e89182e907dabe5d9b3bd81ba");
48 check_xml ("test/data/digest.xml", "build/test/digest.xml", {});
52 BOOST_AUTO_TEST_CASE (dcp_digest_file_test2)
54 auto get_key_from_digest = [](boost::filesystem::path filename) -> optional<string> {
55 ifstream digest(filename.string().c_str());
56 while (digest.good()) {
58 getline (digest, line);
59 boost::algorithm::trim (line);
60 if (boost::starts_with(line, "<Key>") && line.length() > 37) {
61 return line.substr(5, 32);
68 auto red = content_factory("test/data/flat_red.png");
69 auto ov = new_test_film2 ("dcp_digest_file_test2_ov", red);
70 ov->set_encrypted (true);
71 make_and_verify_dcp (ov);
73 auto ov_key_check = get_key_from_digest ("build/test/dcp_digest_file_test2_ov/" + ov->dcp_name() + ".dcpdig");
74 BOOST_REQUIRE (static_cast<bool>(ov_key_check));
75 BOOST_CHECK_EQUAL (*ov_key_check, ov->key().hex());
77 dcp::DCP find_cpl (ov->dir(ov->dcp_name()));
79 BOOST_REQUIRE (!find_cpl.cpls().empty());
80 auto ov_cpl = find_cpl.cpls()[0]->file();
81 BOOST_REQUIRE (static_cast<bool>(ov_cpl));
83 auto kdm = ov->make_kdm (
84 Config::instance()->decryption_chain()->leaf(),
87 dcp::LocalTime(), dcp::LocalTime(),
88 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
93 auto ov_dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
94 ov_dcp->add_kdm (kdm);
95 ov_dcp->set_reference_video (true);
96 ov_dcp->set_reference_audio (true);
97 auto vf = new_test_film2 ("dcp_digest_file_test2_vf", { ov_dcp });
98 vf->set_encrypted (true);
99 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
101 auto vf_key_check = get_key_from_digest ("build/test/dcp_digest_file_test2_vf/" + vf->dcp_name() + ".dcpdig");
102 BOOST_REQUIRE (static_cast<bool>(vf_key_check));
103 BOOST_CHECK_EQUAL (*vf_key_check, ov->key().hex());