LCOV - code coverage report
Current view: top level - libreoffice/package/source/zipapi - sha1context.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 33 66.7 %
Date: 2012-12-27 Functions: 5 5 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 <rtl/digest.h>
      22             : #include <rtl/ref.hxx>
      23             : 
      24             : #include "sha1context.hxx"
      25             : 
      26             : using namespace ::com::sun::star;
      27             : 
      28             : // static
      29           4 : uno::Reference< xml::crypto::XDigestContext > SHA1DigestContext::Create()
      30             : {
      31           4 :     ::rtl::Reference< SHA1DigestContext > xResult = new SHA1DigestContext();
      32           4 :     xResult->m_pDigest = rtl_digest_createSHA1();
      33           4 :     if ( !xResult->m_pDigest )
      34             :         throw uno::RuntimeException("Can not create cipher!",
      35           0 :                                      uno::Reference< XInterface >() );
      36             : 
      37           4 :     return uno::Reference< xml::crypto::XDigestContext >( xResult.get() );
      38             : }
      39             : 
      40          12 : SHA1DigestContext::~SHA1DigestContext()
      41             : {
      42           4 :     if ( m_pDigest )
      43             :     {
      44           0 :         rtl_digest_destroySHA1( m_pDigest );
      45           0 :         m_pDigest = NULL;
      46             :     }
      47           8 : }
      48             : 
      49           4 : void SAL_CALL SHA1DigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData )
      50             :     throw( lang::DisposedException, uno::RuntimeException )
      51             : {
      52           4 :     ::osl::MutexGuard aGuard( m_aMutex );
      53           4 :     if ( !m_pDigest )
      54           0 :         throw lang::DisposedException();
      55             : 
      56           4 :     if ( rtl_Digest_E_None != rtl_digest_updateSHA1( m_pDigest, aData.getConstArray(), aData.getLength() ) )
      57             :     {
      58           0 :         rtl_digest_destroySHA1( m_pDigest );
      59           0 :         m_pDigest = NULL;
      60             : 
      61           0 :         throw uno::RuntimeException();
      62           4 :     }
      63           4 : }
      64             : 
      65           4 : uno::Sequence< ::sal_Int8 > SAL_CALL SHA1DigestContext::finalizeDigestAndDispose()
      66             :     throw( lang::DisposedException, uno::RuntimeException )
      67             : {
      68           4 :     ::osl::MutexGuard aGuard( m_aMutex );
      69           4 :     if ( !m_pDigest )
      70           0 :         throw lang::DisposedException();
      71             : 
      72           4 :     uno::Sequence< sal_Int8 > aResult( RTL_DIGEST_LENGTH_SHA1 );
      73           4 :     if ( rtl_Digest_E_None != rtl_digest_getSHA1( m_pDigest, reinterpret_cast< sal_uInt8* >( aResult.getArray() ), aResult.getLength() ) )
      74             :     {
      75           0 :         rtl_digest_destroySHA1( m_pDigest );
      76           0 :         m_pDigest = NULL;
      77             : 
      78           0 :         throw uno::RuntimeException();
      79             :     }
      80             : 
      81           4 :     rtl_digest_destroySHA1( m_pDigest );
      82           4 :     m_pDigest = NULL;
      83             : 
      84           4 :     return aResult;
      85             : }
      86             : 
      87             : 
      88             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10