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 <framework/signatureengine.hxx>
22 #include <framework/xmlsignaturetemplateimpl.hxx>
23 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <rtl/ref.hxx>
27 using namespace com::sun::star::uno
;
28 namespace cssu
= com::sun::star::uno
;
29 namespace cssxc
= com::sun::star::xml::crypto
;
30 namespace cssxw
= com::sun::star::xml::wrapper
;
32 SignatureEngine::SignatureEngine()
33 : m_nTotalReferenceNumber(-1)
37 bool SignatureEngine::checkReady() const
38 /****** SignatureEngine/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 amount of reference is known;
51 * 4. all of referenced elements, the key element and the signature
52 * template are bufferred.
55 * bReady - true if all conditions are satisfied, false otherwise
56 ******************************************************************************/
60 sal_Int32 nKeyInc
= 0;
61 if (m_nIdOfKeyEC
!= 0)
68 m_nTotalReferenceNumber
== -1 ||
69 m_nTotalReferenceNumber
+1+nKeyInc
> m_nNumOfResolvedReferences
)
77 void SignatureEngine::tryToPerform( )
78 /****** SignatureEngine/tryToPerform *****************************************
81 * tryToPerform -- tries to perform the signature operation.
84 * if the situation is ready, perform following operations.
85 * 1. prepares a signature template;
86 * 2. calls the signature bridge component;
87 * 3. clears up all used resources;
88 * 4. notifies the result listener;
89 * 5. sets the "accomplishment" flag.
90 ******************************************************************************/
94 rtl::Reference
<XMLSignatureTemplateImpl
> xSignatureTemplate
= new XMLSignatureTemplateImpl();
96 cssu::Reference
< cssxw::XXMLElementWrapper
>
97 xXMLElement
= m_xSAXEventKeeper
->getElement( m_nIdOfTemplateEC
);
99 xSignatureTemplate
->setTemplate(xXMLElement
);
101 std::vector
< sal_Int32
>::const_iterator ii
= m_vReferenceIds
.begin();
103 for( ; ii
!= m_vReferenceIds
.end() ; ++ii
)
105 xXMLElement
= m_xSAXEventKeeper
->getElement( *ii
);
106 xSignatureTemplate
->setTarget(xXMLElement
);
110 * set the Uri binding
112 xSignatureTemplate
->setBinding( this );
114 startEngine(xSignatureTemplate
);
121 notifyResultListener();
123 m_bMissionDone
= true;
127 void SignatureEngine::clearUp( ) const
128 /****** SignatureEngine/clearUp **********************************************
131 * clearUp -- clear up all resources used by this operation.
134 * cleaning resources up includes:
135 * 1. releases the ElementCollector for the signature template element;
136 * 2. releases ElementCollectors for referenced elements;
137 * 3. releases the ElementCollector for the key element, if there is one.
138 ******************************************************************************/
140 cssu::Reference
< cssxc::sax::XReferenceResolvedBroadcaster
>
141 xReferenceResolvedBroadcaster( m_xSAXEventKeeper
, cssu::UNO_QUERY
);
142 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
144 static_cast<const cssu::Reference
< cssxc::sax::XReferenceResolvedListener
> >(static_cast<SecurityEngine
*>(const_cast<SignatureEngine
*>(this))));
146 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfTemplateEC
);
148 std::vector
< sal_Int32
>::const_iterator ii
= m_vReferenceIds
.begin();
150 for( ; ii
!= m_vReferenceIds
.end() ; ++ii
)
152 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
154 static_cast<const cssu::Reference
< cssxc::sax::XReferenceResolvedListener
> >(static_cast<SecurityEngine
*>(const_cast<SignatureEngine
*>(this))));
155 m_xSAXEventKeeper
->removeElementCollector(*ii
);
158 if (m_nIdOfKeyEC
!= 0 && m_nIdOfKeyEC
!= -1)
160 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfKeyEC
);
164 /* XReferenceCollector */
165 void SAL_CALL
SignatureEngine::setReferenceCount( sal_Int32 count
)
167 m_nTotalReferenceNumber
= count
;
171 void SAL_CALL
SignatureEngine::setReferenceId( sal_Int32 id
)
173 m_vReferenceIds
.push_back( id
);
177 void SAL_CALL
SignatureEngine::setUriBinding(
179 const cssu::Reference
< css::io::XInputStream
>& aInputStream
)
181 m_vUris
.push_back(uri
);
182 m_vXInputStreams
.push_back(aInputStream
);
185 cssu::Reference
< css::io::XInputStream
> SAL_CALL
SignatureEngine::getUriBinding( const OUString
& uri
)
187 cssu::Reference
< css::io::XInputStream
> xInputStream
;
189 int size
= m_vUris
.size();
191 for( int i
=0; i
<size
; ++i
)
193 if (m_vUris
[i
] == uri
)
195 xInputStream
= m_vXInputStreams
[i
];
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */