1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
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();
47 case NS_ooxml::LN_AG_Password_cryptProviderType
: // 92025
48 m_nCryptProviderType
= nIntValue
;
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";
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";
58 case NS_ooxml::LN_AG_Password_cryptAlgorithmSid
: // 92028
60 sal_Int32 nCryptAlgorithmSid
= sStringValue
.toInt32();
61 switch (nCryptAlgorithmSid
)
64 m_sAlgorithmName
= "MD2";
67 m_sAlgorithmName
= "MD4";
70 m_sAlgorithmName
= "MD5";
73 m_sAlgorithmName
= "SHA-1";
76 m_sAlgorithmName
= "MAC";
79 m_sAlgorithmName
= "RIPEMD";
82 m_sAlgorithmName
= "RIPEMD-160";
85 m_sAlgorithmName
= "HMAC";
88 m_sAlgorithmName
= "SHA-256";
91 m_sAlgorithmName
= "SHA-384";
94 m_sAlgorithmName
= "SHA-512";
96 default:; // 8, 10, 11, any other value: Undefined.
100 case NS_ooxml::LN_AG_Password_cryptSpinCount
: // 92029
101 m_CryptSpinCount
= nIntValue
;
103 case NS_ooxml::LN_AG_Password_hash
: // 92035
104 m_sHash
= sStringValue
;
106 case NS_ooxml::LN_AG_Password_salt
: // 92036
107 m_sSalt
= sStringValue
;
109 case NS_ooxml::LN_CT_WriteProtection_recommended
:
110 m_bRecommended
= nIntValue
;
115 TagLogger::getInstance().element("unhandled");
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
) };
138 } //namespace writerfilter::dmapper
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */