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 <rtl/ref.hxx>
25 namespace com::sun::star::xml::wrapper
{ class XXMLElementWrapper
; }
27 using namespace com::sun::star::uno
;
29 SignatureEngine::SignatureEngine()
30 : m_nTotalReferenceNumber(-1)
34 bool SignatureEngine::checkReady() const
35 /****** SignatureEngine/checkReady *******************************************
38 * checkReady -- checks the conditions for the main operation.
41 * bReady = checkReady( );
44 * checks whether all following conditions are satisfied:
45 * 1. the main operation has't begun yet;
46 * 2. the key material is known;
47 * 3. the amount of reference is known;
48 * 4. all of referenced elements, the key element and the signature
49 * template are buffered.
52 * bReady - true if all conditions are satisfied, false otherwise
53 ******************************************************************************/
57 sal_Int32 nKeyInc
= 0;
58 if (m_nIdOfKeyEC
!= 0)
65 m_nTotalReferenceNumber
== -1 ||
66 m_nTotalReferenceNumber
+1+nKeyInc
> m_nNumOfResolvedReferences
)
74 void SignatureEngine::tryToPerform( )
75 /****** SignatureEngine/tryToPerform *****************************************
78 * tryToPerform -- tries to perform the signature operation.
81 * if the situation is ready, perform following operations.
82 * 1. prepares a signature template;
83 * 2. calls the signature bridge component;
84 * 3. clears up all used resources;
85 * 4. notifies the result listener;
86 * 5. sets the "accomplishment" flag.
87 ******************************************************************************/
92 rtl::Reference
<XMLSignatureTemplateImpl
> xSignatureTemplate
= new XMLSignatureTemplateImpl();
94 css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
>
95 xXMLElement
= m_xSAXEventKeeper
->getElement( m_nIdOfTemplateEC
);
97 xSignatureTemplate
->setTemplate(xXMLElement
);
99 for( const auto i
: m_vReferenceIds
)
101 xXMLElement
= m_xSAXEventKeeper
->getElement( i
);
102 xSignatureTemplate
->setTarget(xXMLElement
);
106 * set the Uri binding
108 xSignatureTemplate
->setBinding( this );
110 startEngine(xSignatureTemplate
);
117 notifyResultListener();
119 m_bMissionDone
= true;
122 void SignatureEngine::clearUp( ) const
123 /****** SignatureEngine/clearUp **********************************************
126 * clearUp -- clear up all resources used by this operation.
129 * cleaning resources up includes:
130 * 1. releases the ElementCollector for the signature template element;
131 * 2. releases ElementCollectors for referenced elements;
132 * 3. releases the ElementCollector for the key element, if there is one.
133 ******************************************************************************/
135 css::uno::Reference
< css::xml::crypto::sax::XReferenceResolvedBroadcaster
>
136 xReferenceResolvedBroadcaster( m_xSAXEventKeeper
, css::uno::UNO_QUERY
);
137 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
139 static_cast<const css::uno::Reference
< css::xml::crypto::sax::XReferenceResolvedListener
> >(static_cast<SecurityEngine
*>(const_cast<SignatureEngine
*>(this))));
141 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfTemplateEC
);
143 for( const auto& i
: m_vReferenceIds
)
145 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
147 static_cast<const css::uno::Reference
< css::xml::crypto::sax::XReferenceResolvedListener
> >(static_cast<SecurityEngine
*>(const_cast<SignatureEngine
*>(this))));
148 m_xSAXEventKeeper
->removeElementCollector(i
);
151 if (m_nIdOfKeyEC
!= 0 && m_nIdOfKeyEC
!= -1)
153 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfKeyEC
);
157 /* XReferenceCollector */
158 void SAL_CALL
SignatureEngine::setReferenceCount( sal_Int32 count
)
160 m_nTotalReferenceNumber
= count
;
164 void SAL_CALL
SignatureEngine::setReferenceId( sal_Int32 id
)
166 m_vReferenceIds
.push_back( id
);
170 void SAL_CALL
SignatureEngine::setUriBinding(
172 const css::uno::Reference
< css::io::XInputStream
>& aInputStream
)
174 m_vUris
.push_back(uri
);
175 m_vXInputStreams
.push_back(aInputStream
);
178 css::uno::Reference
< css::io::XInputStream
> SAL_CALL
SignatureEngine::getUriBinding( const OUString
& uri
)
180 css::uno::Reference
< css::io::XInputStream
> xInputStream
;
182 int size
= m_vUris
.size();
184 for( int i
=0; i
<size
; ++i
)
186 if (m_vUris
[i
] == uri
)
188 xInputStream
= m_vXInputStreams
[i
];
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */