Avoid potential negative array index access to cached text.
[LibreOffice.git] / writerfilter / source / dmapper / WriteProtection.cxx
blobc300ab09e303837c3b6d2f9f83cdcf379fd6f6f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "WriteProtection.hxx"
21 #include "TagLogger.hxx"
23 #include <comphelper/propertyvalue.hxx>
24 #include <ooxml/resourceids.hxx>
26 using namespace com::sun::star;
28 namespace writerfilter::dmapper
30 WriteProtection::WriteProtection()
31 : LoggedProperties("WriteProtection")
32 , m_nCryptProviderType(NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES)
33 , m_CryptSpinCount(0)
34 , m_bRecommended(false)
38 WriteProtection::~WriteProtection() {}
40 void WriteProtection::lcl_attribute(Id nName, Value& val)
42 int nIntValue = val.getInt();
43 OUString sStringValue = val.getString();
45 switch (nName)
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
52 m_sCryptAlgorithmClass = "hash";
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
60 sal_Int32 nCryptAlgorithmSid = sStringValue.toInt32();
61 switch (nCryptAlgorithmSid)
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.
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:
114 #ifdef DBG_UTIL
115 TagLogger::getInstance().element("unhandled");
116 #endif
121 void WriteProtection::lcl_sprm(Sprm& /*rSprm*/) {}
123 uno::Sequence<beans::PropertyValue> WriteProtection::toSequence() const
125 uno::Sequence<beans::PropertyValue> aResult;
126 if (!m_sAlgorithmName.isEmpty() && !m_sSalt.isEmpty() && !m_sHash.isEmpty()
127 && m_sCryptAlgorithmClass == "hash" && m_sCryptAlgorithmType == "typeAny")
129 aResult = { comphelper::makePropertyValue("algorithm-name", m_sAlgorithmName),
130 comphelper::makePropertyValue("salt", m_sSalt),
131 comphelper::makePropertyValue("iteration-count", m_CryptSpinCount),
132 comphelper::makePropertyValue("hash", m_sHash) };
135 return aResult;
138 } //namespace writerfilter::dmapper
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */