Update ooo320-m1
[ooovba.git] / xmlsecurity / source / framework / decryptorimpl.cxx
blobd4d0ec50cde9c9ae73c556445ecd2ec22fdc5cd4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: decryptorimpl.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include "decryptorimpl.hxx"
35 #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
36 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 namespace cssu = com::sun::star::uno;
40 namespace cssl = com::sun::star::lang;
41 namespace cssxc = com::sun::star::xml::crypto;
42 namespace cssxw = com::sun::star::xml::wrapper;
44 #define SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor"
45 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"
47 #define DECLARE_ASCII( SASCIIVALUE ) \
48 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
50 DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
52 mxMSF = rxMSF;
55 DecryptorImpl::~DecryptorImpl()
59 bool DecryptorImpl::checkReady() const
60 /****** DecryptorImpl/checkReady *********************************************
62 * NAME
63 * checkReady -- checks the conditions for the decryption.
65 * SYNOPSIS
66 * bReady = checkReady( );
68 * FUNCTION
69 * checks whether all following conditions are satisfied:
70 * 1. the result listener is ready;
71 * 2. the EncryptionEngine is ready.
73 * INPUTS
74 * empty
76 * RESULT
77 * bReady - true if all conditions are satisfied, false otherwise
79 * HISTORY
80 * 05.01.2004 - implemented
82 * AUTHOR
83 * Michael Mi
84 * Email: michael.mi@sun.com
85 ******************************************************************************/
87 return (m_xResultListener.is() && EncryptionEngine::checkReady());
90 void DecryptorImpl::notifyResultListener() const
91 throw (cssu::Exception, cssu::RuntimeException)
92 /****** DecryptorImpl/notifyResultListener ***********************************
94 * NAME
95 * notifyResultListener -- notifies the listener about the decryption
96 * result.
98 * SYNOPSIS
99 * notifyResultListener( );
101 * FUNCTION
102 * see NAME.
104 * INPUTS
105 * empty
107 * RESULT
108 * empty
110 * HISTORY
111 * 05.01.2004 - implemented
113 * AUTHOR
114 * Michael Mi
115 * Email: michael.mi@sun.com
116 ******************************************************************************/
118 cssu::Reference< cssxc::sax::XDecryptionResultListener >
119 xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
121 xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus);
124 void DecryptorImpl::startEngine( const cssu::Reference<
125 cssxc::XXMLEncryptionTemplate >&
126 xEncryptionTemplate)
127 throw (cssu::Exception, cssu::RuntimeException)
128 /****** DecryptorImpl/startEngine ********************************************
130 * NAME
131 * startEngine -- decrypts the encryption.
133 * SYNOPSIS
134 * startEngine( xEncryptionTemplate );
136 * FUNCTION
137 * decrypts the encryption element, then if succeeds, updates the link
138 * of old template element to the new encryption element in
139 * SAXEventKeeper.
141 * INPUTS
142 * xEncryptionTemplate - the encryption template to be decrypted.
144 * RESULT
145 * empty
147 * HISTORY
148 * 05.01.2004 - implemented
150 * AUTHOR
151 * Michael Mi
152 * Email: michael.mi@sun.com
153 ******************************************************************************/
155 cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate;
158 xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
159 m_nStatus = xResultTemplate->getStatus();
161 catch( cssu::Exception& )
163 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
166 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
168 cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement
169 = xResultTemplate->getTemplate();
170 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
174 /* XDecryptionResultBroadcaster */
175 void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
176 throw (cssu::Exception, cssu::RuntimeException)
178 m_xResultListener = listener;
179 tryToPerform();
182 void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&)
183 throw (cssu::RuntimeException)
187 /* XInitialization */
188 void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
189 throw (cssu::Exception, cssu::RuntimeException)
191 OSL_ASSERT(aArguments.getLength() == 5);
193 rtl::OUString ouTempString;
195 aArguments[0] >>= ouTempString;
196 m_nSecurityId = ouTempString.toInt32();
197 aArguments[1] >>= m_xSAXEventKeeper;
198 aArguments[2] >>= ouTempString;
199 m_nIdOfTemplateEC = ouTempString.toInt32();
200 aArguments[3] >>= m_xXMLSecurityContext;
201 aArguments[4] >>= m_xXMLEncryption;
204 rtl::OUString DecryptorImpl_getImplementationName ()
205 throw (cssu::RuntimeException)
207 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
210 sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName )
211 throw (cssu::RuntimeException)
213 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
216 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( )
217 throw (cssu::RuntimeException)
219 cssu::Sequence < rtl::OUString > aRet(1);
220 rtl::OUString* pArray = aRet.getArray();
221 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
222 return aRet;
224 #undef SERVICE_NAME
226 cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
227 throw( cssu::Exception )
229 return (cppu::OWeakObject*) new DecryptorImpl(rSMgr);
232 /* XServiceInfo */
233 rtl::OUString SAL_CALL DecryptorImpl::getImplementationName( )
234 throw (cssu::RuntimeException)
236 return DecryptorImpl_getImplementationName();
238 sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName )
239 throw (cssu::RuntimeException)
241 return DecryptorImpl_supportsService( rServiceName );
243 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( )
244 throw (cssu::RuntimeException)
246 return DecryptorImpl_getSupportedServiceNames();