Bump version to 5.0-14
[LibreOffice.git] / xmlsecurity / source / framework / signaturecreatorimpl.cxx
blob68f0025bde7c77172daf58e118e7979b2778ce6e
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 "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( const Reference<XComponentContext> & xContext )
38 : SignatureCreatorImpl_Base(xContext), 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 * INPUTS
62 * empty
64 * RESULT
65 * bReady - true if all conditions are satisfied, false otherwise
67 * AUTHOR
68 * Michael Mi
69 * Email: michael.mi@sun.com
70 ******************************************************************************/
72 return (m_xResultListener.is() &&
73 (m_nIdOfBlocker != -1) &&
74 SignatureEngine::checkReady());
77 void SignatureCreatorImpl::notifyResultListener() const
78 throw (cssu::Exception, cssu::RuntimeException)
79 /****** SignatureCreatorImpl/notifyResultListener *****************************
81 * NAME
82 * notifyResultListener -- notifies the listener about the signature
83 * creation result.
85 * SYNOPSIS
86 * notifyResultListener( );
88 * FUNCTION
89 * see NAME.
91 * INPUTS
92 * empty
94 * RESULT
95 * empty
97 * AUTHOR
98 * Michael Mi
99 * Email: michael.mi@sun.com
100 ******************************************************************************/
102 cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
103 xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
105 xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
108 void SignatureCreatorImpl::startEngine( const cssu::Reference<
109 cssxc::XXMLSignatureTemplate >&
110 xSignatureTemplate)
111 throw (cssu::Exception, cssu::RuntimeException)
112 /****** SignatureCreatorImpl/startEngine *************************************
114 * NAME
115 * startEngine -- generates the signature.
117 * SYNOPSIS
118 * startEngine( xSignatureTemplate );
120 * FUNCTION
121 * generates the signature element, then if succeeds, updates the link
122 * of old template element to the new signature element in
123 * SAXEventKeeper.
125 * INPUTS
126 * xSignatureTemplate - the signature template (along with all referenced
127 * elements) to be signed.
129 * RESULT
130 * empty
132 * AUTHOR
133 * Michael Mi
134 * Email: michael.mi@sun.com
135 ******************************************************************************/
137 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
140 xResultTemplate = m_xXMLSignature->generate(xSignatureTemplate, m_xSecurityEnvironment);
141 m_nStatus = xResultTemplate->getStatus();
143 catch( cssu::Exception& )
145 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
148 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
150 cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
151 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
155 void SignatureCreatorImpl::clearUp() const
156 /****** SignatureCreatorImpl/clearUp *****************************************
158 * NAME
159 * clearUp -- clear up all resources used by the signature generation.
161 * SYNOPSIS
162 * clearUp( );
164 * FUNCTION
165 * cleaning resources up includes:
166 * 1. SignatureEngine's clearing up;
167 * 2. releases the Blocker for the signature template element.
169 * INPUTS
170 * empty
172 * RESULT
173 * empty
175 * AUTHOR
176 * Michael Mi
177 * Email: michael.mi@sun.com
178 ******************************************************************************/
180 SignatureEngine::clearUp();
182 if (m_nIdOfBlocker != -1)
184 m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
188 /* XBlockerMonitor */
189 void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
190 throw (cssu::Exception, cssu::RuntimeException, std::exception)
192 m_nIdOfBlocker = id;
193 tryToPerform();
196 /* XSignatureCreationResultBroadcaster */
197 void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
198 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
199 throw (cssu::Exception, cssu::RuntimeException, std::exception)
201 m_xResultListener = listener;
202 tryToPerform();
205 void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
206 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >&)
207 throw (cssu::RuntimeException, std::exception)
211 /* XInitialization */
212 void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
213 throw (cssu::Exception, cssu::RuntimeException, std::exception)
215 OSL_ASSERT(aArguments.getLength() == 5);
217 OUString ouTempString;
219 aArguments[0] >>= ouTempString;
220 m_nSecurityId = ouTempString.toInt32();
221 aArguments[1] >>= m_xSAXEventKeeper;
222 aArguments[2] >>= ouTempString;
223 m_nIdOfTemplateEC = ouTempString.toInt32();
224 aArguments[3] >>= m_xSecurityEnvironment;
225 aArguments[4] >>= m_xXMLSignature;
229 OUString SignatureCreatorImpl_getImplementationName ()
230 throw (cssu::RuntimeException)
232 return OUString ( IMPLEMENTATION_NAME );
235 cssu::Sequence< OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames( )
236 throw (cssu::RuntimeException)
238 cssu::Sequence < OUString > aRet(1);
239 OUString* pArray = aRet.getArray();
240 pArray[0] = "com.sun.star.xml.crypto.sax.SignatureCreator";
241 return aRet;
244 cssu::Reference< cssu::XInterface > SAL_CALL SignatureCreatorImpl_createInstance(
245 const cssu::Reference< cssl::XMultiServiceFactory >& xMSF )
246 throw( cssu::Exception )
248 return (cppu::OWeakObject*) new SignatureCreatorImpl( comphelper::getComponentContext( xMSF ) );
251 /* XServiceInfo */
252 OUString SAL_CALL SignatureCreatorImpl::getImplementationName( )
253 throw (cssu::RuntimeException, std::exception)
255 return SignatureCreatorImpl_getImplementationName();
258 sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const OUString& rServiceName )
259 throw (cssu::RuntimeException, std::exception)
261 return cppu::supportsService(this, rServiceName);
264 cssu::Sequence< OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
265 throw (cssu::RuntimeException, std::exception)
267 return SignatureCreatorImpl_getSupportedServiceNames();
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */