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/XMLEncryptionTemplate.hpp>
23 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 using namespace com::sun::star::uno
;
27 namespace cssxc
= com::sun::star::xml::crypto
;
28 namespace cssxw
= com::sun::star::xml::wrapper
;
30 EncryptionEngine::EncryptionEngine( const Reference
<XComponentContext
> & xContext
)
31 :m_xContext(xContext
), m_nIdOfBlocker(-1)
35 bool EncryptionEngine::checkReady() const
36 /****** EncryptionEngine/checkReady ******************************************
39 * checkReady -- checks the conditions for the main operation.
42 * bReady = checkReady( );
45 * checks whether all following conditions are satisfied:
46 * 1. the main operation has't begun yet;
47 * 2. the key material is known;
48 * 3. the id of the template blocker is known;
49 * 4. both the key element and the encryption template
56 * bReady - true if all conditions are satisfied, false otherwise
60 * Email: michael.mi@sun.com
61 ******************************************************************************/
65 sal_Int32 nKeyInc
= 0;
66 if (m_nIdOfKeyEC
!= 0)
73 m_nIdOfBlocker
== -1 ||
74 1+nKeyInc
> m_nNumOfResolvedReferences
)
82 void EncryptionEngine::tryToPerform( )
83 throw (Exception
, RuntimeException
)
84 /****** EncryptionEngine/tryToPerform ****************************************
87 * tryToPerform -- tries to perform the encryption/decryption operation.
93 * if the situation is ready, perform following operations.
94 * 1. prepares a encryption template;
95 * 2. calls the encryption bridge component;
96 * 3. clears up all used resources;
97 * 4. notifies the result listener;
98 * 5. sets the "accomplishment" flag.
108 * Email: michael.mi@sun.com
109 ******************************************************************************/
113 Reference
< cssxc::XXMLEncryptionTemplate
> xEncryptionTemplate
=
114 cssxc::XMLEncryptionTemplate::create( m_xContext
);
116 Reference
< cssxw::XXMLElementWrapper
> xXMLElement
117 = m_xSAXEventKeeper
->getElement( m_nIdOfTemplateEC
);
119 xEncryptionTemplate
->setTemplate(xXMLElement
);
121 startEngine( xEncryptionTemplate
);
128 notifyResultListener();
130 m_bMissionDone
= true;
134 void EncryptionEngine::clearUp( ) const
135 /****** EncryptionEngine/clearup *********************************************
138 * clearUp -- clear up all resources used by this operation.
144 * cleaning resources up includes:
145 * 1. releases the ElementCollector for the encryption template element;
146 * 2. releases the Blocker for the encryption template element;
147 * 3. releases the ElementCollector for the key element, if there is one.
157 * Email: michael.mi@sun.com
158 ******************************************************************************/
160 Reference
< cssxc::sax::XReferenceResolvedBroadcaster
>
161 xReferenceResolvedBroadcaster( m_xSAXEventKeeper
, UNO_QUERY
);
163 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
165 static_cast<const Reference
< cssxc::sax::XReferenceResolvedListener
> >((SecurityEngine
*)this));
167 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfTemplateEC
);
169 if (m_nIdOfBlocker
!= -1)
171 m_xSAXEventKeeper
->removeBlocker(m_nIdOfBlocker
);
174 if (m_nIdOfKeyEC
!= 0 && m_nIdOfKeyEC
!= -1)
176 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfKeyEC
);
180 /* XBlockerMonitor */
181 void SAL_CALL
EncryptionEngine::setBlockerId( sal_Int32 id
)
182 throw (com::sun::star::uno::Exception
, com::sun::star::uno::RuntimeException
, std::exception
)
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */