LibreOffice Module writerfilter (master) 1
WriteProtection.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 "WriteProtection.hxx"
21#include "TagLogger.hxx"
22
24#include <ooxml/resourceids.hxx>
25
26using namespace com::sun::star;
27
29{
31 : LoggedProperties("WriteProtection")
32 , m_nCryptProviderType(NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES)
33 , m_CryptSpinCount(0)
34 , m_bRecommended(false)
35{
36}
37
39
41{
42 int nIntValue = val.getInt();
43 OUString sStringValue = val.getString();
44
45 switch (nName)
46 {
47 case NS_ooxml::LN_AG_Password_cryptProviderType: // 92025
48 m_nCryptProviderType = nIntValue;
49 break;
50 case NS_ooxml::LN_AG_Password_cryptAlgorithmClass: // 92026
51 if (nIntValue == NS_ooxml::LN_Value_doc_ST_AlgClass_hash) // 92023
53 break;
54 case NS_ooxml::LN_AG_Password_cryptAlgorithmType: // 92027
55 if (nIntValue == NS_ooxml::LN_Value_doc_ST_AlgType_typeAny) // 92024
56 m_sCryptAlgorithmType = "typeAny";
57 break;
58 case NS_ooxml::LN_AG_Password_cryptAlgorithmSid: // 92028
59 {
60 sal_Int32 nCryptAlgorithmSid = sStringValue.toInt32();
61 switch (nCryptAlgorithmSid)
62 {
63 case 1:
64 m_sAlgorithmName = "MD2";
65 break;
66 case 2:
67 m_sAlgorithmName = "MD4";
68 break;
69 case 3:
70 m_sAlgorithmName = "MD5";
71 break;
72 case 4:
73 m_sAlgorithmName = "SHA-1";
74 break;
75 case 5:
76 m_sAlgorithmName = "MAC";
77 break;
78 case 6:
79 m_sAlgorithmName = "RIPEMD";
80 break;
81 case 7:
82 m_sAlgorithmName = "RIPEMD-160";
83 break;
84 case 9:
85 m_sAlgorithmName = "HMAC";
86 break;
87 case 12:
88 m_sAlgorithmName = "SHA-256";
89 break;
90 case 13:
91 m_sAlgorithmName = "SHA-384";
92 break;
93 case 14:
94 m_sAlgorithmName = "SHA-512";
95 break;
96 default:; // 8, 10, 11, any other value: Undefined.
97 }
98 }
99 break;
100 case NS_ooxml::LN_AG_Password_cryptSpinCount: // 92029
101 m_CryptSpinCount = nIntValue;
102 break;
103 case NS_ooxml::LN_AG_Password_hash: // 92035
104 m_sHash = sStringValue;
105 break;
106 case NS_ooxml::LN_AG_Password_salt: // 92036
107 m_sSalt = sStringValue;
108 break;
109 case NS_ooxml::LN_CT_WriteProtection_recommended:
110 m_bRecommended = nIntValue;
111 break;
112 default:
113 {
114#ifdef DBG_UTIL
115 TagLogger::getInstance().element("unhandled");
116#endif
117 }
118 }
119}
120
122
124{
126 if (!m_sAlgorithmName.isEmpty() && !m_sSalt.isEmpty() && !m_sHash.isEmpty()
127 && m_sCryptAlgorithmClass == "hash" && m_sCryptAlgorithmType == "typeAny")
128 {
129 aResult = { comphelper::makePropertyValue("algorithm-name", m_sAlgorithmName),
133 }
134
135 return aResult;
136}
137
138} //namespace writerfilter::dmapper
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
An SPRM: Section, Paragraph and Run Modifier.
static TagLogger & getInstance()
Definition: TagLogger.cxx:95
void element(const std::string &name)
Definition: TagLogger.cxx:102
virtual int getInt() const =0
Returns integer representation of the value.
virtual OUString getString() const =0
Returns string representation of the value.
sal_Int32 m_nCryptProviderType
Provider type.
virtual void lcl_sprm(Sprm &sprm) override
css::uno::Sequence< css::beans::PropertyValue > toSequence() const
virtual void lcl_attribute(Id Name, Value &val) override
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
sal_uInt32 Id