LCOV - code coverage report
Current view: top level - libreoffice/xmlsecurity/source/framework - decryptorimpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 55 0.0 %
Date: 2012-12-27 Functions: 0 16 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 "decryptorimpl.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.Decryptor"
      32             : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"
      33             : 
      34           0 : DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
      35             : {
      36           0 :     mxMSF = rxMSF;
      37           0 : }
      38             : 
      39           0 : DecryptorImpl::~DecryptorImpl()
      40             : {
      41           0 : }
      42             : 
      43           0 : bool DecryptorImpl::checkReady() const
      44             : /****** DecryptorImpl/checkReady *********************************************
      45             :  *
      46             :  *   NAME
      47             :  *  checkReady -- checks the conditions for the decryption.
      48             :  *
      49             :  *   SYNOPSIS
      50             :  *  bReady = checkReady( );
      51             :  *
      52             :  *   FUNCTION
      53             :  *  checks whether all following conditions are satisfied:
      54             :  *  1. the result listener is ready;
      55             :  *  2. the EncryptionEngine is ready.
      56             :  *
      57             :  *   INPUTS
      58             :  *  empty
      59             :  *
      60             :  *   RESULT
      61             :  *  bReady - true if all conditions are satisfied, false otherwise
      62             :  *
      63             :  *   AUTHOR
      64             :  *  Michael Mi
      65             :  *  Email: michael.mi@sun.com
      66             :  ******************************************************************************/
      67             : {
      68           0 :     return (m_xResultListener.is() && EncryptionEngine::checkReady());
      69             : }
      70             : 
      71           0 : void DecryptorImpl::notifyResultListener() const
      72             :     throw (cssu::Exception, cssu::RuntimeException)
      73             : /****** DecryptorImpl/notifyResultListener ***********************************
      74             :  *
      75             :  *   NAME
      76             :  *  notifyResultListener -- notifies the listener about the decryption
      77             :  *  result.
      78             :  *
      79             :  *   SYNOPSIS
      80             :  *  notifyResultListener( );
      81             :  *
      82             :  *   FUNCTION
      83             :  *  see NAME.
      84             :  *
      85             :  *   INPUTS
      86             :  *  empty
      87             :  *
      88             :  *   RESULT
      89             :  *  empty
      90             :  *
      91             :  *   AUTHOR
      92             :  *  Michael Mi
      93             :  *  Email: michael.mi@sun.com
      94             :  ******************************************************************************/
      95             : {
      96             :     cssu::Reference< cssxc::sax::XDecryptionResultListener >
      97           0 :         xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
      98             : 
      99           0 :     xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus);
     100           0 : }
     101             : 
     102           0 : void DecryptorImpl::startEngine( const cssu::Reference<
     103             :     cssxc::XXMLEncryptionTemplate >&
     104             :     xEncryptionTemplate)
     105             :     throw (cssu::Exception, cssu::RuntimeException)
     106             : /****** DecryptorImpl/startEngine ********************************************
     107             :  *
     108             :  *   NAME
     109             :  *  startEngine -- decrypts the encryption.
     110             :  *
     111             :  *   SYNOPSIS
     112             :  *  startEngine( xEncryptionTemplate );
     113             :  *
     114             :  *   FUNCTION
     115             :  *  decrypts the encryption element, then if succeeds, updates the link
     116             :  *  of old template element to the new encryption element in
     117             :  *  SAXEventKeeper.
     118             :  *
     119             :  *   INPUTS
     120             :  *  xEncryptionTemplate - the encryption template to be decrypted.
     121             :  *
     122             :  *   RESULT
     123             :  *  empty
     124             :  *
     125             :  *   AUTHOR
     126             :  *  Michael Mi
     127             :  *  Email: michael.mi@sun.com
     128             :  ******************************************************************************/
     129             : {
     130           0 :     cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate;
     131             :     try
     132             :     {
     133           0 :         xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
     134           0 :         m_nStatus = xResultTemplate->getStatus();
     135             :     }
     136           0 :     catch( cssu::Exception& )
     137             :     {
     138           0 :         m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
     139             :     }
     140             : 
     141           0 :     if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
     142             :     {
     143             :         cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement
     144           0 :             = xResultTemplate->getTemplate();
     145           0 :         m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
     146           0 :     }
     147           0 : }
     148             : 
     149             : /* XDecryptionResultBroadcaster */
     150           0 : void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
     151             :         throw (cssu::Exception, cssu::RuntimeException)
     152             : {
     153           0 :     m_xResultListener = listener;
     154           0 :     tryToPerform();
     155           0 : }
     156             : 
     157           0 : void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&)
     158             :         throw (cssu::RuntimeException)
     159             : {
     160           0 : }
     161             : 
     162             : /* XInitialization */
     163           0 : void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
     164             :     throw (cssu::Exception, cssu::RuntimeException)
     165             : {
     166             :     OSL_ASSERT(aArguments.getLength() == 5);
     167             : 
     168           0 :     rtl::OUString ouTempString;
     169             : 
     170           0 :     aArguments[0] >>= ouTempString;
     171           0 :     m_nSecurityId = ouTempString.toInt32();
     172           0 :     aArguments[1] >>= m_xSAXEventKeeper;
     173           0 :     aArguments[2] >>= ouTempString;
     174           0 :     m_nIdOfTemplateEC = ouTempString.toInt32();
     175           0 :     aArguments[3] >>= m_xXMLSecurityContext;
     176           0 :     aArguments[4] >>= m_xXMLEncryption;
     177           0 : }
     178             : 
     179           0 : rtl::OUString DecryptorImpl_getImplementationName ()
     180             :     throw (cssu::RuntimeException)
     181             : {
     182           0 :     return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
     183             : }
     184             : 
     185           0 : sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName )
     186             :     throw (cssu::RuntimeException)
     187             : {
     188           0 :     return ServiceName == SERVICE_NAME;
     189             : }
     190             : 
     191           0 : cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames(  )
     192             :     throw (cssu::RuntimeException)
     193             : {
     194           0 :     cssu::Sequence < rtl::OUString > aRet(1);
     195           0 :     rtl::OUString* pArray = aRet.getArray();
     196           0 :     pArray[0] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
     197           0 :     return aRet;
     198             : }
     199             : #undef SERVICE_NAME
     200             : 
     201           0 : cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
     202             :     throw( cssu::Exception )
     203             : {
     204           0 :     return (cppu::OWeakObject*) new DecryptorImpl(rSMgr);
     205             : }
     206             : 
     207             : /* XServiceInfo */
     208           0 : rtl::OUString SAL_CALL DecryptorImpl::getImplementationName(  )
     209             :     throw (cssu::RuntimeException)
     210             : {
     211           0 :     return DecryptorImpl_getImplementationName();
     212             : }
     213           0 : sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName )
     214             :     throw (cssu::RuntimeException)
     215             : {
     216           0 :     return DecryptorImpl_supportsService( rServiceName );
     217             : }
     218           0 : cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames(  )
     219             :     throw (cssu::RuntimeException)
     220             : {
     221           0 :     return DecryptorImpl_getSupportedServiceNames();
     222             : }
     223             : 
     224             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10