Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sfx2/source/doc/signaturestate.cxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10
#include <sfx2/signaturestate.hxx>
11
12
#include <com/sun/star/security/CertificateValidity.hpp>
13
#include <com/sun/star/security/DocumentSignatureInformation.hpp>
14
15
using namespace css;
16
17
namespace DocumentSignatures
18
{
19
SignatureState
20
getSignatureState(const uno::Sequence<security::DocumentSignatureInformation>& aSigInfo)
21
16.9k
{
22
16.9k
    bool bCertValid = true;
23
16.9k
    SignatureState nResult = SignatureState::NOSIGNATURES;
24
16.9k
    bool bCompleteSignature = true;
25
16.9k
    if (!aSigInfo.hasElements())
26
16.9k
        return nResult;
27
28
0
    nResult = SignatureState::OK;
29
0
    for (const auto& rInfo : aSigInfo)
30
0
    {
31
0
        if (bCertValid)
32
0
        {
33
0
            sal_Int32 nCertStat = rInfo.CertificateStatus;
34
0
            bCertValid = nCertStat == security::CertificateValidity::VALID;
35
0
        }
36
37
0
        if (!rInfo.SignatureIsValid)
38
0
        {
39
0
            nResult = SignatureState::BROKEN;
40
0
            break;
41
0
        }
42
0
        bCompleteSignature &= !rInfo.PartialDocumentSignature;
43
0
    }
44
45
0
    if (nResult == SignatureState::OK && !bCertValid && !bCompleteSignature)
46
0
        nResult = SignatureState::NOTVALIDATED_PARTIAL_OK;
47
0
    else if (nResult == SignatureState::OK && !bCertValid)
48
0
        nResult = SignatureState::NOTVALIDATED;
49
0
    else if (nResult == SignatureState::OK && bCertValid && !bCompleteSignature)
50
0
        nResult = SignatureState::PARTIAL_OK;
51
52
    // this code must not check whether the document is modified
53
    // it should only check the provided info
54
55
0
    return nResult;
56
16.9k
}
57
}
58
59
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */