LibreOffice Module comphelper (master) 1
docpasswordhelper.hxx
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#ifndef INCLUDED_COMPHELPER_DOCPASSWORDHELPER_HXX
21#define INCLUDED_COMPHELPER_DOCPASSWORDHELPER_HXX
22
24#include <string_view>
25#include <vector>
27#include <comphelper/hash.hxx>
28
30namespace com::sun::star::beans { struct PropertyValue; }
31namespace com::sun::star::beans { struct NamedValue; }
32
33namespace comphelper {
34
36{
37 OK,
39 Abort
40};
41
42
50{
51public:
52 virtual ~IDocPasswordVerifier();
53
73 virtual DocPasswordVerifierResult verifyPassword( const OUString& rPassword, css::uno::Sequence< css::beans::NamedValue >& o_rEncryptionData ) = 0;
74
89 virtual DocPasswordVerifierResult verifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& o_rEncryptionData ) = 0;
90
91};
92
93
97{
98public:
99
100
113 static css::uno::Sequence< css::beans::PropertyValue >
114 GenerateNewModifyPasswordInfo( std::u16string_view aPassword );
115
130 static css::uno::Sequence< css::beans::PropertyValue > ConvertPasswordInfo(
131 const css::uno::Sequence< css::beans::PropertyValue >& aInfo );
132
133 static css::uno::Sequence<css::beans::PropertyValue>
134 GenerateNewModifyPasswordInfoOOXML(std::u16string_view aPassword);
135
150 static bool IsModifyPasswordCorrect(
151 std::u16string_view aPassword,
152 const css::uno::Sequence< css::beans::PropertyValue >& aInfo );
153
154
165 static sal_uInt32 GetWordHashAsUINT32( std::u16string_view aString );
166
167
183 static sal_uInt16 GetXLHashAsUINT16(
184 std::u16string_view aString,
185 rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 );
186
187
199 static css::uno::Sequence< sal_Int8 > GetXLHashAsSequence(
200 std::u16string_view aString );
201
202
240 static css::uno::Sequence<sal_Int8> GetOoxHashAsSequence(
241 const OUString& rPassword,
242 std::u16string_view rSaltValue,
243 sal_uInt32 nSpinCount,
245 std::u16string_view rAlgorithmName);
246
247
286 static OUString GetOoxHashAsBase64(
287 const OUString& rPassword,
288 std::u16string_view rSaltValue,
289 sal_uInt32 nSpinCount,
291 std::u16string_view rAlgorithmName);
292
293
330 static std::vector<unsigned char> GetOoxHashAsVector(
331 const OUString& rPassword,
332 const std::vector<unsigned char>& rSaltValue,
333 sal_uInt32 nSpinCount,
335 std::u16string_view rAlgorithmName);
336
337
342 static css::uno::Sequence< sal_Int8 > GenerateRandomByteSequence(
343 sal_Int32 nLength );
344
345
350 static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
351 std::u16string_view aPassword,
352 const css::uno::Sequence< sal_Int8 >& aDocId );
353
354
359 static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
360 const sal_uInt16 pPassData[16],
361 const css::uno::Sequence< sal_Int8 >& aDocId );
362
367 static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
368 const sal_uInt16 pPassData[16],
369 const sal_uInt8 pDocId[16] );
370
371
425 static css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword(
426 IDocPasswordVerifier& rVerifier,
427 const css::uno::Sequence< css::beans::NamedValue >& rMediaEncData,
428 const OUString& rMediaPassword,
429 const css::uno::Reference< css::task::XInteractionHandler >& rxInteractHandler,
430 const OUString& rDocumentUrl,
431 DocPasswordRequestType eRequestType,
432 const ::std::vector< OUString >* pDefaultPasswords = nullptr,
433 bool* pbIsDefaultPassword = nullptr );
434
435 static css::uno::Sequence< css::beans::NamedValue > decryptGpgSession(
436 const css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > >& rGpgProperties);
437
438private:
440};
441
442
443} // namespace comphelper
444
445#endif
446
447/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper that asks for a document password and checks its validity.
static css::uno::Sequence< sal_Int8 > GenerateStd97Key(const sal_uInt16 pPassData[16], const css::uno::Sequence< sal_Int8 > &aDocId)
This helper function generates a byte sequence representing the key digest value used by MSCodec_Std9...
static css::uno::Sequence< sal_Int8 > GenerateStd97Key(std::u16string_view aPassword, const css::uno::Sequence< sal_Int8 > &aDocId)
This helper function generates a byte sequence representing the key digest value used by MSCodec_Std9...
Base class for a password verifier used by the DocPasswordHelper class below.
virtual DocPasswordVerifierResult verifyPassword(const OUString &rPassword, css::uno::Sequence< css::beans::NamedValue > &o_rEncryptionData)=0
Will be called every time a password needs to be verified.
virtual DocPasswordVerifierResult verifyEncryptionData(const css::uno::Sequence< css::beans::NamedValue > &o_rEncryptionData)=0
Will be called every time an encryption data needs to be verified.
#define COMPHELPER_DLLPUBLIC
#define OK
DocPasswordRequestType
Selects which UNO document password request type to use.
unsigned char sal_uInt8
sal_Int32 nLength