package/source/zipapi/ZipFile.cxx | 81 +++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 40 deletions(-)
New commits: commit 6e3a6ca0500f38f082dd699802fec367cb559200 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Tue Dec 12 21:07:46 2023 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Wed Dec 13 16:51:28 2023 +0100 package: move function down Change-Id: I92742a28cf60a9dfc80001f9ca3c5551fe94472d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160677 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index f700b2722a71..1b4b7ec2e8f8 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -394,46 +394,6 @@ bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > const & r return bOk; } -uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const rtl::Reference< comphelper::RefCountedMutex >& aMutexHolder, - const uno::Reference< uno::XComponentContext >& rxContext, - const uno::Reference< XInputStream >& xStream, - const ::rtl::Reference< EncryptionData > &rData ) -{ - if ( !rData.is() ) - throw ZipIOException("Encrypted stream without encryption data!" ); - - if ( !rData->m_aKey.hasElements() ) - throw packages::WrongPasswordException(THROW_WHERE ); - - uno::Reference< XSeekable > xSeek( xStream, UNO_QUERY ); - if ( !xSeek.is() ) - throw ZipIOException("The stream must be seekable!" ); - - // if we have a digest, then this file is an encrypted one and we should - // check if we can decrypt it or not - OSL_ENSURE( rData->m_aDigest.hasElements(), "Can't detect password correctness without digest!" ); - if ( rData->m_aDigest.hasElements() ) - { - sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() ); - if ( nSize > n_ConstDigestLength + 32 ) - nSize = n_ConstDigestLength + 32; - - // skip header - xSeek->seek( n_ConstHeaderSize + rData->m_aInitVector.getLength() + - rData->m_aSalt.getLength() + rData->m_aDigest.getLength() ); - - // Only want to read enough to verify the digest - Sequence < sal_Int8 > aReadBuffer ( nSize ); - - xStream->readBytes( aReadBuffer, nSize ); - - if ( !StaticHasValidPassword( rxContext, aReadBuffer, rData ) ) - throw packages::WrongPasswordException(THROW_WHERE ); - } - - return new XUnbufferedStream( aMutexHolder, xStream, rData ); -} - #if 0 // for debugging purposes void CheckSequence( const uno::Sequence< sal_Int8 >& aSequence ) @@ -670,6 +630,47 @@ uno::Reference< XInputStream > ZipFile::createStreamForZipEntry( return xBufStream; } +uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( + const rtl::Reference<comphelper::RefCountedMutex>& rMutexHolder, + const uno::Reference<uno::XComponentContext>& rxContext, + const uno::Reference<XInputStream>& xStream, + const ::rtl::Reference<EncryptionData> &rData) +{ + if (!rData.is()) + throw ZipIOException("Encrypted stream without encryption data!" ); + + if (!rData->m_aKey.hasElements()) + throw packages::WrongPasswordException(THROW_WHERE); + + uno::Reference<XSeekable> xSeek(xStream, UNO_QUERY); + if (!xSeek.is()) + throw ZipIOException("The stream must be seekable!"); + + // if we have a digest, then this file is an encrypted one and we should + // check if we can decrypt it or not + OSL_ENSURE(rData->m_aDigest.hasElements(), "Can't detect password correctness without digest!"); + if (rData->m_aDigest.hasElements()) + { + sal_Int32 nSize = sal::static_int_cast<sal_Int32>(xSeek->getLength()); + if (nSize > n_ConstDigestLength + 32) + nSize = n_ConstDigestLength + 32; + + // skip header + xSeek->seek(n_ConstHeaderSize + rData->m_aInitVector.getLength() + + rData->m_aSalt.getLength() + rData->m_aDigest.getLength()); + + // Only want to read enough to verify the digest + Sequence<sal_Int8> aReadBuffer(nSize); + + xStream->readBytes(aReadBuffer, nSize); + + if (!StaticHasValidPassword(rxContext, aReadBuffer, rData)) + throw packages::WrongPasswordException(THROW_WHERE); + } + + return new XUnbufferedStream(rMutexHolder, xStream, rData); +} + ZipEnumeration ZipFile::entries() { return aEntries;