summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-02-14 22:13:31 +0000
committerCarl Hetherington <cth@carlh.net>2018-02-14 22:16:07 +0000
commite2a4e0f08c9e8cc82fb20f1cd358897fae46c9ee (patch)
treee936e7abbaeb3a07806499f194861525752ab25f
parent4a5ef0b4dc6310c5eb7a35fb1c79541bf856b9a8 (diff)
Use a bool instead of an int for disable-forensic-picture and
a optional<int> instead of an int with a magic -1 for disable-forensic-audio.
-rw-r--r--src/decrypted_kdm.cc7
-rw-r--r--src/decrypted_kdm.h7
-rw-r--r--src/encrypted_kdm.cc23
-rw-r--r--src/encrypted_kdm.h4
-rw-r--r--test/encryption_test.cc2
-rw-r--r--test/kdm_test.cc15
-rw-r--r--test/round_trip_test.cc2
7 files changed, 35 insertions, 25 deletions
diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc
index 53e958c1..0fa95f9a 100644
--- a/src/decrypted_kdm.cc
+++ b/src/decrypted_kdm.cc
@@ -303,7 +303,12 @@ DecryptedKDM::add_key (DecryptedKDMKey key)
EncryptedKDM
DecryptedKDM::encrypt (
- shared_ptr<const CertificateChain> signer, Certificate recipient, vector<Certificate> trusted_devices, Formulation formulation, int disable_forensic_marking_picture, int disable_forensic_marking_audio
+ shared_ptr<const CertificateChain> signer,
+ Certificate recipient,
+ vector<Certificate> trusted_devices,
+ Formulation formulation,
+ bool disable_forensic_marking_picture,
+ optional<int> disable_forensic_marking_audio
) const
{
DCP_ASSERT (!_keys.empty ());
diff --git a/src/decrypted_kdm.h b/src/decrypted_kdm.h
index c264bfbc..7ae1d161 100644
--- a/src/decrypted_kdm.h
+++ b/src/decrypted_kdm.h
@@ -124,6 +124,9 @@ public:
* @param trusted_devices Extra trusted devices which should be written to the KDM (recipient will be written
* as a trusted device automatically and does not need to be included in this list).
* @param formulation Formulation to use for the encrypted KDM.
+ * @param disable_forensic_marking_picture true to disable forensic marking of picture.
+ * @param disable_forensic_marking_audio if not set, don't disable forensic marking of audio. If set to 0,
+ * disable all forensic marking; if set above 0, disable forensic marking above that channel.
* @return Encrypted KDM.
*/
EncryptedKDM encrypt (
@@ -131,8 +134,8 @@ public:
Certificate recipient,
std::vector<Certificate> trusted_devices,
Formulation formulation,
- int disable_forensic_marking_picture,
- int disable_forensic_marking_audio
+ bool disable_forensic_marking_picture,
+ boost::optional<int> disable_forensic_marking_audio
) const;
void add_key (boost::optional<std::string> type, std::string key_id, Key key, std::string cpl_id, Standard standard);
diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc
index d7a2bcc6..7a7d98c1 100644
--- a/src/encrypted_kdm.cc
+++ b/src/encrypted_kdm.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -35,6 +35,7 @@
#include "util.h"
#include "certificate_chain.h"
#include "exceptions.h"
+#include "compose.hpp"
#include <libcxml/cxml.h>
#include <libxml++/document.h>
#include <libxml++/nodes/element.h>
@@ -384,14 +385,14 @@ public:
, authorized_device_info (node->node_child ("AuthorizedDeviceInfo"))
, key_id_list (node->node_child ("KeyIdList"))
{
- disable_forensic_marking_picture = 0;
- disable_forensic_marking_audio = 0;
+ disable_forensic_marking_picture = false;
+ disable_forensic_marking_audio = optional<int>();
if (node->optional_node_child("ForensicMarkFlagList")) {
BOOST_FOREACH (cxml::ConstNodePtr i, node->node_child("ForensicMarkFlagList")->node_children("ForensicMarkFlag")) {
if (i->content() == picture_disable) {
- disable_forensic_marking_picture = -1;
+ disable_forensic_marking_picture = true;
} else if (starts_with(i->content(), audio_disable)) {
- disable_forensic_marking_audio = -1;
+ disable_forensic_marking_audio = 0;
string const above = audio_disable + "-above-channel-";
if (starts_with(i->content(), above)) {
string above_number = i->content().substr(above.length());
@@ -429,8 +430,8 @@ public:
}
if (disable_forensic_marking_audio) {
string mrkflg = audio_disable;
- if (disable_forensic_marking_audio != -1) {
- mrkflg = str (boost::format (mrkflg + "-above-channel-%u") % disable_forensic_marking_audio);
+ if (*disable_forensic_marking_audio > 0) {
+ mrkflg += String::compose ("-above-channel-%1", *disable_forensic_marking_audio);
}
forensic_mark_flag_list->add_child("ForensicMarkFlag")->add_child_text (mrkflg);
}
@@ -443,8 +444,8 @@ public:
string content_title_text;
LocalTime not_valid_before;
LocalTime not_valid_after;
- int disable_forensic_marking_picture;
- int disable_forensic_marking_audio;
+ bool disable_forensic_marking_picture;
+ optional<int> disable_forensic_marking_audio;
boost::optional<AuthorizedDeviceInfo> authorized_device_info;
KeyIdList key_id_list;
@@ -585,8 +586,8 @@ EncryptedKDM::EncryptedKDM (
LocalTime not_valid_before,
LocalTime not_valid_after,
Formulation formulation,
- int disable_forensic_marking_picture,
- int disable_forensic_marking_audio,
+ bool disable_forensic_marking_picture,
+ optional<int> disable_forensic_marking_audio,
list<pair<string, string> > key_ids,
list<string> keys
)
diff --git a/src/encrypted_kdm.h b/src/encrypted_kdm.h
index 24e8f060..3ac15864 100644
--- a/src/encrypted_kdm.h
+++ b/src/encrypted_kdm.h
@@ -110,8 +110,8 @@ private:
LocalTime not_valid_before,
LocalTime not_valid_after,
Formulation formulation,
- int disable_forensic_marking_picture,
- int disable_forensic_marking_audio,
+ bool disable_forensic_marking_picture,
+ boost::optional<int> disable_forensic_marking_audio,
std::list<std::pair<std::string, std::string> > key_ids,
std::list<std::string> keys
);
diff --git a/test/encryption_test.cc b/test/encryption_test.cc
index 7b41e096..64b4ecd9 100644
--- a/test/encryption_test.cc
+++ b/test/encryption_test.cc
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE (encryption_test)
"2012-07-17T04:45:18+00:00"
);
- kdm.encrypt (signer, signer->leaf(), vector<dcp::Certificate>(), dcp::MODIFIED_TRANSITIONAL_1, -1, -1).as_xml ("build/test/encryption_test.kdm.xml");
+ kdm.encrypt (signer, signer->leaf(), vector<dcp::Certificate>(), dcp::MODIFIED_TRANSITIONAL_1, true, 0).as_xml ("build/test/encryption_test.kdm.xml");
int r = system (
"xmllint --path schema --nonet --noout --schema schema/SMPTE-430-1-2006-Amd-1-2009-KDM.xsd build/test/encryption_test.kdm.xml "
diff --git a/test/kdm_test.cc b/test/kdm_test.cc
index 76a7457c..53aabd87 100644
--- a/test/kdm_test.cc
+++ b/test/kdm_test.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -31,6 +31,7 @@ using std::list;
using std::string;
using std::vector;
using boost::shared_ptr;
+using boost::optional;
/** Check reading and decryption of a KDM */
BOOST_AUTO_TEST_CASE (kdm_test)
@@ -132,7 +133,7 @@ BOOST_AUTO_TEST_CASE (kdm_key_type_scope)
}
static cxml::ConstNodePtr
-kdm_forensic_test (cxml::Document& doc, int picture, int audio)
+kdm_forensic_test (cxml::Document& doc, bool picture, optional<int> audio)
{
dcp::DecryptedKDM decrypted (
dcp::EncryptedKDM (
@@ -163,7 +164,7 @@ kdm_forensic_test (cxml::Document& doc, int picture, int audio)
BOOST_AUTO_TEST_CASE (kdm_forensic_test1)
{
cxml::Document doc;
- cxml::ConstNodePtr forensic = kdm_forensic_test(doc, -1, -1);
+ cxml::ConstNodePtr forensic = kdm_forensic_test(doc, true, 0);
BOOST_REQUIRE (forensic);
list<cxml::NodePtr> flags = forensic->node_children("ForensicMarkFlag");
BOOST_REQUIRE_EQUAL (flags.size(), 2);
@@ -175,7 +176,7 @@ BOOST_AUTO_TEST_CASE (kdm_forensic_test1)
BOOST_AUTO_TEST_CASE (kdm_forensic_test2)
{
cxml::Document doc;
- cxml::ConstNodePtr forensic = kdm_forensic_test(doc, -1, 0);
+ cxml::ConstNodePtr forensic = kdm_forensic_test(doc, true, optional<int>());
BOOST_REQUIRE (forensic);
list<cxml::NodePtr> flags = forensic->node_children("ForensicMarkFlag");
BOOST_REQUIRE_EQUAL (flags.size(), 1);
@@ -186,7 +187,7 @@ BOOST_AUTO_TEST_CASE (kdm_forensic_test2)
BOOST_AUTO_TEST_CASE (kdm_forensic_test3)
{
cxml::Document doc;
- cxml::ConstNodePtr forensic = kdm_forensic_test(doc, 0, -1);
+ cxml::ConstNodePtr forensic = kdm_forensic_test(doc, false, 0);
BOOST_REQUIRE (forensic);
list<cxml::NodePtr> flags = forensic->node_children("ForensicMarkFlag");
BOOST_REQUIRE_EQUAL (flags.size(), 1);
@@ -197,7 +198,7 @@ BOOST_AUTO_TEST_CASE (kdm_forensic_test3)
BOOST_AUTO_TEST_CASE (kdm_forensic_test4)
{
cxml::Document doc;
- cxml::ConstNodePtr forensic = kdm_forensic_test(doc, -1, 3);
+ cxml::ConstNodePtr forensic = kdm_forensic_test(doc, true, 3);
BOOST_REQUIRE (forensic);
list<cxml::NodePtr> flags = forensic->node_children("ForensicMarkFlag");
BOOST_REQUIRE_EQUAL (flags.size(), 2);
@@ -209,6 +210,6 @@ BOOST_AUTO_TEST_CASE (kdm_forensic_test4)
BOOST_AUTO_TEST_CASE (kdm_forensic_test5)
{
cxml::Document doc;
- cxml::ConstNodePtr forensic = kdm_forensic_test(doc, 0, 0);
+ cxml::ConstNodePtr forensic = kdm_forensic_test(doc, false, optional<int>());
BOOST_CHECK (!forensic);
}
diff --git a/test/round_trip_test.cc b/test/round_trip_test.cc
index 1fd89dbb..505477a3 100644
--- a/test/round_trip_test.cc
+++ b/test/round_trip_test.cc
@@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE (round_trip_test)
boost::filesystem::path const kdm_file = work_dir / "kdm.xml";
- kdm_A.encrypt(signer, signer->leaf(), vector<dcp::Certificate>(), dcp::MODIFIED_TRANSITIONAL_1, -1, -1).as_xml (kdm_file);
+ kdm_A.encrypt(signer, signer->leaf(), vector<dcp::Certificate>(), dcp::MODIFIED_TRANSITIONAL_1, true, 0).as_xml (kdm_file);
/* Reload the KDM, using our private key to decrypt it */
dcp::DecryptedKDM kdm_B (dcp::EncryptedKDM (dcp::file_to_string (kdm_file)), signer->key().get ());