bump product version to 4.1.6.2
[LibreOffice.git] / xmlsecurity / source / xmlsec / nss / digestcontext.cxx
blob0e4903f7fdc41473489c2e725561397fbf12ee0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <pk11pub.h>
22 #include "digestcontext.hxx"
24 using namespace ::com::sun::star;
26 ODigestContext::~ODigestContext()
28 if ( m_pContext )
30 PK11_DestroyContext( m_pContext, PR_TRUE );
31 m_pContext = NULL;
35 void SAL_CALL ODigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData )
36 throw (lang::DisposedException, uno::RuntimeException)
38 ::osl::MutexGuard aGuard( m_aMutex );
40 if ( m_bBroken )
41 throw uno::RuntimeException();
43 if ( m_bDisposed )
44 throw lang::DisposedException();
46 if ( !m_b1KData || m_nDigested < 1024 )
48 uno::Sequence< sal_Int8 > aToDigest = aData;
49 if ( m_b1KData && m_nDigested + aData.getLength() > 1024 )
50 aToDigest.realloc( 1024 - m_nDigested );
52 if ( PK11_DigestOp( m_pContext, reinterpret_cast< const unsigned char* >( aToDigest.getConstArray() ), aToDigest.getLength() ) != SECSuccess )
54 PK11_DestroyContext( m_pContext, PR_TRUE );
55 m_pContext = NULL;
56 m_bBroken = true;
57 throw uno::RuntimeException();
60 m_nDigested += aToDigest.getLength();
64 uno::Sequence< ::sal_Int8 > SAL_CALL ODigestContext::finalizeDigestAndDispose()
65 throw (lang::DisposedException, uno::RuntimeException)
67 ::osl::MutexGuard aGuard( m_aMutex );
69 if ( m_bBroken )
70 throw uno::RuntimeException();
72 if ( m_bDisposed )
73 throw lang::DisposedException();
75 uno::Sequence< sal_Int8 > aResult( m_nDigestLength );
76 unsigned int nResultLen = 0;
77 if ( PK11_DigestFinal( m_pContext, reinterpret_cast< unsigned char* >( aResult.getArray() ), &nResultLen, aResult.getLength() ) != SECSuccess )
79 PK11_DestroyContext( m_pContext, PR_TRUE );
80 m_pContext = NULL;
81 m_bBroken = true;
82 throw uno::RuntimeException();
85 PK11_DestroyContext( m_pContext, PR_TRUE );
86 m_pContext = NULL;
87 m_bDisposed = true;
89 aResult.realloc( nResultLen );
90 return aResult;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */