1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <rtl/digest.h>
22 #include <rtl/ref.hxx>
24 #include "sha1context.hxx"
26 using namespace ::com::sun::star
;
29 uno::Reference
< xml::crypto::XDigestContext
> SHA1DigestContext::Create()
31 ::rtl::Reference
< SHA1DigestContext
> xResult
= new SHA1DigestContext();
32 xResult
->m_pDigest
= rtl_digest_createSHA1();
33 if ( !xResult
->m_pDigest
)
34 throw uno::RuntimeException("Can not create cipher!",
35 uno::Reference
< XInterface
>() );
37 return uno::Reference
< xml::crypto::XDigestContext
>( xResult
.get() );
40 SHA1DigestContext::~SHA1DigestContext()
44 rtl_digest_destroySHA1( m_pDigest
);
49 void SAL_CALL
SHA1DigestContext::updateDigest( const uno::Sequence
< ::sal_Int8
>& aData
)
50 throw( lang::DisposedException
, uno::RuntimeException
)
52 ::osl::MutexGuard
aGuard( m_aMutex
);
54 throw lang::DisposedException();
56 if ( rtl_Digest_E_None
!= rtl_digest_updateSHA1( m_pDigest
, aData
.getConstArray(), aData
.getLength() ) )
58 rtl_digest_destroySHA1( m_pDigest
);
61 throw uno::RuntimeException();
65 uno::Sequence
< ::sal_Int8
> SAL_CALL
SHA1DigestContext::finalizeDigestAndDispose()
66 throw( lang::DisposedException
, uno::RuntimeException
)
68 ::osl::MutexGuard
aGuard( m_aMutex
);
70 throw lang::DisposedException();
72 uno::Sequence
< sal_Int8
> aResult( RTL_DIGEST_LENGTH_SHA1
);
73 if ( rtl_Digest_E_None
!= rtl_digest_getSHA1( m_pDigest
, reinterpret_cast< sal_uInt8
* >( aResult
.getArray() ), aResult
.getLength() ) )
75 rtl_digest_destroySHA1( m_pDigest
);
78 throw uno::RuntimeException();
81 rtl_digest_destroySHA1( m_pDigest
);
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */