Extract check_certificates() method.
authorCarl Hetherington <cth@carlh.net>
Mon, 14 Feb 2022 09:36:07 +0000 (10:36 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 14 Feb 2022 09:36:07 +0000 (10:36 +0100)
src/lib/config.cc
src/lib/config.h

index 37168296611746e713d1d6bb99b8089c127d5109..bab15ecb705768025d00e58c3e2bf7ebd4982761 100644 (file)
@@ -450,25 +450,7 @@ try
                }
        }
 
-       optional<BadReason> 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::BadReason>
+Config::check_certificates () const
+{
+       optional<BadReason> 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;
+}
+
index be4e6ecf13814ac01adb54916efe3b9c4d976d1f..e01eab780e8c9ce4dfabd2aee89caa7675d1845e 100644 (file)
@@ -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<BadReason> check_certificates () const;
+
        static Config* instance ();
        static void drop ();
        static void restore_defaults ();