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>
Sat, 19 Feb 2022 23:53:59 +0000 (00:53 +0100)
src/lib/config.cc
src/lib/config.h

index 913edcf183f52f11e5a6d7e584f3185f6b5bec63..bc03377b618b10903d293ca0af1b9d423b61c796 100644 (file)
@@ -459,25 +459,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) {
@@ -1504,3 +1486,29 @@ save_all_config_as_zip (boost::filesystem::path zip_file)
        zipper.close ();
 }
 
+
+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 9dc123426cdef50fd27e6493c86c578600796234..686e30da3380d911061310214ce57bba25b869cb 100644 (file)
@@ -1113,6 +1113,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 ();