From c5a9590a9a84eb4eee8536dfa1eef59d7126eeac Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 14 Feb 2022 10:36:07 +0100 Subject: [PATCH] Extract check_certificates() method. --- src/lib/config.cc | 46 +++++++++++++++++++++++++++------------------- src/lib/config.h | 2 ++ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/lib/config.cc b/src/lib/config.cc index 371682966..bab15ecb7 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -450,25 +450,7 @@ try } } - optional bad; - - for (auto const& i: _signer_chain->unordered()) { - if (i.has_utf8_strings()) { - bad = BAD_SIGNER_UTF8_STRINGS; - } - if ((i.not_after().year() - i.not_before().year()) > 15) { - bad = BAD_SIGNER_VALIDITY_TOO_LONG; - } - } - - if (!_signer_chain->chain_valid() || !_signer_chain->private_key_valid()) { - bad = BAD_SIGNER_INCONSISTENT; - } - - if (!_decryption_chain->chain_valid() || !_decryption_chain->private_key_valid()) { - bad = BAD_DECRYPTION_INCONSISTENT; - } - + auto bad = check_certificates (); if (bad) { auto const remake = Bad(*bad); if (remake && *remake) { @@ -1470,3 +1452,29 @@ Config::add_custom_language (dcp::LanguageTag tag) } } + +optional +Config::check_certificates () const +{ + optional bad; + + for (auto const& i: _signer_chain->unordered()) { + if (i.has_utf8_strings()) { + bad = BAD_SIGNER_UTF8_STRINGS; + } + if ((i.not_after().year() - i.not_before().year()) > 15) { + bad = BAD_SIGNER_VALIDITY_TOO_LONG; + } + } + + if (!_signer_chain->chain_valid() || !_signer_chain->private_key_valid()) { + bad = BAD_SIGNER_INCONSISTENT; + } + + if (!_decryption_chain->chain_valid() || !_decryption_chain->private_key_valid()) { + bad = BAD_DECRYPTION_INCONSISTENT; + } + + return bad; +} + diff --git a/src/lib/config.h b/src/lib/config.h index be4e6ecf1..e01eab780 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -1084,6 +1084,8 @@ public: void rename_template (std::string old_name, std::string new_name) const; void delete_template (std::string name) const; + boost::optional check_certificates () const; + static Config* instance (); static void drop (); static void restore_defaults (); -- 2.30.2