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

Generated by: LCOV version 1.10