LCOV - code coverage report
Current view: top level - libreoffice/xmlsecurity/source/framework - signatureengine.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 61 0.0 %
Date: 2012-12-27 Functions: 0 8 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 "signatureengine.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 SIGNATURE_TEMPLATE "com.sun.star.xml.crypto.XMLSignatureTemplate"
      32             : 
      33           0 : SignatureEngine::SignatureEngine( )
      34           0 :     :m_nTotalReferenceNumber(-1)
      35             : {
      36           0 : }
      37             : 
      38           0 : bool SignatureEngine::checkReady() const
      39             : /****** SignatureEngine/checkReady *******************************************
      40             :  *
      41             :  *   NAME
      42             :  *  checkReady -- checks the conditions for the main operation.
      43             :  *
      44             :  *   SYNOPSIS
      45             :  *  bReady = checkReady( );
      46             :  *
      47             :  *   FUNCTION
      48             :  *  checks whether all following conditions are satisfied:
      49             :  *  1. the main operation has't begun yet;
      50             :  *  2. the key material is known;
      51             :  *  3. the amount of reference is known;
      52             :  *  4. all of referenced elements, the key element and the signature
      53             :  *     template are bufferred.
      54             :  *
      55             :  *   INPUTS
      56             :  *  empty
      57             :  *
      58             :  *   RESULT
      59             :  *  bReady - true if all conditions are satisfied, false otherwise
      60             :  *
      61             :  *   AUTHOR
      62             :  *  Michael Mi
      63             :  *  Email: michael.mi@sun.com
      64             :  ******************************************************************************/
      65             : {
      66           0 :     bool rc = true;
      67             : 
      68           0 :     sal_Int32 nKeyInc = 0;
      69           0 :     if (m_nIdOfKeyEC != 0)
      70             :     {
      71           0 :         nKeyInc = 1;
      72             :     }
      73             : 
      74           0 :     if (m_bMissionDone ||
      75             :         m_nIdOfKeyEC == -1 ||
      76             :         m_nTotalReferenceNumber == -1 ||
      77             :         m_nTotalReferenceNumber+1+nKeyInc > m_nNumOfResolvedReferences)
      78             :     {
      79           0 :         rc = false;
      80             :     }
      81             : 
      82           0 :     return rc;
      83             : }
      84             : 
      85           0 : void SignatureEngine::tryToPerform( )
      86             :         throw (cssu::Exception, cssu::RuntimeException)
      87             : /****** SignatureEngine/tryToPerform *****************************************
      88             :  *
      89             :  *   NAME
      90             :  *  tryToPerform -- tries to perform the signature operation.
      91             :  *
      92             :  *   SYNOPSIS
      93             :  *  tryToPerform( );
      94             :  *
      95             :  *   FUNCTION
      96             :  *  if the situation is ready, perform following operations.
      97             :  *  1. prepares a signature template;
      98             :  *  2. calls the signature bridge component;
      99             :  *  3. clears up all used resources;
     100             :  *  4. notifies the result listener;
     101             :  *  5. sets the "accomplishment" flag.
     102             :  *
     103             :  *   INPUTS
     104             :  *  empty
     105             :  *
     106             :  *   RESULT
     107             :  *  empty
     108             :  *
     109             :  *   AUTHOR
     110             :  *  Michael Mi
     111             :  *  Email: michael.mi@sun.com
     112             :  ******************************************************************************/
     113             : {
     114           0 :     if (checkReady())
     115             :     {
     116             :         const rtl::OUString ouSignatureTemplate (
     117           0 :             RTL_CONSTASCII_USTRINGPARAM( SIGNATURE_TEMPLATE ) );
     118             :         cssu::Reference < cssxc::XXMLSignatureTemplate >
     119           0 :             xSignatureTemplate( mxMSF->createInstance( ouSignatureTemplate ), cssu::UNO_QUERY );
     120             : 
     121             :         OSL_ASSERT( xSignatureTemplate.is() );
     122             : 
     123             :         cssu::Reference< cssxw::XXMLElementWrapper >
     124           0 :             xXMLElement = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC );
     125             : 
     126           0 :         xSignatureTemplate->setTemplate(xXMLElement);
     127             : 
     128           0 :         std::vector< sal_Int32 >::const_iterator ii = m_vReferenceIds.begin();
     129             : 
     130           0 :         for( ; ii != m_vReferenceIds.end() ; ++ii )
     131             :         {
     132           0 :             xXMLElement = m_xSAXEventKeeper->getElement( *ii );
     133           0 :             xSignatureTemplate->setTarget(xXMLElement);
     134             :         }
     135             : 
     136             :         /*
     137             :          * set the Uri binding
     138             :          */
     139           0 :         xSignatureTemplate->setBinding( this );
     140             : 
     141           0 :         startEngine( xSignatureTemplate );
     142             : 
     143             :         /*
     144             :          * done
     145             :          */
     146           0 :         clearUp( );
     147             : 
     148           0 :         notifyResultListener();
     149             : 
     150           0 :         m_bMissionDone = true;
     151             :     }
     152           0 : }
     153             : 
     154           0 : void SignatureEngine::clearUp( ) const
     155             : /****** SignatureEngine/clearUp **********************************************
     156             :  *
     157             :  *   NAME
     158             :  *  clearUp -- clear up all resources used by this operation.
     159             :  *
     160             :  *   SYNOPSIS
     161             :  *  clearUp( );
     162             :  *
     163             :  *   FUNCTION
     164             :  *  cleaning resources up includes:
     165             :  *  1. releases the ElementCollector for the signature template element;
     166             :  *  2. releases ElementCollectors for referenced elements;
     167             :  *  3. releases the ElementCollector for the key element, if there is one.
     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             :     cssu::Reference < cssxc::sax::XReferenceResolvedBroadcaster >
     181           0 :         xReferenceResolvedBroadcaster( m_xSAXEventKeeper, cssu::UNO_QUERY );
     182           0 :     xReferenceResolvedBroadcaster->removeReferenceResolvedListener(
     183             :         m_nIdOfTemplateEC,
     184           0 :         (const cssu::Reference < cssxc::sax::XReferenceResolvedListener >)((SecurityEngine *)this));
     185             : 
     186           0 :     m_xSAXEventKeeper->removeElementCollector(m_nIdOfTemplateEC);
     187             : 
     188           0 :     std::vector< sal_Int32 >::const_iterator ii = m_vReferenceIds.begin();
     189             : 
     190           0 :     for( ; ii != m_vReferenceIds.end() ; ++ii )
     191             :     {
     192           0 :         xReferenceResolvedBroadcaster->removeReferenceResolvedListener(
     193           0 :             *ii,
     194           0 :             (const cssu::Reference < cssxc::sax::XReferenceResolvedListener >)((SecurityEngine *)this));
     195           0 :         m_xSAXEventKeeper->removeElementCollector(*ii);
     196             :     }
     197             : 
     198           0 :     if (m_nIdOfKeyEC != 0 && m_nIdOfKeyEC != -1)
     199             :     {
     200           0 :         m_xSAXEventKeeper->removeElementCollector(m_nIdOfKeyEC);
     201           0 :     }
     202           0 : }
     203             : 
     204             : /* XReferenceCollector */
     205           0 : void SAL_CALL SignatureEngine::setReferenceCount( sal_Int32 count )
     206             :     throw (cssu::Exception, cssu::RuntimeException)
     207             : {
     208           0 :     m_nTotalReferenceNumber = count;
     209           0 :     tryToPerform();
     210           0 : }
     211             : 
     212           0 : void SAL_CALL SignatureEngine::setReferenceId( sal_Int32 id )
     213             :     throw (cssu::Exception, cssu::RuntimeException)
     214             : {
     215           0 :     m_vReferenceIds.push_back( id );
     216           0 : }
     217             : 
     218             : /* XUriBinding */
     219           0 : void SAL_CALL SignatureEngine::setUriBinding(
     220             :     const rtl::OUString& uri,
     221             :     const cssu::Reference< com::sun::star::io::XInputStream >& aInputStream )
     222             :     throw (cssu::Exception, cssu::RuntimeException)
     223             : {
     224           0 :     m_vUris.push_back(uri);
     225           0 :     m_vXInputStreams.push_back(aInputStream);
     226           0 : }
     227             : 
     228           0 : cssu::Reference< com::sun::star::io::XInputStream > SAL_CALL SignatureEngine::getUriBinding( const rtl::OUString& uri )
     229             :     throw (cssu::Exception, cssu::RuntimeException)
     230             : {
     231           0 :     cssu::Reference< com::sun::star::io::XInputStream > xInputStream;
     232             : 
     233           0 :     int size = m_vUris.size();
     234             : 
     235           0 :     for( int i=0; i<size; ++i)
     236             :     {
     237           0 :         if (m_vUris[i] == uri)
     238             :         {
     239           0 :             xInputStream = m_vXInputStreams[i];
     240           0 :             break;
     241             :         }
     242             :     }
     243             : 
     244           0 :     return xInputStream;
     245             : }
     246             : 
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10