Bump version to 5.0-14
[LibreOffice.git] / xmlsecurity / source / framework / decryptorimpl.cxx
blobbb41a3dce52fd6f652447f0a44e2db12de69c7e4
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 "decryptorimpl.hxx"
22 #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.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.DecryptorImpl"
37 DecryptorImpl::DecryptorImpl(const Reference< XComponentContext > & xContext) : DecryptorImpl_Base(xContext)
41 DecryptorImpl::~DecryptorImpl()
45 bool DecryptorImpl::checkReady() const
46 /****** DecryptorImpl/checkReady *********************************************
48 * NAME
49 * checkReady -- checks the conditions for the decryption.
51 * SYNOPSIS
52 * bReady = checkReady( );
54 * FUNCTION
55 * checks whether all following conditions are satisfied:
56 * 1. the result listener is ready;
57 * 2. the EncryptionEngine 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() && EncryptionEngine::checkReady());
73 void DecryptorImpl::notifyResultListener() const
74 throw (cssu::Exception, cssu::RuntimeException)
75 /****** DecryptorImpl/notifyResultListener ***********************************
77 * NAME
78 * notifyResultListener -- notifies the listener about the decryption
79 * result.
81 * SYNOPSIS
82 * notifyResultListener( );
84 * FUNCTION
85 * see NAME.
87 * INPUTS
88 * empty
90 * RESULT
91 * empty
93 * AUTHOR
94 * Michael Mi
95 * Email: michael.mi@sun.com
96 ******************************************************************************/
98 cssu::Reference< cssxc::sax::XDecryptionResultListener >
99 xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
101 xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus);
104 void DecryptorImpl::startEngine( const cssu::Reference<
105 cssxc::XXMLEncryptionTemplate >&
106 xEncryptionTemplate)
107 throw (cssu::Exception, cssu::RuntimeException)
108 /****** DecryptorImpl/startEngine ********************************************
110 * NAME
111 * startEngine -- decrypts the encryption.
113 * SYNOPSIS
114 * startEngine( xEncryptionTemplate );
116 * FUNCTION
117 * decrypts the encryption element, then if succeeds, updates the link
118 * of old template element to the new encryption element in
119 * SAXEventKeeper.
121 * INPUTS
122 * xEncryptionTemplate - the encryption template to be decrypted.
124 * RESULT
125 * empty
127 * AUTHOR
128 * Michael Mi
129 * Email: michael.mi@sun.com
130 ******************************************************************************/
132 cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate;
135 xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
136 m_nStatus = xResultTemplate->getStatus();
138 catch( cssu::Exception& )
140 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
143 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
145 cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement
146 = xResultTemplate->getTemplate();
147 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
151 /* XDecryptionResultBroadcaster */
152 void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
153 throw (cssu::Exception, cssu::RuntimeException, std::exception)
155 m_xResultListener = listener;
156 tryToPerform();
159 void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&)
160 throw (cssu::RuntimeException, std::exception)
164 /* XInitialization */
165 void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
166 throw (cssu::Exception, cssu::RuntimeException, std::exception)
168 OSL_ASSERT(aArguments.getLength() == 5);
170 OUString ouTempString;
172 aArguments[0] >>= ouTempString;
173 m_nSecurityId = ouTempString.toInt32();
174 aArguments[1] >>= m_xSAXEventKeeper;
175 aArguments[2] >>= ouTempString;
176 m_nIdOfTemplateEC = ouTempString.toInt32();
177 aArguments[3] >>= m_xXMLSecurityContext;
178 aArguments[4] >>= m_xXMLEncryption;
181 OUString DecryptorImpl_getImplementationName ()
182 throw (cssu::RuntimeException)
184 return OUString ( IMPLEMENTATION_NAME );
187 cssu::Sequence< OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( )
188 throw (cssu::RuntimeException)
190 cssu::Sequence < OUString > aRet(1);
191 OUString* pArray = aRet.getArray();
192 pArray[0] = "com.sun.star.xml.crypto.sax.Decryptor";
193 return aRet;
196 cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& xMSF)
197 throw( cssu::Exception )
199 return (cppu::OWeakObject*) new DecryptorImpl( comphelper::getComponentContext( xMSF ) );
202 /* XServiceInfo */
203 OUString SAL_CALL DecryptorImpl::getImplementationName( )
204 throw (cssu::RuntimeException, std::exception)
206 return DecryptorImpl_getImplementationName();
209 sal_Bool SAL_CALL DecryptorImpl::supportsService( const OUString& rServiceName )
210 throw (cssu::RuntimeException, std::exception)
212 return cppu::supportsService(this, rServiceName);
215 cssu::Sequence< OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( )
216 throw (cssu::RuntimeException, std::exception)
218 return DecryptorImpl_getSupportedServiceNames();
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */