Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/pdf/EncryptionHashTransporter.hxx
Line
Count
Source
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
10
#pragma once
11
12
#include <com/sun/star/beans/XMaterialHolder.hpp>
13
#include <comphelper/hash.hxx>
14
#include <cppuhelper/implbase.hxx>
15
#include <sal/log.hxx>
16
17
#include <map>
18
19
namespace vcl::pdf
20
{
21
/* a crutch to transport a ::comphelper::Hash safely though UNO API
22
   this is needed for the PDF export dialog, which otherwise would have to pass
23
   clear text passwords down till they can be used in PDFWriter. Unfortunately
24
   the MD5 sum of the password (which is needed to create the PDF encryption key)
25
   is not sufficient, since an MD5 digest cannot be created in an arbitrary state
26
   which would be needed in computeEncryptionKey.
27
*/
28
class EncryptionHashTransporter : public cppu::WeakImplHelper<css::beans::XMaterialHolder>
29
{
30
    // V2R3
31
    std::unique_ptr<comphelper::Hash> m_pDigest;
32
    std::vector<sal_uInt8> maOValue;
33
34
    // V5R6
35
    std::vector<sal_uInt8> mU;
36
    std::vector<sal_uInt8> mUE;
37
    std::vector<sal_uInt8> mO;
38
    std::vector<sal_uInt8> mOE;
39
    std::vector<sal_uInt8> maEncryptionKey;
40
41
    // ID
42
    sal_IntPtr maID;
43
44
public:
45
    EncryptionHashTransporter();
46
47
    virtual ~EncryptionHashTransporter() override;
48
49
0
    comphelper::Hash* getUDigest() { return m_pDigest.get(); };
50
51
0
    std::vector<sal_uInt8>& getOValue() { return maOValue; }
52
53
0
    void invalidate() { m_pDigest.reset(); }
54
55
0
    const std::vector<sal_uInt8>& getU() const { return mU; }
56
0
    void setU(std::vector<sal_uInt8> const& rU) { mU = rU; }
57
58
0
    const std::vector<sal_uInt8>& getUE() const { return mUE; }
59
0
    void setUE(std::vector<sal_uInt8> const& rUE) { mUE = rUE; }
60
61
0
    const std::vector<sal_uInt8>& getO() const { return mO; }
62
0
    void setO(std::vector<sal_uInt8> const& rO) { mO = rO; }
63
64
0
    const std::vector<sal_uInt8>& getOE() const { return mOE; }
65
0
    void setOE(std::vector<sal_uInt8> const& rOE) { mOE = rOE; }
66
67
0
    const std::vector<sal_uInt8>& getEncryptionKey() const { return maEncryptionKey; }
68
    void setEncryptionKey(std::vector<sal_uInt8> const& rEncryptionKey)
69
0
    {
70
0
        maEncryptionKey = rEncryptionKey;
71
0
    }
72
73
    // XMaterialHolder
74
0
    virtual css::uno::Any SAL_CALL getMaterial() override { return css::uno::Any(sal_Int64(maID)); }
75
76
    static EncryptionHashTransporter*
77
    getEncHashTransporter(const css::uno::Reference<css::beans::XMaterialHolder>& xReference);
78
};
79
}
80
81
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */