LCOV - code coverage report
Current view: top level - xmlsecurity/source/framework - encryptionengine.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 39 0.0 %
Date: 2014-04-14 Functions: 0 5 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 "encryptionengine.hxx"
      22             : #include <com/sun/star/xml/crypto/XMLEncryptionTemplate.hpp>
      23             : #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : 
      26             : using namespace com::sun::star::uno;
      27             : namespace cssxc = com::sun::star::xml::crypto;
      28             : namespace cssxw = com::sun::star::xml::wrapper;
      29             : 
      30           0 : EncryptionEngine::EncryptionEngine( const Reference<XComponentContext> & xContext)
      31           0 :         :m_xContext(xContext), m_nIdOfBlocker(-1)
      32             : {
      33           0 : }
      34             : 
      35           0 : bool EncryptionEngine::checkReady() const
      36             : /****** EncryptionEngine/checkReady ******************************************
      37             :  *
      38             :  *   NAME
      39             :  *  checkReady -- checks the conditions for the main operation.
      40             :  *
      41             :  *   SYNOPSIS
      42             :  *  bReady = checkReady( );
      43             :  *
      44             :  *   FUNCTION
      45             :  *  checks whether all following conditions are satisfied:
      46             :  *  1. the main operation has't begun yet;
      47             :  *  2. the key material is known;
      48             :  *  3. the id of the template blocker is known;
      49             :  *  4. both the key element and the encryption template
      50             :  *     are bufferred.
      51             :  *
      52             :  *   INPUTS
      53             :  *  empty
      54             :  *
      55             :  *   RESULT
      56             :  *  bReady - true if all conditions are satisfied, false otherwise
      57             :  *
      58             :  *   AUTHOR
      59             :  *  Michael Mi
      60             :  *  Email: michael.mi@sun.com
      61             :  ******************************************************************************/
      62             : {
      63           0 :     bool rc = true;
      64             : 
      65           0 :     sal_Int32 nKeyInc = 0;
      66           0 :     if (m_nIdOfKeyEC != 0)
      67             :     {
      68           0 :         nKeyInc = 1;
      69             :     }
      70             : 
      71           0 :     if (m_bMissionDone ||
      72           0 :         m_nIdOfKeyEC == -1 ||
      73           0 :         m_nIdOfBlocker == -1 ||
      74           0 :         1+nKeyInc > m_nNumOfResolvedReferences )
      75             :     {
      76           0 :         rc = false;
      77             :     }
      78             : 
      79           0 :     return rc;
      80             : }
      81             : 
      82           0 : void EncryptionEngine::tryToPerform( )
      83             :         throw (Exception, RuntimeException)
      84             : /****** EncryptionEngine/tryToPerform ****************************************
      85             :  *
      86             :  *   NAME
      87             :  *  tryToPerform -- tries to perform the encryption/decryption operation.
      88             :  *
      89             :  *   SYNOPSIS
      90             :  *  tryToPerform( );
      91             :  *
      92             :  *   FUNCTION
      93             :  *  if the situation is ready, perform following operations.
      94             :  *  1. prepares a encryption template;
      95             :  *  2. calls the encryption bridge component;
      96             :  *  3. clears up all used resources;
      97             :  *  4. notifies the result listener;
      98             :  *  5. sets the "accomplishment" flag.
      99             :  *
     100             :  *   INPUTS
     101             :  *  empty
     102             :  *
     103             :  *   RESULT
     104             :  *  empty
     105             :  *
     106             :  *   AUTHOR
     107             :  *  Michael Mi
     108             :  *  Email: michael.mi@sun.com
     109             :  ******************************************************************************/
     110             : {
     111           0 :     if (checkReady())
     112             :     {
     113             :         Reference < cssxc::XXMLEncryptionTemplate > xEncryptionTemplate =
     114           0 :             cssxc::XMLEncryptionTemplate::create( m_xContext );
     115             : 
     116             :         Reference< cssxw::XXMLElementWrapper > xXMLElement
     117           0 :             = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC );
     118             : 
     119           0 :         xEncryptionTemplate->setTemplate(xXMLElement);
     120             : 
     121           0 :         startEngine( xEncryptionTemplate );
     122             : 
     123             :         /*
     124             :          * done
     125             :          */
     126           0 :         clearUp( );
     127             : 
     128           0 :         notifyResultListener();
     129             : 
     130           0 :         m_bMissionDone = true;
     131             :     }
     132           0 : }
     133             : 
     134           0 : void EncryptionEngine::clearUp( ) const
     135             : /****** EncryptionEngine/clearup *********************************************
     136             :  *
     137             :  *   NAME
     138             :  *  clearUp -- clear up all resources used by this operation.
     139             :  *
     140             :  *   SYNOPSIS
     141             :  *  clearUp( );
     142             :  *
     143             :  *   FUNCTION
     144             :  *  cleaning resources up includes:
     145             :  *  1. releases the ElementCollector for the encryption template element;
     146             :  *  2. releases the Blocker for the encryption template element;
     147             :  *  3. releases the ElementCollector for the key element, if there is one.
     148             :  *
     149             :  *   INPUTS
     150             :  *  empty
     151             :  *
     152             :  *   RESULT
     153             :  *  empty
     154             :  *
     155             :  *   AUTHOR
     156             :  *  Michael Mi
     157             :  *  Email: michael.mi@sun.com
     158             :  ******************************************************************************/
     159             : {
     160             :     Reference < cssxc::sax::XReferenceResolvedBroadcaster >
     161           0 :         xReferenceResolvedBroadcaster( m_xSAXEventKeeper, UNO_QUERY );
     162             : 
     163           0 :     xReferenceResolvedBroadcaster->removeReferenceResolvedListener(
     164             :         m_nIdOfTemplateEC,
     165           0 :         (const Reference < cssxc::sax::XReferenceResolvedListener >)((SecurityEngine *)this));
     166             : 
     167           0 :     m_xSAXEventKeeper->removeElementCollector(m_nIdOfTemplateEC);
     168             : 
     169           0 :     if (m_nIdOfBlocker != -1)
     170             :     {
     171           0 :         m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
     172             :     }
     173             : 
     174           0 :     if (m_nIdOfKeyEC != 0 && m_nIdOfKeyEC != -1)
     175             :     {
     176           0 :         m_xSAXEventKeeper->removeElementCollector(m_nIdOfKeyEC);
     177           0 :     }
     178           0 : }
     179             : 
     180             : /* XBlockerMonitor */
     181           0 : void SAL_CALL EncryptionEngine::setBlockerId( sal_Int32 id )
     182             :     throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException, std::exception)
     183             : {
     184           0 :     m_nIdOfBlocker = id;
     185           0 :     tryToPerform();
     186           0 : }
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10