fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmlsecurity / source / framework / decryptorimpl.cxx
blobec35abeec0a2488c11283d5f8ae4595bc68c5a52
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>
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.Decryptor"
32 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"
34 DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
36 mxMSF = rxMSF;
39 DecryptorImpl::~DecryptorImpl()
43 bool DecryptorImpl::checkReady() const
44 /****** DecryptorImpl/checkReady *********************************************
46 * NAME
47 * checkReady -- checks the conditions for the decryption.
49 * SYNOPSIS
50 * bReady = checkReady( );
52 * FUNCTION
53 * checks whether all following conditions are satisfied:
54 * 1. the result listener is ready;
55 * 2. the EncryptionEngine is ready.
57 * INPUTS
58 * empty
60 * RESULT
61 * bReady - true if all conditions are satisfied, false otherwise
63 * AUTHOR
64 * Michael Mi
65 * Email: michael.mi@sun.com
66 ******************************************************************************/
68 return (m_xResultListener.is() && EncryptionEngine::checkReady());
71 void DecryptorImpl::notifyResultListener() const
72 throw (cssu::Exception, cssu::RuntimeException)
73 /****** DecryptorImpl/notifyResultListener ***********************************
75 * NAME
76 * notifyResultListener -- notifies the listener about the decryption
77 * result.
79 * SYNOPSIS
80 * notifyResultListener( );
82 * FUNCTION
83 * see NAME.
85 * INPUTS
86 * empty
88 * RESULT
89 * empty
91 * AUTHOR
92 * Michael Mi
93 * Email: michael.mi@sun.com
94 ******************************************************************************/
96 cssu::Reference< cssxc::sax::XDecryptionResultListener >
97 xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
99 xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus);
102 void DecryptorImpl::startEngine( const cssu::Reference<
103 cssxc::XXMLEncryptionTemplate >&
104 xEncryptionTemplate)
105 throw (cssu::Exception, cssu::RuntimeException)
106 /****** DecryptorImpl/startEngine ********************************************
108 * NAME
109 * startEngine -- decrypts the encryption.
111 * SYNOPSIS
112 * startEngine( xEncryptionTemplate );
114 * FUNCTION
115 * decrypts the encryption element, then if succeeds, updates the link
116 * of old template element to the new encryption element in
117 * SAXEventKeeper.
119 * INPUTS
120 * xEncryptionTemplate - the encryption template to be decrypted.
122 * RESULT
123 * empty
125 * AUTHOR
126 * Michael Mi
127 * Email: michael.mi@sun.com
128 ******************************************************************************/
130 cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate;
133 xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
134 m_nStatus = xResultTemplate->getStatus();
136 catch( cssu::Exception& )
138 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
141 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
143 cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement
144 = xResultTemplate->getTemplate();
145 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
149 /* XDecryptionResultBroadcaster */
150 void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
151 throw (cssu::Exception, cssu::RuntimeException)
153 m_xResultListener = listener;
154 tryToPerform();
157 void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&)
158 throw (cssu::RuntimeException)
162 /* XInitialization */
163 void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
164 throw (cssu::Exception, cssu::RuntimeException)
166 OSL_ASSERT(aArguments.getLength() == 5);
168 OUString ouTempString;
170 aArguments[0] >>= ouTempString;
171 m_nSecurityId = ouTempString.toInt32();
172 aArguments[1] >>= m_xSAXEventKeeper;
173 aArguments[2] >>= ouTempString;
174 m_nIdOfTemplateEC = ouTempString.toInt32();
175 aArguments[3] >>= m_xXMLSecurityContext;
176 aArguments[4] >>= m_xXMLEncryption;
179 OUString DecryptorImpl_getImplementationName ()
180 throw (cssu::RuntimeException)
182 return OUString ( IMPLEMENTATION_NAME );
185 sal_Bool SAL_CALL DecryptorImpl_supportsService( const OUString& ServiceName )
186 throw (cssu::RuntimeException)
188 return ServiceName == SERVICE_NAME;
191 cssu::Sequence< OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( )
192 throw (cssu::RuntimeException)
194 cssu::Sequence < OUString > aRet(1);
195 OUString* pArray = aRet.getArray();
196 pArray[0] = OUString ( SERVICE_NAME );
197 return aRet;
199 #undef SERVICE_NAME
201 cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
202 throw( cssu::Exception )
204 return (cppu::OWeakObject*) new DecryptorImpl(rSMgr);
207 /* XServiceInfo */
208 OUString SAL_CALL DecryptorImpl::getImplementationName( )
209 throw (cssu::RuntimeException)
211 return DecryptorImpl_getImplementationName();
213 sal_Bool SAL_CALL DecryptorImpl::supportsService( const OUString& rServiceName )
214 throw (cssu::RuntimeException)
216 return DecryptorImpl_supportsService( rServiceName );
218 cssu::Sequence< OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( )
219 throw (cssu::RuntimeException)
221 return DecryptorImpl_getSupportedServiceNames();
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */