add_screen.bind_int64(1, cinema_id.get());
add_screen.bind_text(2, screen.name);
add_screen.bind_text(3, screen.notes);
- add_screen.bind_text(4, screen.recipient->certificate(true));
+ add_screen.bind_text(4, screen.recipient()->certificate(true));
add_screen.bind_text(5, screen.recipient_file.get_value_or(""));
add_screen.execute();
CinemaList::screen_from_result(SQLiteStatement& statement, ScreenID screen_id) const
{
auto certificate_string = statement.column_text(4);
- optional<dcp::Certificate> certificate = certificate_string.empty() ? optional<dcp::Certificate>() : dcp::Certificate(certificate_string);
+ optional<string> certificate = certificate_string.empty() ? optional<string>() : certificate_string;
auto recipient_file_string = statement.column_text(5);
optional<string> recipient_file = recipient_file_string.empty() ? optional<string>() : recipient_file_string;
statement.bind_int64(1, cinema_id.get());
statement.bind_text(2, screen.name);
statement.bind_text(3, screen.notes);
- statement.bind_text(4, screen.recipient->certificate(true));
+ statement.bind_text(4, screen.recipient()->certificate(true));
statement.bind_text(5, screen.recipient_file.get_value_or(""));
statement.bind_int64(6, screen_id.get());
dcp::LocalTime valid_to
)
{
- if (!recipient.recipient) {
+ if (!recipient.recipient()) {
return {};
}
}
auto const decrypted_kdm = film->make_kdm(cpl, valid_from, valid_to);
- auto const kdm = decrypted_kdm.encrypt(signer, recipient.recipient.get(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, true, 0);
+ auto const kdm = decrypted_kdm.encrypt(signer, recipient.recipient().get(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, true, 0);
dcp::NameFormat::Map name_values;
name_values['f'] = kdm.content_title_text();
add_dkdm_recipient.bind_text(1, dkdm_recipient.name);
add_dkdm_recipient.bind_text(2, dkdm_recipient.notes);
- add_dkdm_recipient.bind_text(3, dkdm_recipient.recipient ? dkdm_recipient.recipient->certificate(true) : "");
+ add_dkdm_recipient.bind_text(3, dkdm_recipient.recipient() ? dkdm_recipient.recipient()->certificate(true) : "");
add_dkdm_recipient.bind_text(4, join_strings(dkdm_recipient.emails));
add_dkdm_recipient.execute();
add_dkdm_recipient.bind_text(1, dkdm_recipient.name);
add_dkdm_recipient.bind_text(2, dkdm_recipient.notes);
- add_dkdm_recipient.bind_text(3, dkdm_recipient.recipient ? dkdm_recipient.recipient->certificate(true) : "");
+ add_dkdm_recipient.bind_text(3, dkdm_recipient.recipient() ? dkdm_recipient.recipient()->certificate(true) : "");
add_dkdm_recipient.bind_text(4, join_strings(dkdm_recipient.emails));
add_dkdm_recipient.bind_int64(5, id.get());
try {
list<KDMWithMetadataPtr> kdms;
for (auto const& screen_details: screens) {
- if (!screen_details.screen.recipient) {
+ if (!screen_details.screen.recipient()) {
continue;
}
auto const kdm = kdm_from_dkdm(
dkdm,
- screen_details.screen.recipient.get(),
+ screen_details.screen.recipient().get(),
screen_details.screen.trusted_device_thumbprints(),
valid_from,
valid_to,
#include "kdm_recipient.h"
+using boost::optional;
+
+
KDMRecipient::KDMRecipient (cxml::ConstNodePtr node)
: name (node->string_child("Name"))
, notes (node->optional_string_child("Notes").get_value_or(""))
{
if (node->optional_string_child("Certificate")) {
- recipient = dcp::Certificate (node->string_child("Certificate"));
+ _recipient = dcp::Certificate(node->string_child("Certificate"));
} else if (node->optional_string_child("Recipient")) {
- recipient = dcp::Certificate (node->string_child("Recipient"));
+ _recipient = dcp::Certificate(node->string_child("Recipient"));
}
recipient_file = node->optional_string_child("RecipientFile");
KDMRecipient::as_xml (xmlpp::Element* parent) const
{
cxml::add_text_child(parent, "Name", name);
- if (recipient) {
- cxml::add_text_child(parent, "Recipient", recipient->certificate(true));
+ if (auto const r = recipient()) {
+ cxml::add_text_child(parent, "Recipient", r->certificate(true));
}
if (recipient_file) {
cxml::add_text_child(parent, "RecipientFile", *recipient_file);
cxml::add_text_child(parent, "Notes", notes);
}
+
+boost::optional<dcp::Certificate>
+KDMRecipient::recipient() const
+{
+ if (_recipient) {
+ return _recipient;
+ }
+
+ if (_recipient_string) {
+ return dcp::Certificate(*_recipient_string);
+ }
+
+ return {};
+}
+
+
+void
+KDMRecipient::set_recipient(optional<dcp::Certificate> certificate)
+{
+ _recipient = certificate;
+ _recipient_string = {};
+}
+
class KDMRecipient
{
public:
- KDMRecipient (std::string const& name_, std::string const& notes_, boost::optional<dcp::Certificate> recipient_, boost::optional<std::string> recipient_file_)
+ KDMRecipient (std::string const& name_, std::string const& notes_, boost::optional<dcp::Certificate> recipient, boost::optional<std::string> recipient_file_)
: name (name_)
, notes (notes_)
- , recipient (recipient_)
, recipient_file (recipient_file_)
+ , _recipient(recipient)
+ {}
+
+ KDMRecipient(std::string const& name_, std::string const& notes_, boost::optional<std::string> recipient, boost::optional<std::string> recipient_file_)
+ : name(name_)
+ , notes(notes_)
+ , recipient_file(recipient_file_)
+ , _recipient_string(recipient)
{}
explicit KDMRecipient (cxml::ConstNodePtr);
virtual void as_xml (xmlpp::Element *) const;
+ boost::optional<dcp::Certificate> recipient() const;
+ void set_recipient(boost::optional<dcp::Certificate> certificate);
+
std::string name;
std::string notes;
- boost::optional<dcp::Certificate> recipient;
/** The pathname or URL that the recipient certificate was obtained from; purely
* to inform the user.
*/
boost::optional<std::string> recipient_file;
+
+private:
+ /* The recipient certificate may be stored as either a string or a dcp::Certificate;
+ * the string is useful if we want to be lazy about constructing the dcp::Certificate.
+ */
+ boost::optional<dcp::Certificate> _recipient;
+ boost::optional<std::string> _recipient_string;
};
vector<KDMCertificatePeriod>& period_checks
)
{
- if (!screen.recipient) {
+ if (!screen.recipient()) {
return {};
}
- period_checks.push_back(check_kdm_and_certificate_validity_periods(cinema.name, screen.name, screen.recipient.get(), valid_from, valid_to));
+ period_checks.push_back(check_kdm_and_certificate_validity_periods(cinema.name, screen.name, screen.recipient().get(), valid_from, valid_to));
auto signer = Config::instance()->signer_chain();
if (!signer->valid()) {
}
auto kdm = make_kdm(valid_from, valid_to).encrypt(
- signer, screen.recipient.get(), screen.trusted_device_thumbprints(), formulation, disable_forensic_marking_picture, disable_forensic_marking_audio
+ signer, screen.recipient().get(), screen.trusted_device_thumbprints(), formulation, disable_forensic_marking_picture, disable_forensic_marking_audio
);
dcp::NameFormat::Map name_values;
, trusted_devices (trusted_devices_)
{}
+ Screen(
+ std::string const & name_,
+ std::string const & notes_,
+ boost::optional<std::string> recipient_,
+ boost::optional<std::string> recipient_file_,
+ std::vector<TrustedDevice> trusted_devices_
+ )
+ : KDMRecipient(name_, notes_, recipient_, recipient_file_)
+ , trusted_devices(trusted_devices_)
+ {}
+
std::vector<std::string> trusted_device_thumbprints () const;
std::vector<TrustedDevice> trusted_devices;
};
recipient->name,
recipient->notes,
recipient->emails,
- recipient->recipient
+ recipient->recipient()
);
if (dialog.ShowModal() == wxID_OK) {
recipient->name = dialog.name();
recipient->emails = dialog.emails();
recipient->notes = dialog.notes();
- recipient->recipient = dialog.recipient();
+ recipient->set_recipient(dialog.recipient());
recipients.update_dkdm_recipient(recipient_id, *recipient);
_targets->SetItemText(selection.first, std_to_wx(dialog.name()));
}
GetParent(), _("Edit screen"),
screen->name,
screen->notes,
- screen->recipient,
+ screen->recipient(),
screen->recipient_file,
screen->trusted_devices
);
screen->name = dialog.name();
screen->notes = dialog.notes();
- screen->recipient = dialog.recipient();
+ screen->set_recipient(dialog.recipient());
screen->recipient_file = dialog.recipient_file();
screen->trusted_devices = dialog.trusted_devices();
_cinema_list.update_screen(cinema_id, screen_id, *screen);
BOOST_CHECK(check[0].first == screen_id);
BOOST_CHECK_EQUAL(check[0].second.name, "Screen 1");
BOOST_CHECK_EQUAL(check[0].second.notes, "Smells of popcorn");
- BOOST_CHECK(check[0].second.recipient == dcp::Certificate(dcp::file_to_string("test/data/cert.pem")));
+ BOOST_CHECK(check[0].second.recipient() == dcp::Certificate(dcp::file_to_string("test/data/cert.pem")));
BOOST_CHECK(check[0].second.recipient_file == string("test/data/cert.pem"));
}
BOOST_CHECK(check[0].first == screen_id);
BOOST_CHECK_EQUAL(check[0].second.name, "Screen 1 updated");
BOOST_CHECK_EQUAL(check[0].second.notes, "Smells of popcorn and hope");
- BOOST_CHECK(check[0].second.recipient == dcp::Certificate(dcp::file_to_string("test/data/cert.pem")));
+ BOOST_CHECK(check[0].second.recipient() == dcp::Certificate(dcp::file_to_string("test/data/cert.pem")));
BOOST_CHECK(check[0].second.recipient_file == string("test/data/cert.pem"));
}
BOOST_CHECK_EQUAL(screens.size(), 2U);
auto screen_iter = screens.begin();
BOOST_CHECK_EQUAL(screen_iter->second.name, "1");
- BOOST_CHECK(screen_iter->second.recipient);
- BOOST_CHECK_EQUAL(screen_iter->second.recipient->subject_dn_qualifier(), "CVsuuv9eYsQZSl8U4fDpvOmzZhI=");
+ BOOST_CHECK(screen_iter->second.recipient());
+ BOOST_CHECK_EQUAL(screen_iter->second.recipient()->subject_dn_qualifier(), "CVsuuv9eYsQZSl8U4fDpvOmzZhI=");
++screen_iter;
BOOST_CHECK_EQUAL(screen_iter->second.name, "2");
- BOOST_CHECK(screen_iter->second.recipient);
- BOOST_CHECK_EQUAL(screen_iter->second.recipient->subject_dn_qualifier(), "CVsuuv9eYsQZSl8U4fDpvOmzZhI=");
+ BOOST_CHECK(screen_iter->second.recipient());
+ BOOST_CHECK_EQUAL(screen_iter->second.recipient()->subject_dn_qualifier(), "CVsuuv9eYsQZSl8U4fDpvOmzZhI=");
}
BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.emails.size(), 2U);
BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.emails[0], "epicbob@gmail.com");
BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.emails[1], "boblikesemlong@cinema-bob.com");
- BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.recipient->subject_dn_qualifier(), "r5/Q5f3UTm7qzoF5QzNZP6aEuvI=");
+ BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.recipient()->subject_dn_qualifier(), "r5/Q5f3UTm7qzoF5QzNZP6aEuvI=");
++dkdm_recipient_iter;
BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.name, "Sharon's Shorts");
BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.notes, "Even if it sucks, at least it's over quickly");
- BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.recipient->subject_dn_qualifier(), "FHerM3Us/DWuqD1MnztStSlFJO0=");
+ BOOST_CHECK_EQUAL(dkdm_recipient_iter->second.recipient()->subject_dn_qualifier(), "FHerM3Us/DWuqD1MnztStSlFJO0=");
++dkdm_recipient_iter;
}