1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "encryptionengine.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 cssxc
= com::sun::star::xml::crypto
;
28 namespace cssxw
= com::sun::star::xml::wrapper
;
30 #define ENCRYPTION_TEMPLATE "com.sun.star.xml.crypto.XMLEncryptionTemplate"
32 EncryptionEngine::EncryptionEngine( )
37 bool EncryptionEngine::checkReady() const
38 /****** EncryptionEngine/checkReady ******************************************
41 * checkReady -- checks the conditions for the main operation.
44 * bReady = checkReady( );
47 * checks whether all following conditions are satisfied:
48 * 1. the main operation has't begun yet;
49 * 2. the key material is known;
50 * 3. the id of the template blocker is known;
51 * 4. both the key element and the encryption template
58 * bReady - true if all conditions are satisfied, false otherwise
62 * Email: michael.mi@sun.com
63 ******************************************************************************/
67 sal_Int32 nKeyInc
= 0;
68 if (m_nIdOfKeyEC
!= 0)
75 m_nIdOfBlocker
== -1 ||
76 1+nKeyInc
> m_nNumOfResolvedReferences
)
84 void EncryptionEngine::tryToPerform( )
85 throw (cssu::Exception
, cssu::RuntimeException
)
86 /****** EncryptionEngine/tryToPerform ****************************************
89 * tryToPerform -- tries to perform the encryption/decryption operation.
95 * if the situation is ready, perform following operations.
96 * 1. prepares a encryption template;
97 * 2. calls the encryption bridge component;
98 * 3. clears up all used resources;
99 * 4. notifies the result listener;
100 * 5. sets the "accomplishment" flag.
110 * Email: michael.mi@sun.com
111 ******************************************************************************/
115 const rtl::OUString
sEncryptionTemplate (
116 RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_TEMPLATE
) );
117 cssu::Reference
< cssxc::XXMLEncryptionTemplate
> xEncryptionTemplate(
118 mxMSF
->createInstance( sEncryptionTemplate
), cssu::UNO_QUERY
);
120 OSL_ASSERT( xEncryptionTemplate
.is() );
122 cssu::Reference
< cssxw::XXMLElementWrapper
> xXMLElement
123 = m_xSAXEventKeeper
->getElement( m_nIdOfTemplateEC
);
125 xEncryptionTemplate
->setTemplate(xXMLElement
);
127 startEngine( xEncryptionTemplate
);
134 notifyResultListener();
136 m_bMissionDone
= true;
140 void EncryptionEngine::clearUp( ) const
141 /****** EncryptionEngine/clearup *********************************************
144 * clearUp -- clear up all resources used by this operation.
150 * cleaning resources up includes:
151 * 1. releases the ElementCollector for the encryption template element;
152 * 2. releases the Blocker for the encryption template element;
153 * 3. releases the ElementCollector for the key element, if there is one.
163 * Email: michael.mi@sun.com
164 ******************************************************************************/
166 cssu::Reference
< cssxc::sax::XReferenceResolvedBroadcaster
>
167 xReferenceResolvedBroadcaster( m_xSAXEventKeeper
, cssu::UNO_QUERY
);
169 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
171 (const cssu::Reference
< cssxc::sax::XReferenceResolvedListener
>)((SecurityEngine
*)this));
173 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfTemplateEC
);
175 if (m_nIdOfBlocker
!= -1)
177 m_xSAXEventKeeper
->removeBlocker(m_nIdOfBlocker
);
180 if (m_nIdOfKeyEC
!= 0 && m_nIdOfKeyEC
!= -1)
182 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfKeyEC
);
186 /* XBlockerMonitor */
187 void SAL_CALL
EncryptionEngine::setBlockerId( sal_Int32 id
)
188 throw (com::sun::star::uno::Exception
, com::sun::star::uno::RuntimeException
)
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */