LibreOffice Module xmlsecurity (master)
1
xmlsecurity
source
xmlsec
nss
digestcontext.cxx
Go to the documentation of this file.
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
#include <
sal/config.h
>
21
22
#include <com/sun/star/lang/DisposedException.hpp>
23
24
#include <pk11pub.h>
25
#include "
digestcontext.hxx
"
26
27
using namespace
::
com::sun::star
;
28
29
ODigestContext::~ODigestContext
()
30
{
31
if
(
m_pContext
)
32
{
33
PK11_DestroyContext(
m_pContext
, PR_TRUE );
34
m_pContext
=
nullptr
;
35
}
36
}
37
38
void
SAL_CALL
ODigestContext::updateDigest
(
const
uno::Sequence< ::sal_Int8 >& aData )
39
{
40
std::scoped_lock aGuard(
m_aMutex
);
41
42
if
(
m_bBroken
)
43
throw
uno::RuntimeException();
44
45
if
(
m_bDisposed
)
46
throw
lang::DisposedException();
47
48
if
(
m_b1KData
&&
m_nDigested
>= 1024)
49
return
;
50
51
uno::Sequence< sal_Int8 > aToDigest =
aData
;
52
if
(
m_b1KData
&&
m_nDigested
+
aData
.getLength() > 1024 )
53
aToDigest.realloc( 1024 -
m_nDigested
);
54
55
if
( PK11_DigestOp(
m_pContext
,
reinterpret_cast<
const
unsigned
char
*
>
( aToDigest.getConstArray() ), aToDigest.getLength() ) != SECSuccess )
56
{
57
PK11_DestroyContext(
m_pContext
, PR_TRUE );
58
m_pContext
=
nullptr
;
59
m_bBroken
=
true
;
60
throw
uno::RuntimeException();
61
}
62
63
m_nDigested
+= aToDigest.getLength();
64
}
65
66
uno::Sequence< ::sal_Int8 > SAL_CALL
ODigestContext::finalizeDigestAndDispose
()
67
{
68
std::scoped_lock aGuard(
m_aMutex
);
69
70
if
(
m_bBroken
)
71
throw
uno::RuntimeException();
72
73
if
(
m_bDisposed
)
74
throw
lang::DisposedException();
75
76
uno::Sequence< sal_Int8 > aResult(
m_nDigestLength
);
77
unsigned
int
nResultLen = 0;
78
if
( PK11_DigestFinal(
m_pContext
,
reinterpret_cast<
unsigned
char
*
>
( aResult.getArray() ), &nResultLen, aResult.getLength() ) != SECSuccess )
79
{
80
PK11_DestroyContext(
m_pContext
, PR_TRUE );
81
m_pContext
=
nullptr
;
82
m_bBroken
=
true
;
83
throw
uno::RuntimeException();
84
}
85
86
PK11_DestroyContext(
m_pContext
, PR_TRUE );
87
m_pContext
=
nullptr
;
88
m_bDisposed
=
true
;
89
90
aResult.realloc( nResultLen );
91
return
aResult;
92
}
93
94
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ODigestContext::m_bBroken
bool m_bBroken
Definition:
digestcontext.hxx:39
ODigestContext::m_nDigestLength
sal_Int32 const m_nDigestLength
Definition:
digestcontext.hxx:34
ODigestContext::updateDigest
virtual void SAL_CALL updateDigest(const css::uno::Sequence< ::sal_Int8 > &aData) override
Definition:
digestcontext.cxx:38
ODigestContext::m_nDigested
sal_Int32 m_nDigested
Definition:
digestcontext.hxx:36
ODigestContext::m_b1KData
bool const m_b1KData
Definition:
digestcontext.hxx:35
ODigestContext::m_bDisposed
bool m_bDisposed
Definition:
digestcontext.hxx:38
ODigestContext::finalizeDigestAndDispose
virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeDigestAndDispose() override
Definition:
digestcontext.cxx:66
ODigestContext::m_aMutex
std::mutex m_aMutex
Definition:
digestcontext.hxx:31
ODigestContext::~ODigestContext
virtual ~ODigestContext() override
Definition:
digestcontext.cxx:29
ODigestContext::m_pContext
PK11Context * m_pContext
Definition:
digestcontext.hxx:33
config.h
digestcontext.hxx
aData
constexpr OUStringLiteral aData
com::sun::star
Generated on Sun Jul 30 2023 04:29:54 for LibreOffice Module xmlsecurity (master) by
1.9.3