LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec/nss - digestcontext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 26 41 63.4 %
Date: 2014-04-11 Functions: 4 4 100.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 <pk11pub.h>
      22             : #include "digestcontext.hxx"
      23             : 
      24             : using namespace ::com::sun::star;
      25             : 
      26          81 : ODigestContext::~ODigestContext()
      27             : {
      28          27 :     if ( m_pContext )
      29             :     {
      30           0 :         PK11_DestroyContext( m_pContext, PR_TRUE );
      31           0 :         m_pContext = NULL;
      32             :     }
      33          54 : }
      34             : 
      35          27 : void SAL_CALL ODigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData )
      36             :     throw (lang::DisposedException, uno::RuntimeException, std::exception)
      37             : {
      38          27 :     ::osl::MutexGuard aGuard( m_aMutex );
      39             : 
      40          27 :     if ( m_bBroken )
      41           0 :         throw uno::RuntimeException();
      42             : 
      43          27 :     if ( m_bDisposed )
      44           0 :         throw lang::DisposedException();
      45             : 
      46          27 :     if ( !m_b1KData || m_nDigested < 1024 )
      47             :     {
      48          27 :         uno::Sequence< sal_Int8 > aToDigest = aData;
      49          27 :         if ( m_b1KData && m_nDigested + aData.getLength() > 1024 )
      50           0 :             aToDigest.realloc( 1024 - m_nDigested );
      51             : 
      52          27 :         if ( PK11_DigestOp( m_pContext, reinterpret_cast< const unsigned char* >( aToDigest.getConstArray() ), aToDigest.getLength() ) != SECSuccess )
      53             :         {
      54           0 :             PK11_DestroyContext( m_pContext, PR_TRUE );
      55           0 :             m_pContext = NULL;
      56           0 :             m_bBroken = true;
      57           0 :             throw uno::RuntimeException();
      58             :         }
      59             : 
      60          27 :         m_nDigested += aToDigest.getLength();
      61          27 :     }
      62          27 : }
      63             : 
      64          27 : uno::Sequence< ::sal_Int8 > SAL_CALL ODigestContext::finalizeDigestAndDispose()
      65             :     throw (lang::DisposedException, uno::RuntimeException, std::exception)
      66             : {
      67          27 :     ::osl::MutexGuard aGuard( m_aMutex );
      68             : 
      69          27 :     if ( m_bBroken )
      70           0 :         throw uno::RuntimeException();
      71             : 
      72          27 :     if ( m_bDisposed )
      73           0 :         throw lang::DisposedException();
      74             : 
      75          27 :     uno::Sequence< sal_Int8 > aResult( m_nDigestLength );
      76          27 :     unsigned int nResultLen = 0;
      77          27 :     if ( PK11_DigestFinal( m_pContext, reinterpret_cast< unsigned char* >( aResult.getArray() ), &nResultLen, aResult.getLength() ) != SECSuccess )
      78             :     {
      79           0 :         PK11_DestroyContext( m_pContext, PR_TRUE );
      80           0 :         m_pContext = NULL;
      81           0 :         m_bBroken = true;
      82           0 :         throw uno::RuntimeException();
      83             :     }
      84             : 
      85          27 :     PK11_DestroyContext( m_pContext, PR_TRUE );
      86          27 :     m_pContext = NULL;
      87          27 :     m_bDisposed = true;
      88             : 
      89          27 :     aResult.realloc( nResultLen );
      90          27 :     return aResult;
      91             : }
      92             : 
      93             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10