summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comphelper/source/misc/docpasswordhelper.cxx33
-rw-r--r--comphelper/source/misc/mediadescriptor.cxx29
-rw-r--r--include/comphelper/docpasswordhelper.hxx54
-rw-r--r--include/comphelper/mediadescriptor.hxx48
-rw-r--r--oox/source/core/filterdetect.cxx4
5 files changed, 80 insertions, 88 deletions
diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx
index 6f177e68bf2a..9d312a341f58 100644
--- a/comphelper/source/misc/docpasswordhelper.cxx
+++ b/comphelper/source/misc/docpasswordhelper.cxx
@@ -19,8 +19,8 @@
#include "comphelper/docpasswordhelper.hxx"
+#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/task/XInteractionHandler.hpp>
-#include "comphelper/mediadescriptor.hxx"
#include <osl/time.h>
#include <rtl/digest.h>
@@ -412,37 +412,6 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence(
return (eResult == DocPasswordVerifierResult_OK) ? aEncData : uno::Sequence< beans::NamedValue >();
}
-/*static*/ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > DocPasswordHelper::requestAndVerifyDocPassword(
- IDocPasswordVerifier& rVerifier,
- MediaDescriptor& rMediaDesc,
- DocPasswordRequestType eRequestType,
- const ::std::vector< OUString >* pDefaultPasswords )
-{
- uno::Sequence< beans::NamedValue > aMediaEncData = rMediaDesc.getUnpackedValueOrDefault(
- MediaDescriptor::PROP_ENCRYPTIONDATA(), uno::Sequence< beans::NamedValue >() );
- OUString aMediaPassword = rMediaDesc.getUnpackedValueOrDefault(
- MediaDescriptor::PROP_PASSWORD(), OUString() );
- Reference< XInteractionHandler > xInteractHandler = rMediaDesc.getUnpackedValueOrDefault(
- MediaDescriptor::PROP_INTERACTIONHANDLER(), Reference< XInteractionHandler >() );
- OUString aDocumentName = rMediaDesc.getUnpackedValueOrDefault(
- MediaDescriptor::PROP_URL(), OUString() );
-
- bool bIsDefaultPassword = false;
- uno::Sequence< beans::NamedValue > aEncryptionData = requestAndVerifyDocPassword(
- rVerifier, aMediaEncData, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword );
-
- rMediaDesc.erase( MediaDescriptor::PROP_PASSWORD() );
- rMediaDesc.erase( MediaDescriptor::PROP_ENCRYPTIONDATA() );
-
- // insert valid password into media descriptor (but not a default password)
- if( (aEncryptionData.getLength() > 0) && !bIsDefaultPassword )
- rMediaDesc[ MediaDescriptor::PROP_ENCRYPTIONDATA() ] <<= aEncryptionData;
-
- return aEncryptionData;
-}
-
-// ============================================================================
-
} // namespace comphelper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx
index fd2ff28c0e5f..44665c5b956a 100644
--- a/comphelper/source/misc/mediadescriptor.cxx
+++ b/comphelper/source/misc/mediadescriptor.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <comphelper/docpasswordhelper.hxx>
#include <comphelper/mediadescriptor.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/stillreadwriteinteraction.hxx>
@@ -444,6 +445,34 @@ void MediaDescriptor::clearComponentDataEntry( const OUString& rName )
}
}
+::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > MediaDescriptor::requestAndVerifyDocPassword(
+ IDocPasswordVerifier& rVerifier,
+ DocPasswordRequestType eRequestType,
+ const ::std::vector< OUString >* pDefaultPasswords )
+{
+ css::uno::Sequence< css::beans::NamedValue > aMediaEncData = getUnpackedValueOrDefault(
+ PROP_ENCRYPTIONDATA(), css::uno::Sequence< css::beans::NamedValue >() );
+ OUString aMediaPassword = getUnpackedValueOrDefault(
+ PROP_PASSWORD(), OUString() );
+ css::uno::Reference< css::task::XInteractionHandler > xInteractHandler = getUnpackedValueOrDefault(
+ PROP_INTERACTIONHANDLER(), css::uno::Reference< css::task::XInteractionHandler >() );
+ OUString aDocumentName = getUnpackedValueOrDefault(
+ PROP_URL(), OUString() );
+
+ bool bIsDefaultPassword = false;
+ css::uno::Sequence< css::beans::NamedValue > aEncryptionData = DocPasswordHelper::requestAndVerifyDocPassword(
+ rVerifier, aMediaEncData, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword );
+
+ erase( PROP_PASSWORD() );
+ erase( PROP_ENCRYPTIONDATA() );
+
+ // insert valid password into media descriptor (but not a default password)
+ if( (aEncryptionData.getLength() > 0) && !bIsDefaultPassword )
+ (*this)[ PROP_ENCRYPTIONDATA() ] <<= aEncryptionData;
+
+ return aEncryptionData;
+}
+
sal_Bool MediaDescriptor::addInputStream()
{
return impl_addInputStream( sal_True );
diff --git a/include/comphelper/docpasswordhelper.hxx b/include/comphelper/docpasswordhelper.hxx
index 716309840226..8c160fd32e1f 100644
--- a/include/comphelper/docpasswordhelper.hxx
+++ b/include/comphelper/docpasswordhelper.hxx
@@ -30,10 +30,6 @@ namespace com { namespace sun { namespace star { namespace beans { struct Proper
namespace comphelper {
-class MediaDescriptor;
-
-// ============================================================================
-
enum DocPasswordVerifierResult
{
DocPasswordVerifierResult_OK,
@@ -290,56 +286,6 @@ public:
const ::std::vector< OUString >* pDefaultPasswords = 0,
bool* pbIsDefaultPassword = 0 );
- // ------------------------------------------------------------------------
-
- /** This helper function tries to find a password for the document
- described by the passed media descriptor.
-
- First, the list of default passwords will be tried if provided. This is
- needed by import filters for external file formats that have to check a
- predefined password in some cases without asking the user for a
- password. Every password is checked using the passed password verifier.
-
- If not successful, the passed media descriptor is asked for a password,
- that has been set e.g. by an API call to load a document. If existing,
- the password is checked using the passed password verifier.
-
- If still not successful, the interaction handler contained in the
- passed nmedia descriptor is used to request a password from the user.
- This will be repeated until the passed password verifier validates the
- entered password, or if the user chooses to cancel password input.
-
- @param rVerifier
- The password verifier used to check every processed password.
-
- @param rMediaDesc
- The media descriptor of the document that needs to be opened with
- a password. If a valid password (that is not contained in the
- passed list of default passwords) was found, it will be inserted
- into the "Password" property of this descriptor.
-
- @param eRequestType
- The password request type that will be passed to the
- DocPasswordRequest object created internally. See
- docpasswordrequest.hxx for more details.
-
- @param pDefaultPasswords
- If not null, contains default passwords that will be tried before a
- password will be requested from the media descriptor or the user.
-
- @return
- If not empty, contains the password that has been validated by the
- passed password verifier. If empty, no valid password has been
- found, or the user has chossen to cancel password input.
- */
- static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword(
- IDocPasswordVerifier& rVerifier,
- MediaDescriptor& rMediaDesc,
- DocPasswordRequestType eRequestType,
- const ::std::vector< OUString >* pDefaultPasswords = 0 );
-
- // ------------------------------------------------------------------------
-
private:
~DocPasswordHelper();
};
diff --git a/include/comphelper/mediadescriptor.hxx b/include/comphelper/mediadescriptor.hxx
index 3080c496aab2..4cc457e1f5c8 100644
--- a/include/comphelper/mediadescriptor.hxx
+++ b/include/comphelper/mediadescriptor.hxx
@@ -20,6 +20,7 @@
#ifndef INCLUDED_COMPHELPER_MEDIADESCRIPTOR_HXX
#define INCLUDED_COMPHELPER_MEDIADESCRIPTOR_HXX
+#include <comphelper/docpasswordrequest.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <rtl/ustring.hxx>
#include <comphelper/comphelperdllapi.h>
@@ -30,6 +31,8 @@ namespace com { namespace sun { namespace star { namespace io {
namespace comphelper{
+class IDocPasswordVerifier;
+
/** @short can be used to work with a ::com::sun::star::document::MediaDescriptor
struct.
@@ -216,6 +219,51 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
void clearComponentDataEntry(
const OUString& rName );
+ /** This helper function tries to find a password for the document
+ described by this media descriptor.
+
+ First, the list of default passwords will be tried if provided. This
+ is needed by import filters for external file formats that have to
+ check a predefined password in some cases without asking the user
+ for a password. Every password is checked using the passed password
+ verifier.
+
+ If not successful, this media descriptor is asked for a password,
+ that has been set e.g. by an API call to load a document. If
+ existing, the password is checked using the passed password
+ verifier.
+
+ If still not successful, the interaction handler contained in this
+ media descriptor is used to request a password from the user. This
+ will be repeated until the passed password verifier validates the
+ entered password, or if the user chooses to cancel password input.
+
+ If a valid password (that is not contained in the passed list of
+ default passwords) was found, it will be inserted into the
+ "Password" property of this descriptor.
+
+ @param rVerifier
+ The password verifier used to check every processed password.
+
+ @param eRequestType
+ The password request type that will be passed to the
+ DocPasswordRequest object created internally. See
+ docpasswordrequest.hxx for more details.
+
+ @param pDefaultPasswords
+ If not null, contains default passwords that will be tried before a
+ password will be requested from the media descriptor or the user.
+
+ @return
+ If not empty, contains the password that has been validated by the
+ passed password verifier. If empty, no valid password has been
+ found, or the user has chossen to cancel password input.
+ */
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword(
+ IDocPasswordVerifier& rVerifier,
+ DocPasswordRequestType eRequestType,
+ const ::std::vector< OUString >* pDefaultPasswords = 0 );
+
//-------------------------------------------
// helper
private:
diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx
index ffa44a39c56f..2dbb73cd4c43 100644
--- a/oox/source/core/filterdetect.cxx
+++ b/oox/source/core/filterdetect.cxx
@@ -343,8 +343,8 @@ Reference< XInputStream > FilterDetect::extractUnencryptedPackage( MediaDescript
user has cancelled the password input dialog. */
PasswordVerifier aVerifier( aDecryptor );
Sequence<NamedValue> aEncryptionData;
- aEncryptionData = comphelper::DocPasswordHelper::requestAndVerifyDocPassword(
- aVerifier, rMediaDescriptor,
+ aEncryptionData = rMediaDescriptor.requestAndVerifyDocPassword(
+ aVerifier,
comphelper::DocPasswordRequestType_MS,
&aDefaultPasswords );