LCOV - code coverage report
Current view: top level - xmlsecurity/source/framework - encryptorimpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 69 0.0 %
Date: 2012-08-25 Functions: 0 18 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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 "encryptorimpl.hxx"
      22                 :            : #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.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.Encryptor"
      32                 :            : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.EncryptorImpl"
      33                 :            : 
      34                 :          0 : EncryptorImpl::EncryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
      35                 :            : {
      36                 :          0 :     m_nReferenceId = -1;
      37                 :          0 :     mxMSF = rxMSF;
      38                 :          0 : }
      39                 :            : 
      40                 :          0 : EncryptorImpl::~EncryptorImpl()
      41                 :            : {
      42                 :          0 : }
      43                 :            : 
      44                 :          0 : bool EncryptorImpl::checkReady() const
      45                 :            : /****** EncryptorImpl/checkReady *********************************************
      46                 :            :  *
      47                 :            :  *   NAME
      48                 :            :  *  checkReady -- checks the conditions for the encryption.
      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 EncryptionEngine is ready.
      57                 :            :  *
      58                 :            :  *   INPUTS
      59                 :            :  *  empty
      60                 :            :  *
      61                 :            :  *   RESULT
      62                 :            :  *  bReady - true if all conditions are satisfied, false otherwise
      63                 :            :  *
      64                 :            :  *   AUTHOR
      65                 :            :  *  Michael Mi
      66                 :            :  *  Email: michael.mi@sun.com
      67                 :            :  ******************************************************************************/
      68                 :            : {
      69                 :          0 :     sal_Int32 nKeyInc = 0;
      70                 :          0 :     if (m_nIdOfKeyEC != 0)
      71                 :            :     {
      72                 :          0 :         nKeyInc = 1;
      73                 :            :     }
      74                 :            : 
      75                 :          0 :     return (m_xResultListener.is() &&
      76                 :            :         (m_nReferenceId != -1) &&
      77                 :            :         (2+nKeyInc == m_nNumOfResolvedReferences) &&
      78                 :          0 :         EncryptionEngine::checkReady());
      79                 :            : }
      80                 :            : 
      81                 :          0 : void EncryptorImpl::notifyResultListener() const
      82                 :            :     throw (cssu::Exception, cssu::RuntimeException)
      83                 :            : /****** DecryptorImpl/notifyResultListener ***********************************
      84                 :            :  *
      85                 :            :  *   NAME
      86                 :            :  *  notifyResultListener -- notifies the listener about the encryption
      87                 :            :  *  result.
      88                 :            :  *
      89                 :            :  *   SYNOPSIS
      90                 :            :  *  notifyResultListener( );
      91                 :            :  *
      92                 :            :  *   FUNCTION
      93                 :            :  *  see NAME.
      94                 :            :  *
      95                 :            :  *   INPUTS
      96                 :            :  *  empty
      97                 :            :  *
      98                 :            :  *   RESULT
      99                 :            :  *  empty
     100                 :            :  *
     101                 :            :  *   AUTHOR
     102                 :            :  *  Michael Mi
     103                 :            :  *  Email: michael.mi@sun.com
     104                 :            :  ******************************************************************************/
     105                 :            : {
     106                 :            :     cssu::Reference< cssxc::sax::XEncryptionResultListener >
     107                 :          0 :         xEncryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
     108                 :            : 
     109                 :          0 :     xEncryptionResultListener->encrypted( m_nSecurityId, m_nStatus );
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : void EncryptorImpl::startEngine( const cssu::Reference<
     113                 :            :     cssxc::XXMLEncryptionTemplate >&
     114                 :            :     xEncryptionTemplate)
     115                 :            :         throw (cssu::Exception, cssu::RuntimeException)
     116                 :            : /****** EncryptorImpl/startEngine ********************************************
     117                 :            :  *
     118                 :            :  *   NAME
     119                 :            :  *  startEngine -- generates the encryption.
     120                 :            :  *
     121                 :            :  *   SYNOPSIS
     122                 :            :  *  startEngine( xEncryptionTemplate );
     123                 :            :  *
     124                 :            :  *   FUNCTION
     125                 :            :  *  generates the encryption element, then if succeeds, updates the link
     126                 :            :  *  of old template element to the new encryption element in
     127                 :            :  *  SAXEventKeeper.
     128                 :            :  *
     129                 :            :  *   INPUTS
     130                 :            :  *  xEncryptionTemplate - the encryption template to be encrypted.
     131                 :            :  *
     132                 :            :  *   RESULT
     133                 :            :  *  empty
     134                 :            :  *
     135                 :            :  *   AUTHOR
     136                 :            :  *  Michael Mi
     137                 :            :  *  Email: michael.mi@sun.com
     138                 :            :  ******************************************************************************/
     139                 :            : {
     140                 :          0 :     cssu::Reference < cssxc::XXMLEncryptionTemplate > xResultTemplate;
     141                 :            : 
     142                 :            :     cssu::Reference< cssxw::XXMLElementWrapper >
     143                 :          0 :         xXMLElement = m_xSAXEventKeeper->getElement( m_nReferenceId );
     144                 :          0 :     xEncryptionTemplate->setTarget(xXMLElement);
     145                 :            : 
     146                 :            :     try
     147                 :            :     {
     148                 :          0 :         xResultTemplate = m_xXMLEncryption->encrypt(
     149                 :          0 :             xEncryptionTemplate, m_xSecurityEnvironment);
     150                 :          0 :         m_nStatus = xResultTemplate->getStatus();
     151                 :            :     }
     152                 :          0 :     catch( cssu::Exception& )
     153                 :            :     {
     154                 :          0 :         m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
     155                 :            :     }
     156                 :            : 
     157                 :          0 :     if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
     158                 :            :     {
     159                 :            :         cssu::Reference < cssxw::XXMLElementWrapper > xResultEncryption
     160                 :          0 :             = xResultTemplate->getTemplate();
     161                 :          0 :         m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultEncryption);
     162                 :          0 :         m_xSAXEventKeeper->setElement(m_nReferenceId, NULL);
     163                 :          0 :     }
     164                 :          0 : }
     165                 :            : 
     166                 :            : /* XReferenceCollector */
     167                 :          0 : void SAL_CALL EncryptorImpl::setReferenceCount(sal_Int32)
     168                 :            :     throw (cssu::Exception, cssu::RuntimeException)
     169                 :            : {
     170                 :            :     /*
     171                 :            :      * dummp method, because there is only one reference in
     172                 :            :      * encryption, different from signature.
     173                 :            :      * so the referenceNumber is always 1
     174                 :            :      */
     175                 :          0 : }
     176                 :            : 
     177                 :          0 : void SAL_CALL EncryptorImpl::setReferenceId( sal_Int32 id )
     178                 :            :     throw (cssu::Exception, cssu::RuntimeException)
     179                 :            : {
     180                 :          0 :     m_nReferenceId = id;
     181                 :          0 : }
     182                 :            : 
     183                 :            : /* XEncryptionResultBroadcaster */
     184                 :          0 : void SAL_CALL EncryptorImpl::addEncryptionResultListener( const cssu::Reference< cssxc::sax::XEncryptionResultListener >& listener )
     185                 :            :         throw (cssu::Exception, cssu::RuntimeException)
     186                 :            : {
     187                 :          0 :     m_xResultListener = listener;
     188                 :          0 :     tryToPerform();
     189                 :          0 : }
     190                 :            : 
     191                 :          0 : void SAL_CALL EncryptorImpl::removeEncryptionResultListener( const cssu::Reference< cssxc::sax::XEncryptionResultListener >&)
     192                 :            :         throw (cssu::RuntimeException)
     193                 :            : {
     194                 :          0 : }
     195                 :            : 
     196                 :            : /* XInitialization */
     197                 :          0 : void SAL_CALL EncryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
     198                 :            :     throw (cssu::Exception, cssu::RuntimeException)
     199                 :            : {
     200                 :            :     OSL_ASSERT(aArguments.getLength() == 5);
     201                 :            : 
     202                 :          0 :     rtl::OUString ouTempString;
     203                 :            : 
     204                 :          0 :     aArguments[0] >>= ouTempString;
     205                 :          0 :     m_nSecurityId = ouTempString.toInt32();
     206                 :          0 :     aArguments[1] >>= m_xSAXEventKeeper;
     207                 :          0 :     aArguments[2] >>= ouTempString;
     208                 :          0 :     m_nIdOfTemplateEC = ouTempString.toInt32();
     209                 :          0 :     aArguments[3] >>= m_xSecurityEnvironment;
     210                 :          0 :     aArguments[4] >>= m_xXMLEncryption;
     211                 :          0 : }
     212                 :            : 
     213                 :            : 
     214                 :          0 : rtl::OUString EncryptorImpl_getImplementationName ()
     215                 :            :     throw (cssu::RuntimeException)
     216                 :            : {
     217                 :          0 :     return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
     218                 :            : }
     219                 :            : 
     220                 :          0 : sal_Bool SAL_CALL EncryptorImpl_supportsService( const rtl::OUString& ServiceName )
     221                 :            :     throw (cssu::RuntimeException)
     222                 :            : {
     223                 :          0 :     return ServiceName == SERVICE_NAME;
     224                 :            : }
     225                 :            : 
     226                 :          0 : cssu::Sequence< rtl::OUString > SAL_CALL EncryptorImpl_getSupportedServiceNames(  )
     227                 :            :     throw (cssu::RuntimeException)
     228                 :            : {
     229                 :          0 :     cssu::Sequence < rtl::OUString > aRet(1);
     230                 :          0 :     rtl::OUString* pArray = aRet.getArray();
     231                 :          0 :     pArray[0] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
     232                 :          0 :     return aRet;
     233                 :            : }
     234                 :            : #undef SERVICE_NAME
     235                 :            : 
     236                 :          0 : cssu::Reference< cssu::XInterface > SAL_CALL EncryptorImpl_createInstance(
     237                 :            :     const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
     238                 :            :     throw( cssu::Exception )
     239                 :            : {
     240                 :          0 :     return (cppu::OWeakObject*) new EncryptorImpl(rSMgr);
     241                 :            : }
     242                 :            : 
     243                 :            : /* XServiceInfo */
     244                 :          0 : rtl::OUString SAL_CALL EncryptorImpl::getImplementationName(  )
     245                 :            :     throw (cssu::RuntimeException)
     246                 :            : {
     247                 :          0 :     return EncryptorImpl_getImplementationName();
     248                 :            : }
     249                 :          0 : sal_Bool SAL_CALL EncryptorImpl::supportsService( const rtl::OUString& rServiceName )
     250                 :            :     throw (cssu::RuntimeException)
     251                 :            : {
     252                 :          0 :     return EncryptorImpl_supportsService( rServiceName );
     253                 :            : }
     254                 :          0 : cssu::Sequence< rtl::OUString > SAL_CALL EncryptorImpl::getSupportedServiceNames(  )
     255                 :            :     throw (cssu::RuntimeException)
     256                 :            : {
     257                 :          0 :     return EncryptorImpl_getSupportedServiceNames();
     258                 :            : }
     259                 :            : 
     260                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10