Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / xmlsecurity / source / framework / signaturecreatorimpl.cxx
blob7550d519aff9ff78c99cf2407c6d38296cb547bd
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>
26 namespace cssu = com::sun::star::uno;
27 namespace cssl = com::sun::star::lang;
28 namespace cssxc = com::sun::star::xml::crypto;
29 namespace cssxw = com::sun::star::xml::wrapper;
31 #define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureCreator"
32 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
34 SignatureCreatorImpl::SignatureCreatorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF )
35 :m_nIdOfBlocker(-1)
37 mxMSF = rxMSF;
40 SignatureCreatorImpl::~SignatureCreatorImpl( )
44 bool SignatureCreatorImpl::checkReady() const
45 /****** SignatureCreatorImpl/checkReady **************************************
47 * NAME
48 * checkReady -- checks the conditions for the signature generation.
50 * SYNOPSIS
51 * bReady = checkReady( );
53 * FUNCTION
54 * checks whether all following conditions are satisfied:
55 * 1. the result listener is ready;
56 * 2. the id of the template blocker is known;
57 * 3. the SignatureEngine is ready.
59 * INPUTS
60 * empty
62 * RESULT
63 * bReady - true if all conditions are satisfied, false otherwise
65 * AUTHOR
66 * Michael Mi
67 * Email: michael.mi@sun.com
68 ******************************************************************************/
70 return (m_xResultListener.is() &&
71 (m_nIdOfBlocker != -1) &&
72 SignatureEngine::checkReady());
75 void SignatureCreatorImpl::notifyResultListener() const
76 throw (cssu::Exception, cssu::RuntimeException)
77 /****** SignatureCreatorImpl/notifyResultListener *****************************
79 * NAME
80 * notifyResultListener -- notifies the listener about the signature
81 * creation result.
83 * SYNOPSIS
84 * notifyResultListener( );
86 * FUNCTION
87 * see NAME.
89 * INPUTS
90 * empty
92 * RESULT
93 * empty
95 * AUTHOR
96 * Michael Mi
97 * Email: michael.mi@sun.com
98 ******************************************************************************/
100 cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
101 xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
103 xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
106 void SignatureCreatorImpl::startEngine( const cssu::Reference<
107 cssxc::XXMLSignatureTemplate >&
108 xSignatureTemplate)
109 throw (cssu::Exception, cssu::RuntimeException)
110 /****** SignatureCreatorImpl/startEngine *************************************
112 * NAME
113 * startEngine -- generates the signature.
115 * SYNOPSIS
116 * startEngine( xSignatureTemplate );
118 * FUNCTION
119 * generates the signature element, then if succeeds, updates the link
120 * of old template element to the new signature element in
121 * SAXEventKeeper.
123 * INPUTS
124 * xSignatureTemplate - the signature template (along with all referenced
125 * elements) to be signed.
127 * RESULT
128 * empty
130 * AUTHOR
131 * Michael Mi
132 * Email: michael.mi@sun.com
133 ******************************************************************************/
135 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
138 xResultTemplate = m_xXMLSignature->generate(xSignatureTemplate, m_xSecurityEnvironment);
139 m_nStatus = xResultTemplate->getStatus();
141 catch( cssu::Exception& )
143 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
146 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
148 cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
149 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
153 void SignatureCreatorImpl::clearUp() const
154 /****** SignatureCreatorImpl/clearUp *****************************************
156 * NAME
157 * clearUp -- clear up all resources used by the signature generation.
159 * SYNOPSIS
160 * clearUp( );
162 * FUNCTION
163 * cleaning resources up includes:
164 * 1. SignatureEngine's clearing up;
165 * 2. releases the Blocker for the signature template element.
167 * INPUTS
168 * empty
170 * RESULT
171 * empty
173 * AUTHOR
174 * Michael Mi
175 * Email: michael.mi@sun.com
176 ******************************************************************************/
178 SignatureEngine::clearUp();
180 if (m_nIdOfBlocker != -1)
182 m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
186 /* XBlockerMonitor */
187 void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
188 throw (cssu::Exception, cssu::RuntimeException)
190 m_nIdOfBlocker = id;
191 tryToPerform();
194 /* XSignatureCreationResultBroadcaster */
195 void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
196 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
197 throw (cssu::Exception, cssu::RuntimeException)
199 m_xResultListener = listener;
200 tryToPerform();
203 void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
204 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >&)
205 throw (cssu::RuntimeException)
209 /* XInitialization */
210 void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
211 throw (cssu::Exception, cssu::RuntimeException)
213 OSL_ASSERT(aArguments.getLength() == 5);
215 rtl::OUString ouTempString;
217 aArguments[0] >>= ouTempString;
218 m_nSecurityId = ouTempString.toInt32();
219 aArguments[1] >>= m_xSAXEventKeeper;
220 aArguments[2] >>= ouTempString;
221 m_nIdOfTemplateEC = ouTempString.toInt32();
222 aArguments[3] >>= m_xSecurityEnvironment;
223 aArguments[4] >>= m_xXMLSignature;
227 rtl::OUString SignatureCreatorImpl_getImplementationName ()
228 throw (cssu::RuntimeException)
230 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
233 sal_Bool SAL_CALL SignatureCreatorImpl_supportsService( const rtl::OUString& ServiceName )
234 throw (cssu::RuntimeException)
236 return ServiceName == SERVICE_NAME;
239 cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames( )
240 throw (cssu::RuntimeException)
242 cssu::Sequence < rtl::OUString > aRet(1);
243 rtl::OUString* pArray = aRet.getArray();
244 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
245 return aRet;
247 #undef SERVICE_NAME
249 cssu::Reference< cssu::XInterface > SAL_CALL SignatureCreatorImpl_createInstance(
250 const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
251 throw( cssu::Exception )
253 return (cppu::OWeakObject*) new SignatureCreatorImpl( rSMgr );
256 /* XServiceInfo */
257 rtl::OUString SAL_CALL SignatureCreatorImpl::getImplementationName( )
258 throw (cssu::RuntimeException)
260 return SignatureCreatorImpl_getImplementationName();
262 sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const rtl::OUString& rServiceName )
263 throw (cssu::RuntimeException)
265 return SignatureCreatorImpl_supportsService( rServiceName );
267 cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
268 throw (cssu::RuntimeException)
270 return SignatureCreatorImpl_getSupportedServiceNames();
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */