From 5e10a6f047d12f1e2e3d0e2f8ee30f93897a2227 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 17 Jan 2025 01:31:38 +0100 Subject: Allow KDMRecipient and hence Screen to convert certs to dcp::Certificate lazily. This is pretty slow (as it runs the certificate through OpenSSL) and we don't need to do it for every certificate in a database when we load the database. --- src/lib/kdm_recipient.cc | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/lib/kdm_recipient.cc') diff --git a/src/lib/kdm_recipient.cc b/src/lib/kdm_recipient.cc index c33eb1b9f..7e7e14324 100644 --- a/src/lib/kdm_recipient.cc +++ b/src/lib/kdm_recipient.cc @@ -22,14 +22,17 @@ #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"); @@ -40,8 +43,8 @@ void 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); @@ -50,3 +53,26 @@ KDMRecipient::as_xml (xmlpp::Element* parent) const cxml::add_text_child(parent, "Notes", notes); } + +boost::optional +KDMRecipient::recipient() const +{ + if (_recipient) { + return _recipient; + } + + if (_recipient_string) { + return dcp::Certificate(*_recipient_string); + } + + return {}; +} + + +void +KDMRecipient::set_recipient(optional certificate) +{ + _recipient = certificate; + _recipient_string = {}; +} + -- cgit v1.2.3