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/signaturecreatorimpl.hxx>
22 #include <framework/xmlsignaturetemplateimpl.hxx>
23 #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <osl/diagnose.h>
26 #include <rtl/ref.hxx>
28 namespace com::sun::star::xml::wrapper
{ class XXMLElementWrapper
; }
30 using namespace com::sun::star::uno
;
32 SignatureCreatorImpl::SignatureCreatorImpl()
37 SignatureCreatorImpl::~SignatureCreatorImpl( )
41 void SignatureCreatorImpl::notifyResultListener() const
42 /****** SignatureCreatorImpl/notifyResultListener *****************************
45 * notifyResultListener -- notifies the listener about the signature
47 ******************************************************************************/
49 css::uno::Reference
< css::xml::crypto::sax::XSignatureCreationResultListener
>
50 xSignatureCreationResultListener ( m_xResultListener
, css::uno::UNO_QUERY
) ;
52 xSignatureCreationResultListener
->signatureCreated( m_nSecurityId
, m_nStatus
);
55 void SignatureCreatorImpl::startEngine(const rtl::Reference
<XMLSignatureTemplateImpl
>& xSignatureTemplate
)
56 /****** SignatureCreatorImpl/startEngine *************************************
59 * startEngine -- generates the signature.
62 * generates the signature element, then if succeeds, updates the link
63 * of old template element to the new signature element in
67 * xSignatureTemplate - the signature template (along with all referenced
68 * elements) to be signed.
69 ******************************************************************************/
71 css::uno::Reference
< css::xml::crypto::XXMLSignatureTemplate
> xResultTemplate
;
74 xResultTemplate
= m_xXMLSignature
->generate(css::uno::Reference
<css::xml::crypto::XXMLSignatureTemplate
>(xSignatureTemplate
), m_xSecurityEnvironment
);
75 m_nStatus
= xResultTemplate
->getStatus();
77 catch( css::uno::Exception
& )
79 m_nStatus
= css::xml::crypto::SecurityOperationStatus_RUNTIMEERROR_FAILED
;
82 if (m_nStatus
== css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED
)
84 css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
> xResultSignature
= xResultTemplate
->getTemplate();
85 m_xSAXEventKeeper
->setElement(m_nIdOfTemplateEC
, xResultSignature
);
89 void SignatureCreatorImpl::clearUp() const
90 /****** SignatureCreatorImpl/clearUp *****************************************
93 * clearUp -- clear up all resources used by the signature generation.
99 * cleaning resources up includes:
100 * 1. SignatureEngine's clearing up;
101 * 2. releases the Blocker for the signature template element.
102 ******************************************************************************/
104 SignatureEngine::clearUp();
106 if (m_nIdOfBlocker
!= -1)
108 m_xSAXEventKeeper
->removeBlocker(m_nIdOfBlocker
);
112 /* XBlockerMonitor */
113 void SAL_CALL
SignatureCreatorImpl::setBlockerId( sal_Int32 id
)
119 /* XSignatureCreationResultBroadcaster */
120 void SAL_CALL
SignatureCreatorImpl::addSignatureCreationResultListener(
121 const css::uno::Reference
< css::xml::crypto::sax::XSignatureCreationResultListener
>& listener
)
123 m_xResultListener
= listener
;
127 void SAL_CALL
SignatureCreatorImpl::removeSignatureCreationResultListener(
128 const css::uno::Reference
< css::xml::crypto::sax::XSignatureCreationResultListener
>&)
132 /* XInitialization */
133 void SAL_CALL
SignatureCreatorImpl::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
135 OSL_ASSERT(aArguments
.getLength() == 5);
137 OUString ouTempString
;
139 aArguments
[0] >>= ouTempString
;
140 m_nSecurityId
= ouTempString
.toInt32();
141 aArguments
[1] >>= m_xSAXEventKeeper
;
142 aArguments
[2] >>= ouTempString
;
143 m_nIdOfTemplateEC
= ouTempString
.toInt32();
144 aArguments
[3] >>= m_xSecurityEnvironment
;
145 aArguments
[4] >>= m_xXMLSignature
;
149 OUString
SignatureCreatorImpl_getImplementationName ()
151 return u
"com.sun.star.xml.security.framework.SignatureCreatorImpl"_ustr
;
154 css::uno::Sequence
< OUString
> SignatureCreatorImpl_getSupportedServiceNames( )
156 return { u
"com.sun.star.xml.crypto.sax.SignatureCreator"_ustr
};
160 OUString SAL_CALL
SignatureCreatorImpl::getImplementationName( )
162 return SignatureCreatorImpl_getImplementationName();
165 sal_Bool SAL_CALL
SignatureCreatorImpl::supportsService( const OUString
& rServiceName
)
167 return cppu::supportsService(this, rServiceName
);
170 css::uno::Sequence
< OUString
> SAL_CALL
SignatureCreatorImpl::getSupportedServiceNames( )
172 return SignatureCreatorImpl_getSupportedServiceNames();
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */