From 8061c8c70b7ffcd8f472d2f5b909911f2095fec7 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 12 Nov 2013 18:12:26 +0100 Subject: Make requestAndVerifyDocPassword var with MediaDescriptor a mem fn of latter Change-Id: I645d554c7ce592d93ca0696fa7e6068ce40c9058 --- comphelper/source/misc/docpasswordhelper.cxx | 33 +--------------------------- comphelper/source/misc/mediadescriptor.cxx | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 32 deletions(-) (limited to 'comphelper') 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 #include -#include "comphelper/mediadescriptor.hxx" #include #include @@ -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 #include #include #include @@ -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 ); -- cgit