diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-01-17 01:31:38 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-01-22 14:34:25 +0100 |
| commit | 5e10a6f047d12f1e2e3d0e2f8ee30f93897a2227 (patch) | |
| tree | c3daccbbf2291d6330df2c2f6d99bf34fcb2e288 /src/lib/kdm_recipient.cc | |
| parent | c29ba2526337b486d4a3b1a1468513a22293bc87 (diff) | |
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.
Diffstat (limited to 'src/lib/kdm_recipient.cc')
| -rw-r--r-- | src/lib/kdm_recipient.cc | 34 |
1 files changed, 30 insertions, 4 deletions
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<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 = {}; +} + |
