Bump version to 6.0-36
[LibreOffice.git] / xmlsecurity / source / framework / signaturecreatorimpl.cxx
blob00e635667a16c81568f22b55d1b80c1ec5ad5548
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 .
21 #include <framework/signaturecreatorimpl.hxx>
22 #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
23 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <osl/diagnose.h>
29 using namespace com::sun::star::uno;
30 namespace cssu = com::sun::star::uno;
31 namespace cssl = com::sun::star::lang;
32 namespace cssxc = com::sun::star::xml::crypto;
33 namespace cssxw = com::sun::star::xml::wrapper;
35 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
37 SignatureCreatorImpl::SignatureCreatorImpl()
38 : SignatureCreatorImpl_Base(), m_nIdOfBlocker(-1)
42 SignatureCreatorImpl::~SignatureCreatorImpl( )
46 bool SignatureCreatorImpl::checkReady() const
47 /****** SignatureCreatorImpl/checkReady **************************************
49 * NAME
50 * checkReady -- checks the conditions for the signature generation.
52 * SYNOPSIS
53 * bReady = checkReady( );
55 * FUNCTION
56 * checks whether all following conditions are satisfied:
57 * 1. the result listener is ready;
58 * 2. the id of the template blocker is known;
59 * 3. the SignatureEngine is ready.
61 * RESULT
62 * bReady - true if all conditions are satisfied, false otherwise
63 ******************************************************************************/
65 return (m_xResultListener.is() &&
66 (m_nIdOfBlocker != -1) &&
67 SignatureEngine::checkReady());
70 void SignatureCreatorImpl::notifyResultListener() const
71 /****** SignatureCreatorImpl/notifyResultListener *****************************
73 * NAME
74 * notifyResultListener -- notifies the listener about the signature
75 * creation result.
76 ******************************************************************************/
78 cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
79 xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
81 xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
84 void SignatureCreatorImpl::startEngine(const rtl::Reference<XMLSignatureTemplateImpl>& xSignatureTemplate)
85 /****** SignatureCreatorImpl/startEngine *************************************
87 * NAME
88 * startEngine -- generates the signature.
90 * FUNCTION
91 * generates the signature element, then if succeeds, updates the link
92 * of old template element to the new signature element in
93 * SAXEventKeeper.
95 * INPUTS
96 * xSignatureTemplate - the signature template (along with all referenced
97 * elements) to be signed.
98 ******************************************************************************/
100 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
103 xResultTemplate = m_xXMLSignature->generate(css::uno::Reference<css::xml::crypto::XXMLSignatureTemplate>(xSignatureTemplate.get()), m_xSecurityEnvironment);
104 m_nStatus = xResultTemplate->getStatus();
106 catch( cssu::Exception& )
108 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
111 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
113 cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
114 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
118 void SignatureCreatorImpl::clearUp() const
119 /****** SignatureCreatorImpl/clearUp *****************************************
121 * NAME
122 * clearUp -- clear up all resources used by the signature generation.
124 * SYNOPSIS
125 * clearUp( );
127 * FUNCTION
128 * cleaning resources up includes:
129 * 1. SignatureEngine's clearing up;
130 * 2. releases the Blocker for the signature template element.
131 ******************************************************************************/
133 SignatureEngine::clearUp();
135 if (m_nIdOfBlocker != -1)
137 m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
141 /* XBlockerMonitor */
142 void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
144 m_nIdOfBlocker = id;
145 tryToPerform();
148 /* XSignatureCreationResultBroadcaster */
149 void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
150 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
152 m_xResultListener = listener;
153 tryToPerform();
156 void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
157 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >&)
161 /* XInitialization */
162 void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
164 OSL_ASSERT(aArguments.getLength() == 5);
166 OUString ouTempString;
168 aArguments[0] >>= ouTempString;
169 m_nSecurityId = ouTempString.toInt32();
170 aArguments[1] >>= m_xSAXEventKeeper;
171 aArguments[2] >>= ouTempString;
172 m_nIdOfTemplateEC = ouTempString.toInt32();
173 aArguments[3] >>= m_xSecurityEnvironment;
174 aArguments[4] >>= m_xXMLSignature;
178 OUString SignatureCreatorImpl_getImplementationName ()
180 return OUString ( IMPLEMENTATION_NAME );
183 cssu::Sequence< OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames( )
185 cssu::Sequence<OUString> aRet { "com.sun.star.xml.crypto.sax.SignatureCreator" };
186 return aRet;
189 /* XServiceInfo */
190 OUString SAL_CALL SignatureCreatorImpl::getImplementationName( )
192 return SignatureCreatorImpl_getImplementationName();
195 sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const OUString& rServiceName )
197 return cppu::supportsService(this, rServiceName);
200 cssu::Sequence< OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
202 return SignatureCreatorImpl_getSupportedServiceNames();
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */