Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / xmlsecurity / source / xmlsec / nss / xmlsecuritycontext_nssimpl.cxx
blob18c0bd3ecd5e62e2fc949aaff2d6e5f6989431d3
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 #include <sal/config.h>
21 #include <vector>
22 #include <cppuhelper/implbase.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
27 namespace com::sun::star::uno { class XComponentContext; }
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::lang ;
32 using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
33 using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
35 class XMLSecurityContext_NssImpl
36 : public ::cppu::WeakImplHelper<xml::crypto::XXMLSecurityContext, lang::XServiceInfo>
38 private:
39 std::vector<uno::Reference<xml::crypto::XSecurityEnvironment>> m_vSecurityEnvironments;
41 sal_Int32 m_nDefaultEnvIndex;
43 public:
44 XMLSecurityContext_NssImpl();
46 //XXMLSecurityContext
47 virtual sal_Int32 SAL_CALL addSecurityEnvironment(
48 const uno::Reference<xml::crypto::XSecurityEnvironment>& aSecurityEnvironment) override;
50 virtual ::sal_Int32 SAL_CALL getSecurityEnvironmentNumber() override;
52 virtual uno::Reference<xml::crypto::XSecurityEnvironment>
53 SAL_CALL getSecurityEnvironmentByIndex(::sal_Int32 index) override;
55 virtual uno::Reference<xml::crypto::XSecurityEnvironment>
56 SAL_CALL getSecurityEnvironment() override;
58 virtual ::sal_Int32 SAL_CALL getDefaultSecurityEnvironmentIndex() override;
60 virtual void SAL_CALL setDefaultSecurityEnvironmentIndex(sal_Int32 nDefaultEnvIndex) override;
62 //XServiceInfo
63 virtual OUString SAL_CALL getImplementationName() override;
65 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
67 virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
70 XMLSecurityContext_NssImpl::XMLSecurityContext_NssImpl()
71 : m_nDefaultEnvIndex(-1)
75 sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::addSecurityEnvironment(
76 const uno::Reference< xml::crypto::XSecurityEnvironment >& aSecurityEnvironment)
78 if( !aSecurityEnvironment.is() )
80 throw uno::RuntimeException() ;
83 m_vSecurityEnvironments.push_back( aSecurityEnvironment );
85 return m_vSecurityEnvironments.size() - 1 ;
89 sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber( )
91 return m_vSecurityEnvironments.size();
94 uno::Reference< xml::crypto::XSecurityEnvironment > SAL_CALL
95 XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
97 if (index < 0 || index >= static_cast<sal_Int32>(m_vSecurityEnvironments.size()))
98 throw uno::RuntimeException();
100 uno::Reference< xml::crypto::XSecurityEnvironment > xSecurityEnvironment = m_vSecurityEnvironments[index];
101 return xSecurityEnvironment;
104 uno::Reference< xml::crypto::XSecurityEnvironment > SAL_CALL
105 XMLSecurityContext_NssImpl::getSecurityEnvironment( )
107 if (m_nDefaultEnvIndex < 0 || m_nDefaultEnvIndex >= static_cast<sal_Int32>(m_vSecurityEnvironments.size()))
108 throw uno::RuntimeException();
110 return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex);
113 sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getDefaultSecurityEnvironmentIndex( )
115 return m_nDefaultEnvIndex ;
118 void SAL_CALL XMLSecurityContext_NssImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex )
120 m_nDefaultEnvIndex = nDefaultEnvIndex;
123 /* XServiceInfo */
124 OUString SAL_CALL XMLSecurityContext_NssImpl::getImplementationName() {
125 return "com.sun.star.xml.crypto.XMLSecurityContext";
128 /* XServiceInfo */
129 sal_Bool SAL_CALL XMLSecurityContext_NssImpl::supportsService( const OUString& serviceName) {
130 return cppu::supportsService(this, serviceName);
133 /* XServiceInfo */
134 uno::Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl::getSupportedServiceNames() {
135 uno::Sequence<OUString> seqServiceNames { "com.sun.star.xml.crypto.XMLSecurityContext" };
136 return seqServiceNames ;
139 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
140 com_sun_star_xml_crypto_XMLSecurityContext_get_implementation(
141 uno::XComponentContext* /*pCtx*/, uno::Sequence<uno::Any> const& /*rSeq*/)
143 return cppu::acquire(new XMLSecurityContext_NssImpl);
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */