1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_package.hxx"
31 #include <rtl/digest.h>
32 #include <rtl/ref.hxx>
34 #include "sha1context.hxx"
36 using namespace ::com::sun::star
;
39 uno::Reference
< xml::crypto::XDigestContext
> SHA1DigestContext::Create()
41 ::rtl::Reference
< SHA1DigestContext
> xResult
= new SHA1DigestContext();
42 xResult
->m_pDigest
= rtl_digest_createSHA1();
43 if ( !xResult
->m_pDigest
)
44 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not create cipher!\n" ),
45 uno::Reference
< XInterface
>() );
47 return uno::Reference
< xml::crypto::XDigestContext
>( xResult
.get() );
50 SHA1DigestContext::~SHA1DigestContext()
54 rtl_digest_destroySHA1( m_pDigest
);
59 void SAL_CALL
SHA1DigestContext::updateDigest( const uno::Sequence
< ::sal_Int8
>& aData
)
60 throw( lang::DisposedException
, uno::RuntimeException
)
62 ::osl::MutexGuard
aGuard( m_aMutex
);
64 throw lang::DisposedException();
66 if ( rtl_Digest_E_None
!= rtl_digest_updateSHA1( m_pDigest
, aData
.getConstArray(), aData
.getLength() ) )
68 rtl_digest_destroySHA1( m_pDigest
);
71 throw uno::RuntimeException();
75 uno::Sequence
< ::sal_Int8
> SAL_CALL
SHA1DigestContext::finalizeDigestAndDispose()
76 throw( lang::DisposedException
, uno::RuntimeException
)
78 ::osl::MutexGuard
aGuard( m_aMutex
);
80 throw lang::DisposedException();
82 uno::Sequence
< sal_Int8
> aResult( RTL_DIGEST_LENGTH_SHA1
);
83 if ( rtl_Digest_E_None
!= rtl_digest_getSHA1( m_pDigest
, reinterpret_cast< sal_uInt8
* >( aResult
.getArray() ), aResult
.getLength() ) )
85 rtl_digest_destroySHA1( m_pDigest
);
88 throw uno::RuntimeException();
91 rtl_digest_destroySHA1( m_pDigest
);