Update git submodules
[LibreOffice.git] / xmlsecurity / inc / certificatechooser.hxx
blob12303fbf1cd54ce3eb15373ee75bb5ef15744f92
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <vcl/weld.hxx>
24 #include <unotools/resmgr.hxx>
25 #include <unotools/useroptions.hxx>
26 #include <unordered_map>
28 namespace com::sun::star {
29 namespace security { class XCertificate; }
30 namespace xml::crypto {
31 class XSecurityEnvironment;
35 namespace com::sun::star::xml::crypto { class XXMLSecurityContext; }
37 struct UserData
39 css::uno::Reference<css::security::XCertificate> xCertificate;
40 css::uno::Reference<css::xml::crypto::XXMLSecurityContext> xSecurityContext;
41 css::uno::Reference<css::xml::crypto::XSecurityEnvironment> xSecurityEnvironment;
44 enum class UserAction
46 Sign,
47 SelectSign, // Select signing certificate
48 Encrypt
51 class CertificateChooser final : public weld::GenericDialogController
53 private:
54 static inline CertificateChooser* mxInstance = nullptr;
56 std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > mxSecurityContexts;
57 std::vector<std::shared_ptr<UserData>> mvUserData;
59 bool mbInitialized;
60 UserAction const meAction;
61 OUString msPreferredKey;
62 css::uno::Reference<css::security::XCertificate> mxEncryptToSelf;
64 std::unique_ptr<weld::Label> m_xFTSign;
65 std::unique_ptr<weld::Label> m_xFTEncrypt;
66 std::unique_ptr<weld::TreeView> m_xCertLB;
67 std::unique_ptr<weld::Button> m_xViewBtn;
68 std::unique_ptr<weld::Button> m_xOKBtn;
69 std::unique_ptr<weld::Label> m_xFTDescription;
70 std::unique_ptr<weld::Entry> m_xDescriptionED;
71 std::unique_ptr<weld::Entry> m_xSearchBox;
72 std::unique_ptr<weld::Button> m_xReloadBtn;
74 std::unordered_map<css::uno::Reference< css::xml::crypto::XXMLSecurityContext>,
75 css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > > xMemCerts;
77 DECL_LINK(ReloadButtonHdl, weld::Button&, void);
78 DECL_LINK(ViewButtonHdl, weld::Button&, void);
79 DECL_LINK(CertificateHighlightHdl, weld::TreeView&, void);
80 DECL_LINK(CertificateSelectHdl, weld::TreeView&, bool);
81 DECL_LINK(SearchModifyHdl, weld::Entry&, void);
83 void ImplShowCertificateDetails();
84 void ImplInitialize(bool mbSearch = false);
85 void ImplReloadCertificates();
86 static void HandleOneUsageBit(OUString& string, int& bits, int bit, TranslateId name);
88 public:
89 CertificateChooser(weld::Window* pParent,
90 std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts,
91 UserAction eAction);
92 virtual ~CertificateChooser() override;
94 static CertificateChooser* getInstance(weld::Window* _pParent,
95 std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts,
96 UserAction eAction) {
97 if (!mxInstance)
99 mxInstance = new CertificateChooser(_pParent, std::move(rxSecurityContexts), eAction);
101 return mxInstance;
104 short run() override;
106 css::uno::Sequence<css::uno::Reference< css::security::XCertificate > > GetSelectedCertificates();
107 css::uno::Reference< css::xml::crypto::XXMLSecurityContext > GetSelectedSecurityContext() const;
108 /// Gets the description string provided when selecting the certificate.
109 OUString GetDescription() const;
111 /// Returns the usage string of the selected certificate, if any.
112 OUString GetUsageText();
114 static OUString UsageInClearText(int bits);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */