LCOV - code coverage report
Current view: top level - xmlsecurity/source/framework - signaturecreatorimpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 18 64 28.1 %
Date: 2015-06-13 12:38:46 Functions: 8 17 47.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include "signaturecreatorimpl.hxx"
      22             : #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
      23             : #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : #include <osl/diagnose.h>
      28             : 
      29             : using namespace com::sun::star::uno;
      30             : namespace cssu = com::sun::star::uno;
      31             : namespace cssl = com::sun::star::lang;
      32             : namespace cssxc = com::sun::star::xml::crypto;
      33             : namespace cssxw = com::sun::star::xml::wrapper;
      34             : 
      35             : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
      36             : 
      37           1 : SignatureCreatorImpl::SignatureCreatorImpl( const Reference<XComponentContext> & xContext )
      38           1 :     : SignatureCreatorImpl_Base(xContext), m_nIdOfBlocker(-1)
      39             : {
      40           1 : }
      41             : 
      42           2 : SignatureCreatorImpl::~SignatureCreatorImpl( )
      43             : {
      44           2 : }
      45             : 
      46           0 : bool SignatureCreatorImpl::checkReady() const
      47             : /****** SignatureCreatorImpl/checkReady **************************************
      48             :  *
      49             :  *   NAME
      50             :  *  checkReady -- checks the conditions for the signature generation.
      51             :  *
      52             :  *   SYNOPSIS
      53             :  *  bReady = checkReady( );
      54             :  *
      55             :  *   FUNCTION
      56             :  *  checks whether all following conditions are satisfied:
      57             :  *  1. the result listener is ready;
      58             :  *  2. the id of the template blocker is known;
      59             :  *  3. the SignatureEngine is ready.
      60             :  *
      61             :  *   INPUTS
      62             :  *  empty
      63             :  *
      64             :  *   RESULT
      65             :  *  bReady - true if all conditions are satisfied, false otherwise
      66             :  *
      67             :  *   AUTHOR
      68             :  *  Michael Mi
      69             :  *  Email: michael.mi@sun.com
      70             :  ******************************************************************************/
      71             : {
      72           0 :     return (m_xResultListener.is() &&
      73           0 :             (m_nIdOfBlocker != -1) &&
      74           0 :             SignatureEngine::checkReady());
      75             : }
      76             : 
      77           0 : void SignatureCreatorImpl::notifyResultListener() const
      78             :     throw (cssu::Exception, cssu::RuntimeException)
      79             : /****** SignatureCreatorImpl/notifyResultListener *****************************
      80             :  *
      81             :  *   NAME
      82             :  *  notifyResultListener -- notifies the listener about the signature
      83             :  *  creation result.
      84             :  *
      85             :  *   SYNOPSIS
      86             :  *  notifyResultListener( );
      87             :  *
      88             :  *   FUNCTION
      89             :  *  see NAME.
      90             :  *
      91             :  *   INPUTS
      92             :  *  empty
      93             :  *
      94             :  *   RESULT
      95             :  *  empty
      96             :  *
      97             :  *   AUTHOR
      98             :  *  Michael Mi
      99             :  *  Email: michael.mi@sun.com
     100             :  ******************************************************************************/
     101             : {
     102             :     cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
     103           0 :         xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
     104             : 
     105           0 :     xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
     106           0 : }
     107             : 
     108           0 : void SignatureCreatorImpl::startEngine( const cssu::Reference<
     109             :     cssxc::XXMLSignatureTemplate >&
     110             :     xSignatureTemplate)
     111             :         throw (cssu::Exception, cssu::RuntimeException)
     112             : /****** SignatureCreatorImpl/startEngine *************************************
     113             :  *
     114             :  *   NAME
     115             :  *  startEngine -- generates the signature.
     116             :  *
     117             :  *   SYNOPSIS
     118             :  *  startEngine( xSignatureTemplate );
     119             :  *
     120             :  *   FUNCTION
     121             :  *  generates the signature element, then if succeeds, updates the link
     122             :  *  of old template element to the new signature element in
     123             :  *  SAXEventKeeper.
     124             :  *
     125             :  *   INPUTS
     126             :  *  xSignatureTemplate - the signature template (along with all referenced
     127             :  *  elements) to be signed.
     128             :  *
     129             :  *   RESULT
     130             :  *  empty
     131             :  *
     132             :  *   AUTHOR
     133             :  *  Michael Mi
     134             :  *  Email: michael.mi@sun.com
     135             :  ******************************************************************************/
     136             : {
     137           0 :     cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
     138             :     try
     139             :     {
     140           0 :         xResultTemplate = m_xXMLSignature->generate(xSignatureTemplate, m_xSecurityEnvironment);
     141           0 :         m_nStatus = xResultTemplate->getStatus();
     142             :     }
     143           0 :     catch( cssu::Exception& )
     144             :     {
     145           0 :         m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
     146             :     }
     147             : 
     148           0 :     if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
     149             :     {
     150           0 :         cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
     151           0 :         m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
     152           0 :     }
     153           0 : }
     154             : 
     155           0 : void SignatureCreatorImpl::clearUp() const
     156             : /****** SignatureCreatorImpl/clearUp *****************************************
     157             :  *
     158             :  *   NAME
     159             :  *  clearUp -- clear up all resources used by the signature generation.
     160             :  *
     161             :  *   SYNOPSIS
     162             :  *  clearUp( );
     163             :  *
     164             :  *   FUNCTION
     165             :  *  cleaning resources up includes:
     166             :  *  1. SignatureEngine's clearing up;
     167             :  *  2. releases the Blocker for the signature template element.
     168             :  *
     169             :  *   INPUTS
     170             :  *  empty
     171             :  *
     172             :  *   RESULT
     173             :  *  empty
     174             :  *
     175             :  *   AUTHOR
     176             :  *  Michael Mi
     177             :  *  Email: michael.mi@sun.com
     178             :  ******************************************************************************/
     179             : {
     180           0 :     SignatureEngine::clearUp();
     181             : 
     182           0 :     if (m_nIdOfBlocker != -1)
     183             :     {
     184           0 :         m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
     185             :     }
     186           0 : }
     187             : 
     188             : /* XBlockerMonitor */
     189           0 : void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
     190             :         throw (cssu::Exception, cssu::RuntimeException, std::exception)
     191             : {
     192           0 :     m_nIdOfBlocker = id;
     193           0 :     tryToPerform();
     194           0 : }
     195             : 
     196             : /* XSignatureCreationResultBroadcaster */
     197           0 : void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
     198             :     const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
     199             :     throw (cssu::Exception, cssu::RuntimeException, std::exception)
     200             : {
     201           0 :     m_xResultListener = listener;
     202           0 :     tryToPerform();
     203           0 : }
     204             : 
     205           0 : void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
     206             :     const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >&)
     207             :     throw (cssu::RuntimeException, std::exception)
     208             : {
     209           0 : }
     210             : 
     211             : /* XInitialization */
     212           0 : void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
     213             :     throw (cssu::Exception, cssu::RuntimeException, std::exception)
     214             : {
     215             :     OSL_ASSERT(aArguments.getLength() == 5);
     216             : 
     217           0 :     OUString ouTempString;
     218             : 
     219           0 :     aArguments[0] >>= ouTempString;
     220           0 :     m_nSecurityId = ouTempString.toInt32();
     221           0 :     aArguments[1] >>= m_xSAXEventKeeper;
     222           0 :     aArguments[2] >>= ouTempString;
     223           0 :     m_nIdOfTemplateEC = ouTempString.toInt32();
     224           0 :     aArguments[3] >>= m_xSecurityEnvironment;
     225           0 :     aArguments[4] >>= m_xXMLSignature;
     226           0 : }
     227             : 
     228             : 
     229           8 : OUString SignatureCreatorImpl_getImplementationName ()
     230             :     throw (cssu::RuntimeException)
     231             : {
     232           8 :     return OUString ( IMPLEMENTATION_NAME );
     233             : }
     234             : 
     235           2 : cssu::Sequence< OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames(  )
     236             :     throw (cssu::RuntimeException)
     237             : {
     238           2 :     cssu::Sequence < OUString > aRet(1);
     239           2 :     OUString* pArray = aRet.getArray();
     240           2 :     pArray[0] = "com.sun.star.xml.crypto.sax.SignatureCreator";
     241           2 :     return aRet;
     242             : }
     243             : 
     244           1 : cssu::Reference< cssu::XInterface > SAL_CALL SignatureCreatorImpl_createInstance(
     245             :     const cssu::Reference< cssl::XMultiServiceFactory >& xMSF )
     246             :     throw( cssu::Exception )
     247             : {
     248           1 :     return static_cast<cppu::OWeakObject*>(new SignatureCreatorImpl( comphelper::getComponentContext( xMSF ) ));
     249             : }
     250             : 
     251             : /* XServiceInfo */
     252           1 : OUString SAL_CALL SignatureCreatorImpl::getImplementationName(  )
     253             :     throw (cssu::RuntimeException, std::exception)
     254             : {
     255           1 :     return SignatureCreatorImpl_getImplementationName();
     256             : }
     257             : 
     258           0 : sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const OUString& rServiceName )
     259             :     throw (cssu::RuntimeException, std::exception)
     260             : {
     261           0 :     return cppu::supportsService(this, rServiceName);
     262             : }
     263             : 
     264           1 : cssu::Sequence< OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames(  )
     265             :     throw (cssu::RuntimeException, std::exception)
     266             : {
     267           1 :     return SignatureCreatorImpl_getSupportedServiceNames();
     268             : }
     269             : 
     270             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11