File indexing completed on 2024-06-23 05:14:10

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     selftest/compliancecheck.cpp
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2021 g10 Code GmbH
0006     SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #include <config-kleopatra.h>
0012 
0013 #include "compliancecheck.h"
0014 
0015 #include "implementation_p.h"
0016 
0017 #include <Libkleo/Compliance>
0018 #include <Libkleo/Formatting>
0019 #include <Libkleo/GnuPG>
0020 
0021 #include <KLocalizedString>
0022 
0023 using namespace Kleo;
0024 using namespace Kleo::_detail;
0025 
0026 namespace
0027 {
0028 
0029 class DeVsComplianceCheck : public SelfTestImplementation
0030 {
0031 public:
0032     explicit DeVsComplianceCheck()
0033         : SelfTestImplementation(i18nc("@title %1 is a placeholder for the name of a compliance mode. E.g. NATO RESTRICTED compliant or VS-NfD compliant",
0034                                        "%1?",
0035                                        DeVSCompliance::name(true)))
0036     {
0037         runTest();
0038     }
0039 
0040     void runTest()
0041     {
0042         m_skipped = !DeVSCompliance::isActive();
0043         if (m_skipped) {
0044             m_explanation = xi18nc("@info %1 is a placeholder for the name of a compliance mode. E.g. NATO RESTRICTED compliant or VS-NfD compliant",
0045                                    "<para><application>GnuPG</application> is not configured for %1.</para>",
0046                                    DeVSCompliance::name(true));
0047             return;
0048         }
0049 
0050         m_passed = DeVSCompliance::isCompliant();
0051         if (m_passed) {
0052             return;
0053         }
0054 
0055         m_error = DeVSCompliance::name(m_passed);
0056         m_explanation = xi18nc("@info %1 is a placeholder for the name of a compliance mode. E.g. NATO RESTRICTED compliant or VS-NfD compliant",
0057                                "<para>The <application>GnuPG</application> system used by <application>Kleopatra</application> is not %1.</para>",
0058                                DeVSCompliance::name(true));
0059         m_proposedFix = xi18nc("@info %1 is a placeholder for the name of a compliance mode. E.g. NATO RESTRICTED compliant or VS-NfD compliant",
0060                                "<para>Install a version of <application>GnuPG</application> that is %1.</para>",
0061                                DeVSCompliance::name(true));
0062     }
0063 };
0064 
0065 }
0066 
0067 std::shared_ptr<SelfTest> Kleo::makeDeVSComplianceCheckSelfTest()
0068 {
0069     return std::make_shared<DeVsComplianceCheck>();
0070 }