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 
29 namespace com::sun::star::task { class XInteractionHandler; }
30 namespace com::sun::star::beans { struct PropertyValue; }
31 namespace com::sun::star::beans { struct NamedValue; }
32 
33 namespace comphelper {
34 
36 {
37  OK,
39  Abort
40 };
41 
42 
50 {
51 public:
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 {
98 public:
99 
100 
113  static css::uno::Sequence< css::beans::PropertyValue >
114  GenerateNewModifyPasswordInfo( std::u16string_view aPassword );
115 
116  static css::uno::Sequence<css::beans::PropertyValue>
117  GenerateNewModifyPasswordInfoOOXML(std::u16string_view aPassword);
118 
133  static bool IsModifyPasswordCorrect(
134  std::u16string_view aPassword,
135  const css::uno::Sequence< css::beans::PropertyValue >& aInfo );
136 
137 
148  static sal_uInt32 GetWordHashAsUINT32(
149  const OUString& aString );
150 
151 
167  static sal_uInt16 GetXLHashAsUINT16(
168  std::u16string_view aString,
169  rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 );
170 
171 
183  static css::uno::Sequence< sal_Int8 > GetXLHashAsSequence(
184  std::u16string_view aString );
185 
186 
224  static css::uno::Sequence<sal_Int8> GetOoxHashAsSequence(
225  const OUString& rPassword,
226  std::u16string_view rSaltValue,
227  sal_uInt32 nSpinCount,
228  comphelper::Hash::IterCount eIterCount,
229  std::u16string_view rAlgorithmName);
230 
231 
270  static OUString GetOoxHashAsBase64(
271  const OUString& rPassword,
272  std::u16string_view rSaltValue,
273  sal_uInt32 nSpinCount,
274  comphelper::Hash::IterCount eIterCount,
275  std::u16string_view rAlgorithmName);
276 
277 
314  static std::vector<unsigned char> GetOoxHashAsVector(
315  const OUString& rPassword,
316  const std::vector<unsigned char>& rSaltValue,
317  sal_uInt32 nSpinCount,
318  comphelper::Hash::IterCount eIterCount,
319  std::u16string_view rAlgorithmName);
320 
321 
326  static css::uno::Sequence< sal_Int8 > GenerateRandomByteSequence(
327  sal_Int32 nLength );
328 
329 
334  static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
335  const OUString& aPassword,
336  const css::uno::Sequence< sal_Int8 >& aDocId );
337 
338 
343  static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
344  const sal_uInt16 pPassData[16],
345  const css::uno::Sequence< sal_Int8 >& aDocId );
346 
351  static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
352  const sal_uInt16 pPassData[16],
353  const sal_uInt8 pDocId[16] );
354 
355 
409  static css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword(
410  IDocPasswordVerifier& rVerifier,
411  const css::uno::Sequence< css::beans::NamedValue >& rMediaEncData,
412  const OUString& rMediaPassword,
413  const css::uno::Reference< css::task::XInteractionHandler >& rxInteractHandler,
414  const OUString& rDocumentUrl,
415  DocPasswordRequestType eRequestType,
416  const ::std::vector< OUString >* pDefaultPasswords = nullptr,
417  bool* pbIsDefaultPassword = nullptr );
418 
419  static css::uno::Sequence< css::beans::NamedValue > decryptGpgSession(
420  const css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > >& rGpgProperties);
421 
422 private:
424 };
425 
426 
427 } // namespace comphelper
428 
429 #endif
430 
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper that asks for a document password and checks its validity.
DocPasswordRequestType
Selects which UNO document password request type to use.
unsigned char sal_uInt8
Base class for a password verifier used by the DocPasswordHelper class below.
#define COMPHELPER_DLLPUBLIC
sal_Int32 nLength