summaryrefslogtreecommitdiff
path: root/package/source/zipapi
diff options
context:
space:
mode:
Diffstat (limited to 'package/source/zipapi')
-rw-r--r--package/source/zipapi/ByteChucker.cxx115
-rw-r--r--package/source/zipapi/ByteGrabber.cxx194
-rw-r--r--package/source/zipapi/CRC32.cxx98
-rw-r--r--package/source/zipapi/Deflater.cxx216
-rw-r--r--package/source/zipapi/Inflater.cxx165
-rw-r--r--package/source/zipapi/MemoryByteGrabber.hxx180
-rw-r--r--package/source/zipapi/XUnbufferedStream.cxx379
-rw-r--r--package/source/zipapi/XUnbufferedStream.hxx115
-rw-r--r--package/source/zipapi/ZipEnumeration.cxx56
-rw-r--r--package/source/zipapi/ZipFile.cxx1100
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx452
-rw-r--r--package/source/zipapi/blowfishcontext.cxx122
-rw-r--r--package/source/zipapi/blowfishcontext.hxx58
-rw-r--r--package/source/zipapi/makefile.mk62
-rw-r--r--package/source/zipapi/sha1context.cxx97
-rw-r--r--package/source/zipapi/sha1context.hxx59
16 files changed, 0 insertions, 3468 deletions
diff --git a/package/source/zipapi/ByteChucker.cxx b/package/source/zipapi/ByteChucker.cxx
deleted file mode 100644
index 73025fe12..000000000
--- a/package/source/zipapi/ByteChucker.cxx
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <ByteChucker.hxx>
-#include <PackageConstants.hxx>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <com/sun/star/io/XOutputStream.hpp>
-
-using namespace ::com::sun::star::io;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-
-ByteChucker::ByteChucker(Reference<XOutputStream> xOstream)
-: xStream(xOstream)
-, xSeek (xOstream, UNO_QUERY )
-, a1Sequence ( 1 )
-, a2Sequence ( 2 )
-, a4Sequence ( 4 )
-, p1Sequence ( a1Sequence.getArray() )
-, p2Sequence ( a2Sequence.getArray() )
-, p4Sequence ( a4Sequence.getArray() )
-{
-}
-
-ByteChucker::~ByteChucker()
-{
-}
-
-void ByteChucker::WriteBytes( const Sequence< sal_Int8 >& aData )
- throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
-{
- xStream->writeBytes(aData);
-}
-
-sal_Int64 ByteChucker::GetPosition( )
- throw(IOException, RuntimeException)
-{
- return xSeek->getPosition();
-}
-
-ByteChucker& ByteChucker::operator << (sal_Int8 nInt8)
-{
- p1Sequence[0] = nInt8 & 0xFF;
- WriteBytes( a1Sequence );
- return *this;
-}
-
-ByteChucker& ByteChucker::operator << (sal_Int16 nInt16)
-{
- p2Sequence[0] = static_cast< sal_Int8 >((nInt16 >> 0 ) & 0xFF);
- p2Sequence[1] = static_cast< sal_Int8 >((nInt16 >> 8 ) & 0xFF);
- WriteBytes( a2Sequence );
- return *this;
-}
-ByteChucker& ByteChucker::operator << (sal_Int32 nInt32)
-{
- p4Sequence[0] = static_cast< sal_Int8 >((nInt32 >> 0 ) & 0xFF);
- p4Sequence[1] = static_cast< sal_Int8 >((nInt32 >> 8 ) & 0xFF);
- p4Sequence[2] = static_cast< sal_Int8 >((nInt32 >> 16 ) & 0xFF);
- p4Sequence[3] = static_cast< sal_Int8 >((nInt32 >> 24 ) & 0xFF);
- WriteBytes( a4Sequence );
- return *this;
-}
-
-ByteChucker& ByteChucker::operator << (sal_uInt8 nuInt8)
-{
- p1Sequence[0] = nuInt8 & 0xFF;
- WriteBytes( a1Sequence );
- return *this;
-}
-ByteChucker& ByteChucker::operator << (sal_uInt16 nuInt16)
-{
- p2Sequence[0] = static_cast< sal_Int8 >((nuInt16 >> 0 ) & 0xFF);
- p2Sequence[1] = static_cast< sal_Int8 >((nuInt16 >> 8 ) & 0xFF);
- WriteBytes( a2Sequence );
- return *this;
-}
-ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32)
-{
- p4Sequence[0] = static_cast < sal_Int8 > ((nuInt32 >> 0 ) & 0xFF);
- p4Sequence[1] = static_cast < sal_Int8 > ((nuInt32 >> 8 ) & 0xFF);
- p4Sequence[2] = static_cast < sal_Int8 > ((nuInt32 >> 16 ) & 0xFF);
- p4Sequence[3] = static_cast < sal_Int8 > ((nuInt32 >> 24 ) & 0xFF);
- WriteBytes( a4Sequence );
- return *this;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/ByteGrabber.cxx b/package/source/zipapi/ByteGrabber.cxx
deleted file mode 100644
index 34bd9a7ac..000000000
--- a/package/source/zipapi/ByteGrabber.cxx
+++ /dev/null
@@ -1,194 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <ByteGrabber.hxx>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <com/sun/star/io/XInputStream.hpp>
-
-using namespace ::com::sun::star;
-
-/** ByteGrabber implements the >> operators on an XOutputStream. This is
- * potentially quite slow and may need to be optimised
- */
-
-ByteGrabber::ByteGrabber(uno::Reference < io::XInputStream > xIstream)
-: xStream(xIstream)
-, xSeek (xIstream, uno::UNO_QUERY )
-, aSequence ( 4 )
-{
- pSequence = aSequence.getArray();
-}
-
-ByteGrabber::~ByteGrabber()
-{
-}
-
-void ByteGrabber::setInputStream (uno::Reference < io::XInputStream > xNewStream)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- xStream = xNewStream;
- xSeek = uno::Reference < io::XSeekable > (xNewStream, uno::UNO_QUERY);
-}
-
-// XInputStream chained
-sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData,
- sal_Int32 nBytesToRead )
- throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- return xStream->readBytes(aData, nBytesToRead );
-}
-
-// XSeekable chained...
-sal_Int64 SAL_CALL ByteGrabber::seek( sal_Int64 location )
- throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if (xSeek.is() )
- {
- sal_Int64 nLen = xSeek->getLength();
- if ( location < 0 || location > nLen )
- throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
- if (location > nLen )
- location = nLen;
- xSeek->seek( location );
- return location;
- }
- else
- throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
-}
-
-sal_Int64 SAL_CALL ByteGrabber::getPosition( )
- throw(io::IOException, uno::RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if (xSeek.is() )
- return xSeek->getPosition();
- else
- throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
-}
-
-sal_Int64 SAL_CALL ByteGrabber::getLength( )
- throw(io::IOException, uno::RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if (xSeek.is() )
- return xSeek->getLength();
- else
- throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
-}
-
-ByteGrabber& ByteGrabber::operator >> (sal_Int8& rInt8)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if (xStream->readBytes(aSequence,1) != 1)
- rInt8 = 0;
- else
- rInt8 = aSequence[0] & 0xFF;
- return *this;
-}
-
-ByteGrabber& ByteGrabber::operator >> (sal_Int16& rInt16)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if (xStream->readBytes ( aSequence, 2) != 2)
- rInt16 = 0;
- else
- {
- pSequence = aSequence.getConstArray();
- rInt16 = static_cast <sal_Int16>
- ( (pSequence[0] & 0xFF)
- | (pSequence[1] & 0xFF) << 8);
- }
- return *this;
-}
-
-ByteGrabber& ByteGrabber::operator >> (sal_Int32& rInt32)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if (xStream->readBytes(aSequence, 4) != 4)
- rInt32 = 0;
- else
- {
- pSequence = aSequence.getConstArray();
- rInt32 = static_cast < sal_Int32 >
- ( (pSequence[0] & 0xFF)
- | ( pSequence[1] & 0xFF ) << 8
- | ( pSequence[2] & 0xFF ) << 16
- | ( pSequence[3] & 0xFF ) << 24 );
- }
- return *this;
-}
-
-ByteGrabber& ByteGrabber::operator >> (sal_uInt8& rInt8)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if (xStream->readBytes(aSequence,1) != 1)
- rInt8 = 0;
- else
- rInt8 = static_cast < sal_uInt8 > (aSequence[0] & 0xFF );
- return *this;
-}
-ByteGrabber& ByteGrabber::operator >> (sal_uInt16& rInt16)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if (xStream->readBytes(aSequence, 2) != 2)
- rInt16 = 0;
- else
- {
- pSequence = aSequence.getConstArray();
- rInt16 = static_cast <sal_uInt16>
- ( (pSequence[0] & 0xFF)
- | (pSequence[1] & 0xFF) << 8);
- }
- return *this;
-}
-ByteGrabber& ByteGrabber::operator >> (sal_uInt32& ruInt32)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if (xStream->readBytes(aSequence, 4) != 4)
- ruInt32 = 0;
- else
- {
- pSequence = aSequence.getConstArray();
- ruInt32 = static_cast < sal_uInt32 >
- ( (pSequence[0] & 0xFF)
- | ( pSequence[1] & 0xFF ) << 8
- | ( pSequence[2] & 0xFF ) << 16
- | ( pSequence[3] & 0xFF ) << 24 );
- }
- return *this;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/CRC32.cxx b/package/source/zipapi/CRC32.cxx
deleted file mode 100644
index bf2fff6ff..000000000
--- a/package/source/zipapi/CRC32.cxx
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <CRC32.hxx>
-#ifndef _ZLIB_H
-#ifdef SYSTEM_ZLIB
-#include <zlib.h>
-#else
-#include <external/zlib/zlib.h>
-#endif
-#endif
-#include <PackageConstants.hxx>
-#include <com/sun/star/io/XInputStream.hpp>
-
-using namespace com::sun::star::uno;
-using namespace com::sun::star::io;
-
-/** A class to compute the CRC32 value of a data stream
- */
-
-CRC32::CRC32()
-: nCRC(0)
-{
-}
-CRC32::~CRC32()
-{
-}
-void SAL_CALL CRC32::reset()
- throw(RuntimeException)
-{
- nCRC=0;
-}
-sal_Int32 SAL_CALL CRC32::getValue()
- throw(RuntimeException)
-{
- return nCRC & 0xFFFFFFFFL;
-}
-/** Update CRC32 with specified sequence of bytes
- */
-void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b,
- sal_Int32 off,
- sal_Int32 len)
- throw(RuntimeException)
-{
- nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray()+off, len );
-}
-/** Update CRC32 with specified sequence of bytes
- */
-void SAL_CALL CRC32::update(const Sequence< sal_Int8 > &b)
- throw(RuntimeException)
-{
- nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray(),b.getLength());
-}
-
-sal_Int32 SAL_CALL CRC32::updateStream( Reference < XInputStream > & xStream )
- throw ( RuntimeException )
-{
- sal_Int32 nLength, nTotal = 0;
- Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
- do
- {
- nLength = xStream->readBytes ( aSeq, n_ConstBufferSize );
- updateSegment ( aSeq, 0, nLength );
- nTotal += nLength;
- }
- while ( nLength == n_ConstBufferSize );
-
- return nTotal;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/Deflater.cxx b/package/source/zipapi/Deflater.cxx
deleted file mode 100644
index bb48b4ef3..000000000
--- a/package/source/zipapi/Deflater.cxx
+++ /dev/null
@@ -1,216 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <Deflater.hxx>
-#ifndef _ZLIB_H
-#ifdef SYSTEM_ZLIB
-#include <zlib.h>
-#else
-#include <external/zlib/zlib.h>
-#endif
-#endif
-#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <string.h> // for memset
-
-using namespace com::sun::star::packages::zip::ZipConstants;
-using namespace com::sun::star;
-using namespace ZipUtils;
-
-/** Provides general purpose compression using the ZLIB compression
- * library.
- */
-
-Deflater::~Deflater(void)
-{
- end();
-}
-void Deflater::init (sal_Int32 nLevelArg, sal_Int32 nStrategyArg, sal_Bool bNowrap)
-{
- pStream = new z_stream;
- /* Memset it to 0...sets zalloc/zfree/opaque to NULL */
- memset (pStream, 0, sizeof(*pStream));
-
- switch (deflateInit2(pStream, nLevelArg, Z_DEFLATED, bNowrap? -MAX_WBITS : MAX_WBITS,
- DEF_MEM_LEVEL, nStrategyArg))
- {
- case Z_OK:
- break;
- case Z_MEM_ERROR:
- delete pStream;
- break;
- case Z_STREAM_ERROR:
- delete pStream;
- break;
- default:
- break;
- }
-}
-
-Deflater::Deflater(sal_Int32 nSetLevel, sal_Bool bNowrap)
-: bFinish(sal_False)
-, bFinished(sal_False)
-, bSetParams(sal_False)
-, nLevel(nSetLevel)
-, nStrategy(DEFAULT_STRATEGY)
-, nOffset(0)
-, nLength(0)
-{
- init(nSetLevel, DEFAULT_STRATEGY, bNowrap);
-}
-
-sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength)
-{
- sal_Int32 nResult;
- if (bSetParams)
- {
- pStream->next_in = (unsigned char*) sInBuffer.getConstArray() + nOffset;
- pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset;
- pStream->avail_in = nLength;
- pStream->avail_out = nNewLength;
-
-#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX
- nResult = deflateParams(pStream, nLevel, nStrategy);
-#else
- nResult = z_deflateParams(pStream, nLevel, nStrategy);
-#endif
- switch (nResult)
- {
- case Z_OK:
- bSetParams = sal_False;
- nOffset += nLength - pStream->avail_in;
- nLength = pStream->avail_in;
- return nNewLength - pStream->avail_out;
- case Z_BUF_ERROR:
- bSetParams = sal_False;
- return 0;
- default:
- return 0;
- }
- }
- else
- {
- pStream->next_in = (unsigned char*) sInBuffer.getConstArray() + nOffset;
- pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset;
- pStream->avail_in = nLength;
- pStream->avail_out = nNewLength;
-
-#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX
- nResult = deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH);
-#else
- nResult = z_deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH);
-#endif
- switch (nResult)
- {
- case Z_STREAM_END:
- bFinished = sal_True;
- case Z_OK:
- nOffset += nLength - pStream->avail_in;
- nLength = pStream->avail_in;
- return nNewLength - pStream->avail_out;
- case Z_BUF_ERROR:
- bSetParams = sal_False;
- return 0;
- default:
- return 0;
- }
- }
-}
-
-void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
-{
- OSL_ASSERT( !(nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()));
-
- sInBuffer = rBuffer;
- nOffset = nNewOffset;
- nLength = nNewLength;
-}
-void SAL_CALL Deflater::setLevel( sal_Int32 nNewLevel )
-{
- if ((nNewLevel < 0 || nNewLevel > 9) && nNewLevel != DEFAULT_COMPRESSION)
- {
- // do error handling
- }
- if (nNewLevel != nLevel)
- {
- nLevel = nNewLevel;
- bSetParams = sal_True;
- }
-}
-sal_Bool SAL_CALL Deflater::needsInput( )
-{
- return nLength <=0;
-}
-void SAL_CALL Deflater::finish( )
-{
- bFinish = sal_True;
-}
-sal_Bool SAL_CALL Deflater::finished( )
-{
- return bFinished;
-}
-sal_Int32 SAL_CALL Deflater::doDeflateSegment( uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
-{
- OSL_ASSERT( !(nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()));
- return doDeflateBytes(rBuffer, nNewOffset, nNewLength);
-}
-sal_Int32 SAL_CALL Deflater::getTotalIn( )
-{
- return pStream->total_in;
-}
-sal_Int32 SAL_CALL Deflater::getTotalOut( )
-{
- return pStream->total_out;
-}
-void SAL_CALL Deflater::reset( )
-{
-#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIXB
- deflateReset(pStream);
-#else
- z_deflateReset(pStream);
-#endif
- bFinish = sal_False;
- bFinished = sal_False;
- nOffset = nLength = 0;
-}
-void SAL_CALL Deflater::end( )
-{
- if (pStream != NULL)
- {
-#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX
- deflateEnd(pStream);
-#else
- z_deflateEnd(pStream);
-#endif
- delete pStream;
- }
- pStream = NULL;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/Inflater.cxx b/package/source/zipapi/Inflater.cxx
deleted file mode 100644
index a340caa05..000000000
--- a/package/source/zipapi/Inflater.cxx
+++ /dev/null
@@ -1,165 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <Inflater.hxx>
-#ifndef _ZLIB_H
-#ifdef SYSTEM_ZLIB
-#include <zlib.h>
-#else
-#include <external/zlib/zlib.h>
-#endif
-#endif
-#include <string.h> // for memset
-
-using namespace com::sun::star::uno;
-using namespace ZipUtils;
-
-/** Provides general purpose decompression using the ZLIB library */
-
-Inflater::Inflater(sal_Bool bNoWrap)
-: bFinished(sal_False),
- bSetParams(sal_False),
- bNeedDict(sal_False),
- nOffset(0),
- nLength(0),
- nLastInflateError(0),
- pStream(NULL)
-{
- pStream = new z_stream;
- /* memset to 0 to set zalloc/opaque etc */
- memset (pStream, 0, sizeof(*pStream));
- sal_Int32 nRes;
- nRes = inflateInit2(pStream, bNoWrap ? -MAX_WBITS : MAX_WBITS);
- switch (nRes)
- {
- case Z_OK:
- break;
- case Z_MEM_ERROR:
- delete pStream;
- break;
- case Z_STREAM_ERROR:
- delete pStream;
- break;
- default:
- break;
- }
-}
-
-Inflater::~Inflater()
-{
- end();
-}
-
-void SAL_CALL Inflater::setInput( const Sequence< sal_Int8 >& rBuffer )
-{
- sInBuffer = rBuffer;
- nOffset = 0;
- nLength = rBuffer.getLength();
-}
-
-sal_Bool SAL_CALL Inflater::needsDictionary( )
-{
- return bNeedDict;
-}
-
-sal_Bool SAL_CALL Inflater::finished( )
-{
- return bFinished;
-}
-
-sal_Int32 SAL_CALL Inflater::doInflateSegment( Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
-{
- if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength())
- {
- // do error handling
- }
- return doInflateBytes(rBuffer, nNewOffset, nNewLength);
-}
-
-void SAL_CALL Inflater::end( )
-{
- if (pStream != NULL)
- {
-#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX
- inflateEnd(pStream);
-#else
- z_inflateEnd(pStream);
-#endif
- delete pStream;
- }
- pStream = NULL;
-}
-
-sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength)
-{
- if ( !pStream )
- {
- nLastInflateError = Z_STREAM_ERROR;
- return 0;
- }
-
- nLastInflateError = 0;
-
- pStream->next_in = ( unsigned char* ) ( sInBuffer.getConstArray() + nOffset );
- pStream->avail_in = nLength;
- pStream->next_out = reinterpret_cast < unsigned char* > ( rBuffer.getArray() + nNewOffset );
- pStream->avail_out = nNewLength;
-
-#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX
- sal_Int32 nResult = ::inflate(pStream, Z_PARTIAL_FLUSH);
-#else
- sal_Int32 nResult = ::z_inflate(pStream, Z_PARTIAL_FLUSH);
-#endif
-
- switch (nResult)
- {
- case Z_STREAM_END:
- bFinished = sal_True;
- case Z_OK:
- nOffset += nLength - pStream->avail_in;
- nLength = pStream->avail_in;
- return nNewLength - pStream->avail_out;
-
- case Z_NEED_DICT:
- bNeedDict = sal_True;
- nOffset += nLength - pStream->avail_in;
- nLength = pStream->avail_in;
- return 0;
-
- default:
- // it is no error, if there is no input or no output
- if ( nLength && nNewLength )
- nLastInflateError = nResult;
- }
-
- return 0;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/MemoryByteGrabber.hxx b/package/source/zipapi/MemoryByteGrabber.hxx
deleted file mode 100644
index b2eec4049..000000000
--- a/package/source/zipapi/MemoryByteGrabber.hxx
+++ /dev/null
@@ -1,180 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-#ifndef _MEMORY_BYTE_GRABBER_HXX_
-#define _MEMORY_BYTE_GRABBER_HXX_
-
-#include <com/sun/star/io/XInputStream.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <string.h>
-
-class MemoryByteGrabber
-{
-protected:
- const com::sun::star::uno::Sequence < sal_Int8 > maBuffer;
- const sal_Int8 *mpBuffer;
- sal_Int32 mnCurrent, mnEnd;
-public:
- MemoryByteGrabber ( const com::sun::star::uno::Sequence < sal_Int8 > & rBuffer )
- : maBuffer ( rBuffer )
- , mpBuffer ( rBuffer.getConstArray() )
- , mnCurrent ( 0 )
- , mnEnd ( rBuffer.getLength() )
- {
- }
- MemoryByteGrabber()
- {
- }
- const sal_Int8 * getCurrentPos () { return mpBuffer + mnCurrent; }
-
- // XInputStream chained
- sal_Int32 SAL_CALL readBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData,
- sal_Int32 nBytesToRead )
- throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- if ( nBytesToRead < 0)
- throw com::sun::star::io::BufferSizeExceededException();
-
- if (nBytesToRead + mnCurrent > mnEnd)
- nBytesToRead = mnEnd - mnCurrent;
-
- aData.realloc ( nBytesToRead );
- rtl_copyMemory( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead );
- mnCurrent += nBytesToRead;
- return nBytesToRead;
- }
-
- sal_Int32 SAL_CALL readSomeBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData,
- sal_Int32 nMaxBytesToRead )
- throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- return readBytes( aData, nMaxBytesToRead );
- }
- void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
- throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- mnCurrent += nBytesToSkip;
- }
- sal_Int32 SAL_CALL available( )
- throw(com::sun::star::io::NotConnectedException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- return mnEnd - mnCurrent;
- }
- void SAL_CALL closeInput( )
- throw(com::sun::star::io::NotConnectedException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- }
-
- // XSeekable chained...
- sal_Int64 SAL_CALL seek( sal_Int64 location )
- throw(com::sun::star::lang::IllegalArgumentException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- if ( location < 0 || location > mnEnd )
- throw com::sun::star::lang::IllegalArgumentException ();
- mnCurrent = static_cast < sal_Int32 > ( location );
- return mnCurrent;
- }
- sal_Int64 SAL_CALL getPosition( )
- throw(com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- return mnCurrent;
- }
- sal_Int64 SAL_CALL getLength( )
- throw(com::sun::star::io::IOException, com::sun::star::uno::RuntimeException)
- {
- return mnEnd;
- }
- MemoryByteGrabber& operator >> (sal_Int8& rInt8)
- {
- if (mnCurrent + 1 > mnEnd )
- rInt8 = 0;
- else
- rInt8 = mpBuffer [mnCurrent++] & 0xFF;
- return *this;
- }
- MemoryByteGrabber& operator >> (sal_Int16& rInt16)
- {
- if (mnCurrent + 2 > mnEnd )
- rInt16 = 0;
- else
- {
- rInt16 = mpBuffer[mnCurrent++] & 0xFF;
- rInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
- }
- return *this;
- }
- MemoryByteGrabber& operator >> (sal_Int32& rInt32)
- {
- if (mnCurrent + 4 > mnEnd )
- rInt32 = 0;
- else
- {
- rInt32 = mpBuffer[mnCurrent++] & 0xFF;
- rInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
- rInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 16;
- rInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 24;
- }
- return *this;
- }
-
- MemoryByteGrabber& operator >> (sal_uInt8& rInt8)
- {
- if (mnCurrent + 1 > mnEnd )
- rInt8 = 0;
- else
- rInt8 = mpBuffer [mnCurrent++] & 0xFF;
- return *this;
- }
- MemoryByteGrabber& operator >> (sal_uInt16& rInt16)
- {
- if (mnCurrent + 2 > mnEnd )
- rInt16 = 0;
- else
- {
- rInt16 = mpBuffer [mnCurrent++] & 0xFF;
- rInt16 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8;
- }
- return *this;
- }
- MemoryByteGrabber& operator >> (sal_uInt32& rInt32)
- {
- if (mnCurrent + 4 > mnEnd )
- rInt32 = 0;
- else
- {
- rInt32 = mpBuffer [mnCurrent++] & 0xFF;
- rInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8;
- rInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 16;
- rInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 24;
- }
- return *this;
- }
-};
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx
deleted file mode 100644
index a6049fd2c..000000000
--- a/package/source/zipapi/XUnbufferedStream.cxx
+++ /dev/null
@@ -1,379 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-
-#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <com/sun/star/packages/zip/ZipIOException.hpp>
-#include <com/sun/star/xml/crypto/CipherID.hpp>
-
-#include <XUnbufferedStream.hxx>
-#include <EncryptionData.hxx>
-#include <PackageConstants.hxx>
-#include <ZipFile.hxx>
-#include <EncryptedDataHeader.hxx>
-#include <algorithm>
-#include <string.h>
-
-#include <osl/mutex.hxx>
-
-#if 0
-// for debugging purposes here
-#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
-#include <comphelper/processfactory.hxx>
-using namespace ::com::sun::star;
-#endif
-
-using namespace ::com::sun::star;
-using namespace com::sun::star::packages::zip::ZipConstants;
-using namespace com::sun::star::io;
-using namespace com::sun::star::uno;
-using com::sun::star::lang::IllegalArgumentException;
-using com::sun::star::packages::zip::ZipIOException;
-using ::rtl::OUString;
-
-XUnbufferedStream::XUnbufferedStream(
- const uno::Reference< lang::XMultiServiceFactory >& xFactory,
- SotMutexHolderRef aMutexHolder,
- ZipEntry & rEntry,
- Reference < XInputStream > xNewZipStream,
- const ::rtl::Reference< EncryptionData >& rData,
- sal_Int8 nStreamMode,
- sal_Bool bIsEncrypted,
- const ::rtl::OUString& aMediaType,
- sal_Bool bRecoveryMode )
-: maMutexHolder( aMutexHolder.Is() ? aMutexHolder : SotMutexHolderRef( new SotMutexHolder ) )
-, mxZipStream ( xNewZipStream )
-, mxZipSeek ( xNewZipStream, UNO_QUERY )
-, maEntry ( rEntry )
-, mxData ( rData )
-, mnBlockSize( 1 )
-, maInflater ( sal_True )
-, mbRawStream ( nStreamMode == UNBUFF_STREAM_RAW || nStreamMode == UNBUFF_STREAM_WRAPPEDRAW )
-, mbWrappedRaw ( nStreamMode == UNBUFF_STREAM_WRAPPEDRAW )
-, mbFinished ( sal_False )
-, mnHeaderToRead ( 0 )
-, mnZipCurrent ( 0 )
-, mnZipEnd ( 0 )
-, mnZipSize ( 0 )
-, mnMyCurrent ( 0 )
-, mbCheckCRC( !bRecoveryMode )
-{
- mnZipCurrent = maEntry.nOffset;
- if ( mbRawStream )
- {
- mnZipSize = maEntry.nMethod == DEFLATED ? maEntry.nCompressedSize : maEntry.nSize;
- mnZipEnd = maEntry.nOffset + mnZipSize;
- }
- else
- {
- mnZipSize = maEntry.nSize;
- mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize;
- }
- sal_Bool bHaveEncryptData = ( rData.is() && rData->m_aSalt.getLength() && rData->m_aInitVector.getLength() && rData->m_nIterationCount != 0 ) ? sal_True : sal_False;
- sal_Bool bMustDecrypt = ( nStreamMode == UNBUFF_STREAM_DATA && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False;
-
- if ( bMustDecrypt )
- {
- m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false );
- mnBlockSize = ( rData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 1 );
- }
-
- if ( bHaveEncryptData && mbWrappedRaw && bIsEncrypted )
- {
- // if we have the data needed to decrypt it, but didn't want it decrypted (or
- // we couldn't decrypt it due to wrong password), then we prepend this
- // data to the stream
-
- // Make a buffer big enough to hold both the header and the data itself
- maHeader.realloc ( n_ConstHeaderSize +
- rData->m_aInitVector.getLength() +
- rData->m_aSalt.getLength() +
- rData->m_aDigest.getLength() +
- aMediaType.getLength() * sizeof( sal_Unicode ) );
- sal_Int8 * pHeader = maHeader.getArray();
- ZipFile::StaticFillHeader( rData, rEntry.nSize, aMediaType, pHeader );
- mnHeaderToRead = static_cast < sal_Int16 > ( maHeader.getLength() );
- }
-}
-
-// allows to read package raw stream
-XUnbufferedStream::XUnbufferedStream(
- const uno::Reference< lang::XMultiServiceFactory >& /*xFactory*/,
- const Reference < XInputStream >& xRawStream,
- const ::rtl::Reference< EncryptionData >& rData )
-: maMutexHolder( new SotMutexHolder )
-, mxZipStream ( xRawStream )
-, mxZipSeek ( xRawStream, UNO_QUERY )
-, mxData ( rData )
-, mnBlockSize( 1 )
-, maInflater ( sal_True )
-, mbRawStream ( sal_False )
-, mbWrappedRaw ( sal_False )
-, mbFinished ( sal_False )
-, mnHeaderToRead ( 0 )
-, mnZipCurrent ( 0 )
-, mnZipEnd ( 0 )
-, mnZipSize ( 0 )
-, mnMyCurrent ( 0 )
-, mbCheckCRC( sal_False )
-{
- // for this scenario maEntry is not set !!!
- OSL_ENSURE( mxZipSeek.is(), "The stream must be seekable!\n" );
-
- // skip raw header, it must be already parsed to rData
- mnZipCurrent = n_ConstHeaderSize + rData->m_aInitVector.getLength() +
- rData->m_aSalt.getLength() + rData->m_aDigest.getLength();
-
- try {
- if ( mxZipSeek.is() )
- mnZipSize = mxZipSeek->getLength();
- } catch( Exception& )
- {
- // in case of problem the size will stay set to 0
- }
-
- mnZipEnd = mnZipCurrent + mnZipSize;
-
- // the raw data will not be decrypted, no need for the cipher
- // m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false );
-}
-
-XUnbufferedStream::~XUnbufferedStream()
-{
-}
-
-sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
- throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
-{
- ::osl::MutexGuard aGuard( maMutexHolder->GetMutex() );
-
- sal_Int32 nRequestedBytes = nBytesToRead;
- OSL_ENSURE( !mnHeaderToRead || mbWrappedRaw, "Only encrypted raw stream can be provided with header!" );
- if ( mnMyCurrent + nRequestedBytes > mnZipSize + maHeader.getLength() )
- nRequestedBytes = static_cast < sal_Int32 > ( mnZipSize + maHeader.getLength() - mnMyCurrent );
-
- sal_Int32 nTotal = 0;
- aData.realloc ( nRequestedBytes );
- if ( nRequestedBytes )
- {
- sal_Int32 nRead = 0;
- sal_Int32 nLastRead = 0;
- if ( mbRawStream )
- {
- sal_Int64 nDiff = mnZipEnd - mnZipCurrent;
-
- if ( mbWrappedRaw && mnHeaderToRead )
- {
- sal_Int16 nHeadRead = static_cast< sal_Int16 >(( nRequestedBytes > mnHeaderToRead ?
- mnHeaderToRead : nRequestedBytes ));
- rtl_copyMemory ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead );
- mnHeaderToRead = mnHeaderToRead - nHeadRead;
-
- if ( nHeadRead < nRequestedBytes )
- {
- sal_Int32 nToRead = nRequestedBytes - nHeadRead;
- nToRead = ( nDiff < nToRead ) ? sal::static_int_cast< sal_Int32 >( nDiff ) : nToRead;
-
- Sequence< sal_Int8 > aPureData( nToRead );
- mxZipSeek->seek ( mnZipCurrent );
- nRead = mxZipStream->readBytes ( aPureData, nToRead );
- mnZipCurrent += nRead;
-
- aPureData.realloc( nRead );
- if ( mbCheckCRC )
- maCRC.update( aPureData );
-
- aData.realloc( nHeadRead + nRead );
-
- sal_Int8* pPureBuffer = aPureData.getArray();
- sal_Int8* pBuffer = aData.getArray();
- for ( sal_Int32 nInd = 0; nInd < nRead; nInd++ )
- pBuffer[ nHeadRead + nInd ] = pPureBuffer[ nInd ];
- }
-
- nRead += nHeadRead;
- }
- else
- {
- mxZipSeek->seek ( mnZipCurrent );
-
- nRead = mxZipStream->readBytes (
- aData,
- static_cast < sal_Int32 > ( nDiff < nRequestedBytes ? nDiff : nRequestedBytes ) );
-
- mnZipCurrent += nRead;
-
- aData.realloc( nRead );
- if ( mbWrappedRaw && mbCheckCRC )
- maCRC.update( aData );
- }
- }
- else
- {
- while ( 0 == ( nLastRead = maInflater.doInflateSegment( aData, nRead, aData.getLength() - nRead ) ) ||
- ( nRead + nLastRead != nRequestedBytes && mnZipCurrent < mnZipEnd ) )
- {
- nRead += nLastRead;
-
- if ( nRead > nRequestedBytes )
- throw RuntimeException(
- OUString( RTL_CONSTASCII_USTRINGPARAM( "Should not be possible to read more then requested!" ) ),
- Reference< XInterface >() );
-
- if ( maInflater.finished() || maInflater.getLastInflateError() )
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ),
- Reference< XInterface >() );
-
- if ( maInflater.needsDictionary() )
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "Dictionaries are not supported!" ) ),
- Reference< XInterface >() );
-
- sal_Int32 nDiff = static_cast< sal_Int32 >( mnZipEnd - mnZipCurrent );
- if ( nDiff > 0 )
- {
- mxZipSeek->seek ( mnZipCurrent );
-
- sal_Int32 nToRead = std::max( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) );
- if ( mnBlockSize > 1 )
- nToRead = nToRead + mnBlockSize - nToRead % mnBlockSize;
- nToRead = std::min( nDiff, nToRead );
-
- sal_Int32 nZipRead = mxZipStream->readBytes( maCompBuffer, nToRead );
- if ( nZipRead < nToRead )
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "No expected data!" ) ),
- Reference< XInterface >() );
-
- mnZipCurrent += nZipRead;
- // maCompBuffer now has the data, check if we need to decrypt
- // before passing to the Inflater
- if ( m_xCipherContext.is() )
- {
- if ( mbCheckCRC )
- maCRC.update( maCompBuffer );
-
- maCompBuffer = m_xCipherContext->convertWithCipherContext( maCompBuffer );
- if ( mnZipCurrent == mnZipEnd )
- {
- uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose();
- if ( aSuffix.getLength() )
- {
- sal_Int32 nOldLen = maCompBuffer.getLength();
- maCompBuffer.realloc( nOldLen + aSuffix.getLength() );
- rtl_copyMemory( maCompBuffer.getArray() + nOldLen, aSuffix.getConstArray(), aSuffix.getLength() );
- }
- }
- }
- maInflater.setInput ( maCompBuffer );
- }
- else
- {
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ),
- Reference< XInterface >() );
- }
- }
- }
-
- mnMyCurrent += nRead + nLastRead;
- nTotal = nRead + nLastRead;
- if ( nTotal < nRequestedBytes)
- aData.realloc ( nTotal );
-
- if ( mbCheckCRC && ( !mbRawStream || mbWrappedRaw ) )
- {
- if ( !m_xCipherContext.is() && !mbWrappedRaw )
- maCRC.update( aData );
-
-#if 0
- // for debugging purposes here
- if ( mbWrappedRaw )
- {
- if ( 0 )
- {
- uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
- uno::Reference< ucb::XSimpleFileAccess > xAccess( xFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), uno::UNO_QUERY );
- uno::Reference< io::XOutputStream > xOut = xAccess->openFileWrite(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "file:///d:/777/Encrypted/picture") ) );
- xOut->writeBytes( aData );
- xOut->closeOutput();
- }
- }
-#endif
-
- if ( mnZipSize + maHeader.getLength() == mnMyCurrent && maCRC.getValue() != maEntry.nCrc )
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ),
- Reference< XInterface >() );
- }
- }
-
- return nTotal;
-}
-
-sal_Int32 SAL_CALL XUnbufferedStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
- throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
-{
- return readBytes ( aData, nMaxBytesToRead );
-}
-void SAL_CALL XUnbufferedStream::skipBytes( sal_Int32 nBytesToSkip )
- throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
-{
- if ( nBytesToSkip )
- {
- Sequence < sal_Int8 > aSequence ( nBytesToSkip );
- readBytes ( aSequence, nBytesToSkip );
- }
-}
-
-sal_Int32 SAL_CALL XUnbufferedStream::available( )
- throw( NotConnectedException, IOException, RuntimeException)
-{
- return static_cast < sal_Int32 > ( mnZipSize - mnMyCurrent );
-}
-
-void SAL_CALL XUnbufferedStream::closeInput( )
- throw( NotConnectedException, IOException, RuntimeException)
-{
-}
-/*
-void SAL_CALL XUnbufferedStream::seek( sal_Int64 location )
- throw( IllegalArgumentException, IOException, RuntimeException)
-{
-}
-sal_Int64 SAL_CALL XUnbufferedStream::getPosition( )
- throw(IOException, RuntimeException)
-{
- return mnMyCurrent;
-}
-sal_Int64 SAL_CALL XUnbufferedStream::getLength( )
- throw(IOException, RuntimeException)
-{
- return mnZipSize;
-}
-*/
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/XUnbufferedStream.hxx b/package/source/zipapi/XUnbufferedStream.hxx
deleted file mode 100644
index c0e8fc5f9..000000000
--- a/package/source/zipapi/XUnbufferedStream.hxx
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-#ifndef _XUNBUFFERED_STREAM_HXX
-#define _XUNBUFFERED_STREAM_HXX
-
-#include <com/sun/star/lang/IllegalArgumentException.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <com/sun/star/io/XInputStream.hpp>
-#include <com/sun/star/io/XOutputStream.hpp>
-#include <com/sun/star/xml/crypto/XCipherContext.hpp>
-
-#include <cppuhelper/implbase1.hxx>
-#include <rtl/ref.hxx>
-#include <Inflater.hxx>
-#include <ZipEntry.hxx>
-#include <CRC32.hxx>
-#include <mutexholder.hxx>
-
-#define UNBUFF_STREAM_DATA 0
-#define UNBUFF_STREAM_RAW 1
-#define UNBUFF_STREAM_WRAPPEDRAW 2
-
-class EncryptionData;
-class XUnbufferedStream : public cppu::WeakImplHelper1
-<
- com::sun::star::io::XInputStream
->
-{
-protected:
- SotMutexHolderRef maMutexHolder;
-
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxZipStream;
- com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek;
- com::sun::star::uno::Sequence < sal_Int8 > maCompBuffer, maHeader;
- ZipEntry maEntry;
- ::rtl::Reference< EncryptionData > mxData;
- sal_Int32 mnBlockSize;
- ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
- ZipUtils::Inflater maInflater;
- sal_Bool mbRawStream, mbWrappedRaw, mbFinished;
- sal_Int16 mnHeaderToRead;
- sal_Int64 mnZipCurrent, mnZipEnd, mnZipSize, mnMyCurrent;
- CRC32 maCRC;
- sal_Bool mbCheckCRC;
-
-public:
- XUnbufferedStream(
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
- SotMutexHolderRef aMutexHolder,
- ZipEntry & rEntry,
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream,
- const ::rtl::Reference< EncryptionData >& rData,
- sal_Int8 nStreamMode,
- sal_Bool bIsEncrypted,
- const ::rtl::OUString& aMediaType,
- sal_Bool bRecoveryMode );
-
- // allows to read package raw stream
- XUnbufferedStream(
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
- const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream,
- const ::rtl::Reference< EncryptionData >& rData );
-
-
- virtual ~XUnbufferedStream();
-
- // XInputStream
- virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int32 SAL_CALL available( )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL closeInput( )
- throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- // XSeekable
- /*
- virtual void SAL_CALL seek( sal_Int64 location )
- throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int64 SAL_CALL getPosition( )
- throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- virtual sal_Int64 SAL_CALL getLength( )
- throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
- */
-};
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/ZipEnumeration.cxx b/package/source/zipapi/ZipEnumeration.cxx
deleted file mode 100644
index 45ac260ea..000000000
--- a/package/source/zipapi/ZipEnumeration.cxx
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-#include <ZipEnumeration.hxx>
-
-/** Provides an Enumeration over the contents of a Zip file */
-
-ZipEnumeration::ZipEnumeration( EntryHash & rNewEntryHash)
-: rEntryHash(rNewEntryHash)
-, aIterator(rEntryHash.begin())
-{
-}
-ZipEnumeration::~ZipEnumeration( void )
-{
-}
-sal_Bool SAL_CALL ZipEnumeration::hasMoreElements()
-{
- return (aIterator != rEntryHash.end());
-}
-
-const ZipEntry* SAL_CALL ZipEnumeration::nextElement()
-{
- if (aIterator != rEntryHash.end())
- return &((*aIterator++).second);
- else
- return NULL;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
deleted file mode 100644
index 91ffb4264..000000000
--- a/package/source/zipapi/ZipFile.cxx
+++ /dev/null
@@ -1,1100 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/ucb/XProgressHandler.hpp>
-#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <com/sun/star/xml/crypto/XCipherContext.hpp>
-#include <com/sun/star/xml/crypto/XDigestContext.hpp>
-#include <com/sun/star/xml/crypto/XCipherContextSupplier.hpp>
-#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp>
-#include <com/sun/star/xml/crypto/CipherID.hpp>
-#include <com/sun/star/xml/crypto/DigestID.hpp>
-
-#include <comphelper/storagehelper.hxx>
-#include <comphelper/processfactory.hxx>
-#include <rtl/digest.h>
-
-#include <vector>
-
-#include "blowfishcontext.hxx"
-#include "sha1context.hxx"
-#include <ZipFile.hxx>
-#include <ZipEnumeration.hxx>
-#include <XUnbufferedStream.hxx>
-#include <PackageConstants.hxx>
-#include <EncryptedDataHeader.hxx>
-#include <EncryptionData.hxx>
-#include <MemoryByteGrabber.hxx>
-
-#include <CRC32.hxx>
-
-#define AES_CBC_BLOCK_SIZE 16
-
-using namespace com::sun::star;
-using namespace com::sun::star::io;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::ucb;
-using namespace com::sun::star::lang;
-using namespace com::sun::star::packages;
-using namespace com::sun::star::packages::zip;
-using namespace com::sun::star::packages::zip::ZipConstants;
-
-using rtl::OUString;
-using ZipUtils::Inflater;
-
-/** This class is used to read entries from a zip file
- */
-ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise )
- throw(IOException, ZipException, RuntimeException)
-: aGrabber(xInput)
-, aInflater (sal_True)
-, xStream(xInput)
-, xSeek(xInput, UNO_QUERY)
-, m_xFactory ( xNewFactory )
-, bRecoveryMode( sal_False )
-{
- if (bInitialise)
- {
- if ( readCEN() == -1 )
- {
- aEntries.clear();
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () );
- }
- }
-}
-
-
-
-ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, uno::Reference < XProgressHandler > xProgress )
- throw(IOException, ZipException, RuntimeException)
-: aGrabber(xInput)
-, aInflater (sal_True)
-, xStream(xInput)
-, xSeek(xInput, UNO_QUERY)
-, m_xFactory ( xNewFactory )
-, xProgressHandler( xProgress )
-, bRecoveryMode( bForceRecovery )
-{
- if (bInitialise)
- {
- if ( bForceRecovery )
- {
- recover();
- }
- else if ( readCEN() == -1 )
- {
- aEntries.clear();
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () );
- }
- }
-}
-
-ZipFile::~ZipFile()
-{
- aEntries.clear();
-}
-
-void ZipFile::setInputStream ( uno::Reference < XInputStream > xNewStream )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- xStream = xNewStream;
- xSeek = uno::Reference < XSeekable > ( xStream, UNO_QUERY );
- aGrabber.setInputStream ( xStream );
-}
-
-uno::Reference< xml::crypto::XDigestContext > ZipFile::StaticGetDigestContextForChecksum( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData )
-{
- uno::Reference< xml::crypto::XDigestContext > xDigestContext;
- if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA256_1K )
- {
- uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory;
- if ( !xFactory.is() )
- xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
-
- uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier(
- xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ),
- uno::UNO_QUERY_THROW );
-
- xDigestContext.set( xDigestContextSupplier->getDigestContext( xEncryptionData->m_nCheckAlg, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW );
- }
- else if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA1_1K )
- xDigestContext.set( SHA1DigestContext::Create(), uno::UNO_SET_THROW );
-
- return xDigestContext;
-}
-
-uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData, bool bEncrypt )
-{
- uno::Reference< xml::crypto::XCipherContext > xResult;
-
- try
- {
- uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize );
- if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ),
- aDerivedKey.getLength(),
- reinterpret_cast< const sal_uInt8 * > (xEncryptionData->m_aKey.getConstArray() ),
- xEncryptionData->m_aKey.getLength(),
- reinterpret_cast< const sal_uInt8 * > ( xEncryptionData->m_aSalt.getConstArray() ),
- xEncryptionData->m_aSalt.getLength(),
- xEncryptionData->m_nIterationCount ) )
- {
- throw ZipIOException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not create derived key!") ),
- uno::Reference< XInterface >() );
- }
-
- if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING )
- {
- uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory;
- if ( !xFactory.is() )
- xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
-
- uno::Reference< xml::crypto::XCipherContextSupplier > xCipherContextSupplier(
- xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ),
- uno::UNO_QUERY_THROW );
-
- xResult = xCipherContextSupplier->getCipherContext( xEncryptionData->m_nEncAlg, aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt, uno::Sequence< beans::NamedValue >() );
- }
- else if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::BLOWFISH_CFB_8 )
- {
- xResult = BlowfishCFB8CipherContext::Create( aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt );
- }
- else
- {
- throw ZipIOException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown cipher algorithm is requested!") ),
- uno::Reference< XInterface >() );
- }
- }
- catch( uno::Exception& )
- {
- OSL_ENSURE( sal_False, "Can not create cipher context!" );
- }
-
- return xResult;
-}
-
-void ZipFile::StaticFillHeader( const ::rtl::Reference< EncryptionData >& rData,
- sal_Int32 nSize,
- const ::rtl::OUString& aMediaType,
- sal_Int8 * & pHeader )
-{
- // I think it's safe to restrict vector and salt length to 2 bytes !
- sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->m_aInitVector.getLength() );
- sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->m_aSalt.getLength() );
- sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->m_aDigest.getLength() );
- sal_Int16 nMediaTypeLength = static_cast < sal_Int16 > ( aMediaType.getLength() * sizeof( sal_Unicode ) );
-
- // First the header
- *(pHeader++) = ( n_ConstHeader >> 0 ) & 0xFF;
- *(pHeader++) = ( n_ConstHeader >> 8 ) & 0xFF;
- *(pHeader++) = ( n_ConstHeader >> 16 ) & 0xFF;
- *(pHeader++) = ( n_ConstHeader >> 24 ) & 0xFF;
-
- // Then the version
- *(pHeader++) = ( n_ConstCurrentVersion >> 0 ) & 0xFF;
- *(pHeader++) = ( n_ConstCurrentVersion >> 8 ) & 0xFF;
-
- // Then the iteration Count
- sal_Int32 nIterationCount = rData->m_nIterationCount;
- *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 8 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 16 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 24 ) & 0xFF);
-
- // Then the size
- *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 8 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 16 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 24 ) & 0xFF);
-
- // Then the encryption algorithm
- sal_Int32 nEncAlgID = rData->m_nEncAlg;
- *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 8 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 16 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 24 ) & 0xFF);
-
- // Then the checksum algorithm
- sal_Int32 nChecksumAlgID = rData->m_nCheckAlg;
- *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 8 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 16 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 24 ) & 0xFF);
-
- // Then the derived key size
- sal_Int32 nDerivedKeySize = rData->m_nDerivedKeySize;
- *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 8 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 16 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 24 ) & 0xFF);
-
- // Then the start key generation algorithm
- sal_Int32 nKeyAlgID = rData->m_nStartKeyGenID;
- *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 8 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 16 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 24 ) & 0xFF);
-
- // Then the salt length
- *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 8 ) & 0xFF);
-
- // Then the IV length
- *(pHeader++) = static_cast< sal_Int8 >(( nIVLength >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nIVLength >> 8 ) & 0xFF);
-
- // Then the digest length
- *(pHeader++) = static_cast< sal_Int8 >(( nDigestLength >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nDigestLength >> 8 ) & 0xFF);
-
- // Then the mediatype length
- *(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 0 ) & 0xFF);
- *(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 8 ) & 0xFF);
-
- // Then the salt content
- rtl_copyMemory ( pHeader, rData->m_aSalt.getConstArray(), nSaltLength );
- pHeader += nSaltLength;
-
- // Then the IV content
- rtl_copyMemory ( pHeader, rData->m_aInitVector.getConstArray(), nIVLength );
- pHeader += nIVLength;
-
- // Then the digest content
- rtl_copyMemory ( pHeader, rData->m_aDigest.getConstArray(), nDigestLength );
- pHeader += nDigestLength;
-
- // Then the mediatype itself
- rtl_copyMemory ( pHeader, aMediaType.getStr(), nMediaTypeLength );
- pHeader += nMediaTypeLength;
-}
-
-sal_Bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > & rData,
- sal_Int32 &rEncAlg,
- sal_Int32 &rChecksumAlg,
- sal_Int32 &rDerivedKeySize,
- sal_Int32 &rStartKeyGenID,
- sal_Int32 &rSize,
- ::rtl::OUString& aMediaType,
- const uno::Reference< XInputStream >& rStream )
-{
- sal_Bool bOk = sal_False;
- const sal_Int32 nHeaderSize = n_ConstHeaderSize - 4;
- Sequence < sal_Int8 > aBuffer ( nHeaderSize );
- if ( nHeaderSize == rStream->readBytes ( aBuffer, nHeaderSize ) )
- {
- sal_Int16 nPos = 0;
- sal_Int8 *pBuffer = aBuffer.getArray();
- sal_Int16 nVersion = pBuffer[nPos++] & 0xFF;
- nVersion |= ( pBuffer[nPos++] & 0xFF ) << 8;
- if ( nVersion == n_ConstCurrentVersion )
- {
- sal_Int32 nCount = pBuffer[nPos++] & 0xFF;
- nCount |= ( pBuffer[nPos++] & 0xFF ) << 8;
- nCount |= ( pBuffer[nPos++] & 0xFF ) << 16;
- nCount |= ( pBuffer[nPos++] & 0xFF ) << 24;
- rData->m_nIterationCount = nCount;
-
- rSize = pBuffer[nPos++] & 0xFF;
- rSize |= ( pBuffer[nPos++] & 0xFF ) << 8;
- rSize |= ( pBuffer[nPos++] & 0xFF ) << 16;
- rSize |= ( pBuffer[nPos++] & 0xFF ) << 24;
-
- rEncAlg = pBuffer[nPos++] & 0xFF;
- rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 8;
- rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 16;
- rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 24;
-
- rChecksumAlg = pBuffer[nPos++] & 0xFF;
- rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 8;
- rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 16;
- rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 24;
-
- rDerivedKeySize = pBuffer[nPos++] & 0xFF;
- rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 8;
- rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 16;
- rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 24;
-
- rStartKeyGenID = pBuffer[nPos++] & 0xFF;
- rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 8;
- rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 16;
- rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 24;
-
- sal_Int16 nSaltLength = pBuffer[nPos++] & 0xFF;
- nSaltLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
- sal_Int16 nIVLength = ( pBuffer[nPos++] & 0xFF );
- nIVLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
- sal_Int16 nDigestLength = pBuffer[nPos++] & 0xFF;
- nDigestLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
-
- sal_Int16 nMediaTypeLength = pBuffer[nPos++] & 0xFF;
- nMediaTypeLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
-
- if ( nSaltLength == rStream->readBytes ( aBuffer, nSaltLength ) )
- {
- rData->m_aSalt.realloc ( nSaltLength );
- rtl_copyMemory ( rData->m_aSalt.getArray(), aBuffer.getConstArray(), nSaltLength );
- if ( nIVLength == rStream->readBytes ( aBuffer, nIVLength ) )
- {
- rData->m_aInitVector.realloc ( nIVLength );
- rtl_copyMemory ( rData->m_aInitVector.getArray(), aBuffer.getConstArray(), nIVLength );
- if ( nDigestLength == rStream->readBytes ( aBuffer, nDigestLength ) )
- {
- rData->m_aDigest.realloc ( nDigestLength );
- rtl_copyMemory ( rData->m_aDigest.getArray(), aBuffer.getConstArray(), nDigestLength );
-
- if ( nMediaTypeLength == rStream->readBytes ( aBuffer, nMediaTypeLength ) )
- {
- aMediaType = ::rtl::OUString( (sal_Unicode*)aBuffer.getConstArray(),
- nMediaTypeLength / sizeof( sal_Unicode ) );
- bOk = sal_True;
- }
- }
- }
- }
- }
- }
- return bOk;
-}
-
-uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
- const uno::Reference< XInputStream >& xStream,
- const ::rtl::Reference< EncryptionData > &rData )
- throw ( packages::WrongPasswordException, ZipIOException, RuntimeException )
-{
- if ( !rData.is() )
- throw ZipIOException( OUString(RTL_CONSTASCII_USTRINGPARAM( "Encrypted stream without encryption data!\n" )),
- uno::Reference< XInterface >() );
-
- if ( !rData->m_aKey.getLength() )
- throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
-
- uno::Reference< XSeekable > xSeek( xStream, UNO_QUERY );
- if ( !xSeek.is() )
- throw ZipIOException( OUString(RTL_CONSTASCII_USTRINGPARAM( "The stream must be seekable!\n" )),
- uno::Reference< XInterface >() );
-
-
- // 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.getLength(), "Can't detect password correctness without digest!\n" );
- if ( rData->m_aDigest.getLength() )
- {
- 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( xFactory, aReadBuffer, rData ) )
- throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
- }
-
- return new XUnbufferedStream( xFactory, xStream, rData );
-}
-
-#if 0
-// for debugging purposes
-void CheckSequence( const uno::Sequence< sal_Int8 >& aSequence )
-{
- if ( aSequence.getLength() )
- {
- sal_Int32* pPointer = *( (sal_Int32**)&aSequence );
- sal_Int32 nSize = *( pPointer + 1 );
- sal_Int32 nMemSize = *( pPointer - 2 );
- sal_Int32 nUsedMemSize = ( nSize + 4 * sizeof( sal_Int32 ) );
- OSL_ENSURE( nSize == aSequence.getLength() && nUsedMemSize + 7 - ( nUsedMemSize - 1 ) % 8 == nMemSize, "Broken Sequence!" );
- }
-}
-#endif
-
-sal_Bool ZipFile::StaticHasValidPassword( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const Sequence< sal_Int8 > &aReadBuffer, const ::rtl::Reference< EncryptionData > &rData )
-{
- if ( !rData.is() || !rData->m_aKey.getLength() )
- return sal_False;
-
- sal_Bool bRet = sal_False;
-
- uno::Reference< xml::crypto::XCipherContext > xCipher( StaticGetCipher( xFactory, rData, false ), uno::UNO_SET_THROW );
-
- uno::Sequence< sal_Int8 > aDecryptBuffer;
- uno::Sequence< sal_Int8 > aDecryptBuffer2;
- try
- {
- aDecryptBuffer = xCipher->convertWithCipherContext( aReadBuffer );
- aDecryptBuffer2 = xCipher->finalizeCipherContextAndDispose();
- }
- catch( uno::Exception& )
- {
- // decryption with padding will throw the exception in finalizing if the buffer represent only part of the stream
- // it is no problem, actually this is why we read 32 additional bytes ( two of maximal possible encryption blocks )
- }
-
- if ( aDecryptBuffer2.getLength() )
- {
- sal_Int32 nOldLen = aDecryptBuffer.getLength();
- aDecryptBuffer.realloc( nOldLen + aDecryptBuffer2.getLength() );
- rtl_copyMemory( aDecryptBuffer.getArray() + nOldLen, aDecryptBuffer2.getArray(), aDecryptBuffer2.getLength() );
- }
-
- if ( aDecryptBuffer.getLength() > n_ConstDigestLength )
- aDecryptBuffer.realloc( n_ConstDigestLength );
-
- uno::Sequence< sal_Int8 > aDigestSeq;
- uno::Reference< xml::crypto::XDigestContext > xDigestContext( StaticGetDigestContextForChecksum( xFactory, rData ), uno::UNO_SET_THROW );
-
- xDigestContext->updateDigest( aDecryptBuffer );
- aDigestSeq = xDigestContext->finalizeDigestAndDispose();
-
- // If we don't have a digest, then we have to assume that the password is correct
- if ( rData->m_aDigest.getLength() != 0 &&
- ( aDigestSeq.getLength() != rData->m_aDigest.getLength() ||
- 0 != rtl_compareMemory ( aDigestSeq.getConstArray(),
- rData->m_aDigest.getConstArray(),
- aDigestSeq.getLength() ) ) )
- {
- // We should probably tell the user that the password they entered was wrong
- }
- else
- bRet = sal_True;
-
- return bRet;
-}
-
-sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference< EncryptionData >& rData )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- sal_Bool bRet = sal_False;
- if ( rData.is() && rData->m_aKey.getLength() )
- {
- xSeek->seek( rEntry.nOffset );
- sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
-
- // Only want to read enough to verify the digest
- if ( nSize > n_ConstDigestDecrypt )
- nSize = n_ConstDigestDecrypt;
-
- Sequence < sal_Int8 > aReadBuffer ( nSize );
-
- xStream->readBytes( aReadBuffer, nSize );
-
- bRet = StaticHasValidPassword( m_xFactory, aReadBuffer, rData );
- }
-
- return bRet;
-}
-
-uno::Reference< XInputStream > ZipFile::createUnbufferedStream(
- SotMutexHolderRef aMutexHolder,
- ZipEntry & rEntry,
- const ::rtl::Reference< EncryptionData > &rData,
- sal_Int8 nStreamMode,
- sal_Bool bIsEncrypted,
- ::rtl::OUString aMediaType )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- return new XUnbufferedStream ( m_xFactory, aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode );
-}
-
-
-ZipEnumeration * SAL_CALL ZipFile::entries( )
-{
- return new ZipEnumeration ( aEntries );
-}
-
-uno::Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
- const ::rtl::Reference< EncryptionData > &rData,
- sal_Bool bIsEncrypted,
- SotMutexHolderRef aMutexHolder )
- throw(IOException, ZipException, RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if ( rEntry.nOffset <= 0 )
- readLOC( rEntry );
-
- // We want to return a rawStream if we either don't have a key or if the
- // key is wrong
-
- sal_Bool bNeedRawStream = rEntry.nMethod == STORED;
-
- // if we have a digest, then this file is an encrypted one and we should
- // check if we can decrypt it or not
- if ( bIsEncrypted && rData.is() && rData->m_aDigest.getLength() )
- bNeedRawStream = !hasValidPassword ( rEntry, rData );
-
- return createUnbufferedStream ( aMutexHolder,
- rEntry,
- rData,
- bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA,
- bIsEncrypted );
-}
-
-uno::Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
- const ::rtl::Reference< EncryptionData > &rData,
- sal_Bool bIsEncrypted,
- SotMutexHolderRef aMutexHolder )
- throw ( packages::WrongPasswordException,
- IOException,
- ZipException,
- RuntimeException )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if ( rEntry.nOffset <= 0 )
- readLOC( rEntry );
-
- // An exception must be thrown in case stream is encrypted and
- // there is no key or the key is wrong
- sal_Bool bNeedRawStream = sal_False;
- if ( bIsEncrypted )
- {
- // in case no digest is provided there is no way
- // to detect password correctness
- if ( !rData.is() )
- throw ZipException( OUString(RTL_CONSTASCII_USTRINGPARAM( "Encrypted stream without encryption data!\n" )),
- uno::Reference< XInterface >() );
-
- // 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.getLength(), "Can't detect password correctness without digest!\n" );
- if ( rData->m_aDigest.getLength() && !hasValidPassword ( rEntry, rData ) )
- throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
- }
- else
- bNeedRawStream = ( rEntry.nMethod == STORED );
-
- return createUnbufferedStream ( aMutexHolder,
- rEntry,
- rData,
- bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA,
- bIsEncrypted );
-}
-
-uno::Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry,
- const ::rtl::Reference< EncryptionData >& rData,
- sal_Bool bIsEncrypted,
- SotMutexHolderRef aMutexHolder )
- throw(IOException, ZipException, RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if ( rEntry.nOffset <= 0 )
- readLOC( rEntry );
-
- return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted );
-}
-
-uno::Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
- ZipEntry& rEntry,
- const ::rtl::Reference< EncryptionData >& rData,
- const ::rtl::OUString& aMediaType,
- SotMutexHolderRef aMutexHolder )
- throw ( packages::NoEncryptionException,
- IOException,
- ZipException,
- RuntimeException )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if ( !rData.is() )
- throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
-
- if ( rEntry.nOffset <= 0 )
- readLOC( rEntry );
-
- return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_WRAPPEDRAW, sal_True, aMediaType );
-}
-
-sal_Bool ZipFile::readLOC( ZipEntry &rEntry )
- throw(IOException, ZipException, RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- sal_Int32 nTestSig, nTime, nCRC, nSize, nCompressedSize;
- sal_Int16 nVersion, nFlag, nHow, nPathLen, nExtraLen;
- sal_Int32 nPos = -rEntry.nOffset;
-
- aGrabber.seek(nPos);
- aGrabber >> nTestSig;
-
- if (nTestSig != LOCSIG)
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), uno::Reference < XInterface > () );
- aGrabber >> nVersion;
- aGrabber >> nFlag;
- aGrabber >> nHow;
- aGrabber >> nTime;
- aGrabber >> nCRC;
- aGrabber >> nCompressedSize;
- aGrabber >> nSize;
- aGrabber >> nPathLen;
- aGrabber >> nExtraLen;
- rEntry.nOffset = static_cast < sal_Int32 > (aGrabber.getPosition()) + nPathLen + nExtraLen;
-
- sal_Bool bBroken = sal_False;
-
- try
- {
- // read always in UTF8, some tools seem not to set UTF8 bit
- uno::Sequence < sal_Int8 > aNameBuffer( nPathLen );
- sal_Int32 nRead = aGrabber.readBytes( aNameBuffer, nPathLen );
- if ( nRead < aNameBuffer.getLength() )
- aNameBuffer.realloc( nRead );
-
- ::rtl::OUString sLOCPath = rtl::OUString::intern( (sal_Char *) aNameBuffer.getArray(),
- aNameBuffer.getLength(),
- RTL_TEXTENCODING_UTF8 );
-
- if ( rEntry.nPathLen == -1 ) // the file was created
- {
- rEntry.nPathLen = nPathLen;
- rEntry.sPath = sLOCPath;
- }
-
- // the method can be reset for internal use so it is not checked
- bBroken = rEntry.nVersion != nVersion
- || rEntry.nFlag != nFlag
- || rEntry.nTime != nTime
- || rEntry.nPathLen != nPathLen
- || !rEntry.sPath.equals( sLOCPath );
- }
- catch(::std::bad_alloc &)
- {
- bBroken = sal_True;
- }
-
- if ( bBroken && !bRecoveryMode )
- throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ),
- uno::Reference< XInterface >() );
-
- return sal_True;
-}
-
-sal_Int32 ZipFile::findEND( )
- throw(IOException, ZipException, RuntimeException)
-{
- // this method is called in constructor only, no need for mutex
- sal_Int32 nLength, nPos, nEnd;
- Sequence < sal_Int8 > aBuffer;
- try
- {
- nLength = static_cast <sal_Int32 > (aGrabber.getLength());
- if (nLength == 0 || nLength < ENDHDR)
- return -1;
- nPos = nLength - ENDHDR - ZIP_MAXNAMELEN;
- nEnd = nPos >= 0 ? nPos : 0 ;
-
- aGrabber.seek( nEnd );
- aGrabber.readBytes ( aBuffer, nLength - nEnd );
-
- const sal_Int8 *pBuffer = aBuffer.getConstArray();
-
- nPos = nLength - nEnd - ENDHDR;
- while ( nPos >= 0 )
- {
- if (pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 5 && pBuffer[nPos+3] == 6 )
- return nPos + nEnd;
- nPos--;
- }
- }
- catch ( IllegalArgumentException& )
- {
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
- }
- catch ( NotConnectedException& )
- {
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
- }
- catch ( BufferSizeExceededException& )
- {
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
- }
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
-}
-
-sal_Int32 ZipFile::readCEN()
- throw(IOException, ZipException, RuntimeException)
-{
- // this method is called in constructor only, no need for mutex
- sal_Int32 nCenLen, nCenPos = -1, nCenOff, nEndPos, nLocPos;
- sal_uInt16 nCount, nTotal;
-
- try
- {
- nEndPos = findEND();
- if (nEndPos == -1)
- return -1;
- aGrabber.seek(nEndPos + ENDTOT);
- aGrabber >> nTotal;
- aGrabber >> nCenLen;
- aGrabber >> nCenOff;
-
- if ( nTotal * CENHDR > nCenLen )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), uno::Reference < XInterface > () );
-
- if ( nTotal > ZIP_MAXENTRIES )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), uno::Reference < XInterface > () );
-
- if ( nCenLen < 0 || nCenLen > nEndPos )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () );
-
- nCenPos = nEndPos - nCenLen;
-
- if ( nCenOff < 0 || nCenOff > nCenPos )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () );
-
- nLocPos = nCenPos - nCenOff;
- aGrabber.seek( nCenPos );
- Sequence < sal_Int8 > aCENBuffer ( nCenLen );
- sal_Int64 nRead = aGrabber.readBytes ( aCENBuffer, nCenLen );
- if ( static_cast < sal_Int64 > ( nCenLen ) != nRead )
- throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), uno::Reference < XInterface > () );
-
- MemoryByteGrabber aMemGrabber ( aCENBuffer );
-
- ZipEntry aEntry;
- sal_Int32 nTestSig;
- sal_Int16 nCommentLen;
-
- for (nCount = 0 ; nCount < nTotal; nCount++)
- {
- aMemGrabber >> nTestSig;
- if ( nTestSig != CENSIG )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), uno::Reference < XInterface > () );
-
- aMemGrabber.skipBytes ( 2 );
- aMemGrabber >> aEntry.nVersion;
-
- if ( ( aEntry.nVersion & 1 ) == 1 )
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), uno::Reference < XInterface > () );
-
- aMemGrabber >> aEntry.nFlag;
- aMemGrabber >> aEntry.nMethod;
-
- if ( aEntry.nMethod != STORED && aEntry.nMethod != DEFLATED)
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), uno::Reference < XInterface > () );
-
- aMemGrabber >> aEntry.nTime;
- aMemGrabber >> aEntry.nCrc;
- aMemGrabber >> aEntry.nCompressedSize;
- aMemGrabber >> aEntry.nSize;
- aMemGrabber >> aEntry.nPathLen;
- aMemGrabber >> aEntry.nExtraLen;
- aMemGrabber >> nCommentLen;
- aMemGrabber.skipBytes ( 8 );
- aMemGrabber >> aEntry.nOffset;
-
- aEntry.nOffset += nLocPos;
- aEntry.nOffset *= -1;
-
- if ( aEntry.nPathLen < 0 )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), uno::Reference < XInterface > () );
-
- if ( nCommentLen < 0 )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), uno::Reference < XInterface > () );
-
- if ( aEntry.nExtraLen < 0 )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), uno::Reference < XInterface > () );
-
- // read always in UTF8, some tools seem not to set UTF8 bit
- aEntry.sPath = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(),
- aEntry.nPathLen,
- RTL_TEXTENCODING_UTF8 );
-
- if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sPath, sal_True ) )
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), uno::Reference < XInterface > () );
-
- aMemGrabber.skipBytes( aEntry.nPathLen + aEntry.nExtraLen + nCommentLen );
- aEntries[aEntry.sPath] = aEntry;
- }
-
- if (nCount != nTotal)
- throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), uno::Reference < XInterface > () );
- }
- catch ( IllegalArgumentException & )
- {
- // seek can throw this...
- nCenPos = -1; // make sure we return -1 to indicate an error
- }
- return nCenPos;
-}
-
-sal_Int32 ZipFile::recover()
- throw(IOException, ZipException, RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- sal_Int32 nLength;
- Sequence < sal_Int8 > aBuffer;
- Sequence < sal_Int32 > aHeaderOffsets;
-
- try
- {
- nLength = static_cast <sal_Int32 > (aGrabber.getLength());
- if (nLength == 0 || nLength < ENDHDR)
- return -1;
-
- aGrabber.seek( 0 );
-
- const sal_Int32 nToRead = 32000;
- for( sal_Int32 nGenPos = 0; aGrabber.readBytes( aBuffer, nToRead ) && aBuffer.getLength() > 16; )
- {
- const sal_Int8 *pBuffer = aBuffer.getConstArray();
- sal_Int32 nBufSize = aBuffer.getLength();
-
- sal_Int32 nPos = 0;
- // the buffer should contain at least one header,
- // or if it is end of the file, at least the postheader with sizes and hash
- while( nPos < nBufSize - 30
- || ( nBufSize < nToRead && nPos < nBufSize - 16 ) )
-
- {
- if ( nPos < nBufSize - 30 && pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 3 && pBuffer[nPos+3] == 4 )
- {
- ZipEntry aEntry;
- MemoryByteGrabber aMemGrabber ( Sequence< sal_Int8 >( ((sal_Int8*)(&(pBuffer[nPos+4]))), 26 ) );
-
- aMemGrabber >> aEntry.nVersion;
- if ( ( aEntry.nVersion & 1 ) != 1 )
- {
- aMemGrabber >> aEntry.nFlag;
- aMemGrabber >> aEntry.nMethod;
-
- if ( aEntry.nMethod == STORED || aEntry.nMethod == DEFLATED )
- {
- aMemGrabber >> aEntry.nTime;
- aMemGrabber >> aEntry.nCrc;
- aMemGrabber >> aEntry.nCompressedSize;
- aMemGrabber >> aEntry.nSize;
- aMemGrabber >> aEntry.nPathLen;
- aMemGrabber >> aEntry.nExtraLen;
-
- sal_Int32 nDescrLength =
- ( aEntry.nMethod == DEFLATED && ( aEntry.nFlag & 8 ) ) ?
- 16 : 0;
-
-
- // This is a quick fix for OOo1.1RC
- // For OOo2.0 the whole package must be switched to unsigned values
- if ( aEntry.nCompressedSize < 0 ) aEntry.nCompressedSize = 0x7FFFFFFF;
- if ( aEntry.nSize < 0 ) aEntry.nSize = 0x7FFFFFFF;
- if ( aEntry.nPathLen < 0 ) aEntry.nPathLen = 0x7FFF;
- if ( aEntry.nExtraLen < 0 ) aEntry.nExtraLen = 0x7FFF;
- // End of quick fix
-
- sal_Int32 nDataSize = ( aEntry.nMethod == DEFLATED ) ? aEntry.nCompressedSize : aEntry.nSize;
- sal_Int32 nBlockLength = nDataSize + aEntry.nPathLen + aEntry.nExtraLen + 30 + nDescrLength;
- if ( aEntry.nPathLen >= 0 && aEntry.nExtraLen >= 0
- && ( nGenPos + nPos + nBlockLength ) <= nLength )
- {
- // read always in UTF8, some tools seem not to set UTF8 bit
- if( nPos + 30 + aEntry.nPathLen <= nBufSize )
- aEntry.sPath = OUString ( (sal_Char *) &pBuffer[nPos + 30],
- aEntry.nPathLen,
- RTL_TEXTENCODING_UTF8 );
- else
- {
- Sequence < sal_Int8 > aFileName;
- aGrabber.seek( nGenPos + nPos + 30 );
- aGrabber.readBytes( aFileName, aEntry.nPathLen );
- aEntry.sPath = OUString ( (sal_Char *) aFileName.getArray(),
- aFileName.getLength(),
- RTL_TEXTENCODING_UTF8 );
- aEntry.nPathLen = static_cast< sal_Int16 >(aFileName.getLength());
- }
-
- aEntry.nOffset = nGenPos + nPos + 30 + aEntry.nPathLen + aEntry.nExtraLen;
-
- if ( ( aEntry.nSize || aEntry.nCompressedSize ) && !checkSizeAndCRC( aEntry ) )
- {
- aEntry.nCrc = 0;
- aEntry.nCompressedSize = 0;
- aEntry.nSize = 0;
- }
-
- if ( aEntries.find( aEntry.sPath ) == aEntries.end() )
- aEntries[aEntry.sPath] = aEntry;
- }
- }
- }
-
- nPos += 4;
- }
- else if (pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 7 && pBuffer[nPos+3] == 8 )
- {
- sal_Int32 nCompressedSize, nSize, nCRC32;
- MemoryByteGrabber aMemGrabber ( Sequence< sal_Int8 >( ((sal_Int8*)(&(pBuffer[nPos+4]))), 12 ) );
- aMemGrabber >> nCRC32;
- aMemGrabber >> nCompressedSize;
- aMemGrabber >> nSize;
-
- for( EntryHash::iterator aIter = aEntries.begin(); aIter != aEntries.end(); ++aIter )
- {
- ZipEntry aTmp = (*aIter).second;
-
- // this is a broken package, accept this block not only for DEFLATED streams
- if( (*aIter).second.nFlag & 8 )
- {
- sal_Int32 nStreamOffset = nGenPos + nPos - nCompressedSize;
- if ( nStreamOffset == (*aIter).second.nOffset && nCompressedSize > (*aIter).second.nCompressedSize )
- {
- // only DEFLATED blocks need to be checked
- sal_Bool bAcceptBlock = ( (*aIter).second.nMethod == STORED && nCompressedSize == nSize );
-
- if ( !bAcceptBlock )
- {
- sal_Int32 nRealSize = 0, nRealCRC = 0;
- getSizeAndCRC( nStreamOffset, nCompressedSize, &nRealSize, &nRealCRC );
- bAcceptBlock = ( nRealSize == nSize && nRealCRC == nCRC32 );
- }
-
- if ( bAcceptBlock )
- {
- (*aIter).second.nCrc = nCRC32;
- (*aIter).second.nCompressedSize = nCompressedSize;
- (*aIter).second.nSize = nSize;
- }
- }
-#if 0
-// for now ignore clearly broken streams
- else if( !(*aIter).second.nCompressedSize )
- {
- (*aIter).second.nCrc = nCRC32;
- sal_Int32 nRealStreamSize = nGenPos + nPos - (*aIter).second.nOffset;
- (*aIter).second.nCompressedSize = nGenPos + nPos - (*aIter).second.nOffset;
- (*aIter).second.nSize = nSize;
- }
-#endif
- }
- }
-
- nPos += 4;
- }
- else
- nPos++;
- }
-
- nGenPos += nPos;
- aGrabber.seek( nGenPos );
- }
-
- return 0;
- }
- catch ( IllegalArgumentException& )
- {
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
- }
- catch ( NotConnectedException& )
- {
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
- }
- catch ( BufferSizeExceededException& )
- {
- throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () );
- }
-}
-
-sal_Bool ZipFile::checkSizeAndCRC( const ZipEntry& aEntry )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- sal_Int32 nSize = 0, nCRC = 0;
-
- if( aEntry.nMethod == STORED )
- return ( getCRC( aEntry.nOffset, aEntry.nSize ) == aEntry.nCrc );
-
- getSizeAndCRC( aEntry.nOffset, aEntry.nCompressedSize, &nSize, &nCRC );
- return ( aEntry.nSize == nSize && aEntry.nCrc == nCRC );
-}
-
-sal_Int32 ZipFile::getCRC( sal_Int32 nOffset, sal_Int32 nSize )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- Sequence < sal_Int8 > aBuffer;
- CRC32 aCRC;
- sal_Int32 nBlockSize = ::std::min( nSize, static_cast< sal_Int32 >( 32000 ) );
-
- aGrabber.seek( nOffset );
- for ( int ind = 0;
- aGrabber.readBytes( aBuffer, nBlockSize ) && ind * nBlockSize < nSize;
- ind++ )
- {
- aCRC.updateSegment( aBuffer, 0, ::std::min( nBlockSize, nSize - ind * nBlockSize ) );
- }
-
- return aCRC.getValue();
-}
-
-void ZipFile::getSizeAndCRC( sal_Int32 nOffset, sal_Int32 nCompressedSize, sal_Int32 *nSize, sal_Int32 *nCRC )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- Sequence < sal_Int8 > aBuffer;
- CRC32 aCRC;
- sal_Int32 nRealSize = 0;
- Inflater aInflaterLocal( sal_True );
- sal_Int32 nBlockSize = ::std::min( nCompressedSize, static_cast< sal_Int32 >( 32000 ) );
-
- aGrabber.seek( nOffset );
- for ( int ind = 0;
- !aInflaterLocal.finished() && aGrabber.readBytes( aBuffer, nBlockSize ) && ind * nBlockSize < nCompressedSize;
- ind++ )
- {
- Sequence < sal_Int8 > aData( nBlockSize );
- sal_Int32 nLastInflated = 0;
- sal_Int32 nInBlock = 0;
-
- aInflaterLocal.setInput( aBuffer );
- do
- {
- nLastInflated = aInflaterLocal.doInflateSegment( aData, 0, nBlockSize );
- aCRC.updateSegment( aData, 0, nLastInflated );
- nInBlock += nLastInflated;
- } while( !aInflater.finished() && nLastInflated );
-
- nRealSize += nInBlock;
- }
-
- *nSize = nRealSize;
- *nCRC = aCRC.getValue();
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
deleted file mode 100644
index 8efe20ebc..000000000
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ /dev/null
@@ -1,452 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-
-#include <com/sun/star/packages/zip/ZipConstants.hpp>
-#include <com/sun/star/io/XOutputStream.hpp>
-#include <comphelper/storagehelper.hxx>
-
-#include <osl/time.h>
-
-#include <EncryptionData.hxx>
-#include <PackageConstants.hxx>
-#include <ZipEntry.hxx>
-#include <ZipFile.hxx>
-#include <ZipPackageStream.hxx>
-#include <ZipOutputStream.hxx>
-
-using namespace com::sun::star;
-using namespace com::sun::star::io;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::packages;
-using namespace com::sun::star::packages::zip;
-using namespace com::sun::star::packages::zip::ZipConstants;
-
-/** This class is used to write Zip files
- */
-ZipOutputStream::ZipOutputStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory,
- const uno::Reference < XOutputStream > &xOStream )
-: m_xFactory( xFactory )
-, xStream(xOStream)
-, m_aDeflateBuffer(n_ConstBufferSize)
-, aDeflater(DEFAULT_COMPRESSION, sal_True)
-, aChucker(xOStream)
-, pCurrentEntry(NULL)
-, nMethod(DEFLATED)
-, bFinished(sal_False)
-, bEncryptCurrentEntry(sal_False)
-, m_pCurrentStream(NULL)
-{
-}
-
-ZipOutputStream::~ZipOutputStream( void )
-{
- for (sal_Int32 i = 0, nEnd = aZipList.size(); i < nEnd; i++)
- delete aZipList[i];
-}
-
-void SAL_CALL ZipOutputStream::setMethod( sal_Int32 nNewMethod )
- throw(RuntimeException)
-{
- nMethod = static_cast < sal_Int16 > (nNewMethod);
-}
-void SAL_CALL ZipOutputStream::setLevel( sal_Int32 nNewLevel )
- throw(RuntimeException)
-{
- aDeflater.setLevel( nNewLevel);
-}
-
-void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry,
- ZipPackageStream* pStream,
- sal_Bool bEncrypt)
- throw(IOException, RuntimeException)
-{
- if (pCurrentEntry != NULL)
- closeEntry();
- if (rEntry.nTime == -1)
- rEntry.nTime = getCurrentDosTime();
- if (rEntry.nMethod == -1)
- rEntry.nMethod = nMethod;
- rEntry.nVersion = 20;
- rEntry.nFlag = 1 << 11;
- if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 ||
- rEntry.nCrc == -1)
- {
- rEntry.nSize = rEntry.nCompressedSize = 0;
- rEntry.nFlag |= 8;
- }
-
- if (bEncrypt)
- {
- bEncryptCurrentEntry = sal_True;
-
- m_xCipherContext = ZipFile::StaticGetCipher( m_xFactory, pStream->GetEncryptionData(), true );
- m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xFactory, pStream->GetEncryptionData() );
- mnDigested = 0;
- rEntry.nFlag |= 1 << 4;
- m_pCurrentStream = pStream;
- }
- sal_Int32 nLOCLength = writeLOC(rEntry);
- rEntry.nOffset = static_cast < sal_Int32 > (aChucker.GetPosition()) - nLOCLength;
- aZipList.push_back( &rEntry );
- pCurrentEntry = &rEntry;
-}
-
-void SAL_CALL ZipOutputStream::closeEntry( )
- throw(IOException, RuntimeException)
-{
- ZipEntry *pEntry = pCurrentEntry;
- if (pEntry)
- {
- switch (pEntry->nMethod)
- {
- case DEFLATED:
- aDeflater.finish();
- while (!aDeflater.finished())
- doDeflate();
- if ((pEntry->nFlag & 8) == 0)
- {
- if (pEntry->nSize != aDeflater.getTotalIn())
- {
- OSL_FAIL("Invalid entry size");
- }
- if (pEntry->nCompressedSize != aDeflater.getTotalOut())
- {
- // Different compression strategies make the merit of this
- // test somewhat dubious
- pEntry->nCompressedSize = aDeflater.getTotalOut();
- }
- if (pEntry->nCrc != aCRC.getValue())
- {
- OSL_FAIL("Invalid entry CRC-32");
- }
- }
- else
- {
- if ( !bEncryptCurrentEntry )
- {
- pEntry->nSize = aDeflater.getTotalIn();
- pEntry->nCompressedSize = aDeflater.getTotalOut();
- }
- pEntry->nCrc = aCRC.getValue();
- writeEXT(*pEntry);
- }
- aDeflater.reset();
- aCRC.reset();
- break;
- case STORED:
- if (!((pEntry->nFlag & 8) == 0))
- OSL_FAIL( "Serious error, one of compressed size, size or CRC was -1 in a STORED stream");
- break;
- default:
- OSL_FAIL("Invalid compression method");
- break;
- }
-
- if (bEncryptCurrentEntry)
- {
- bEncryptCurrentEntry = sal_False;
-
- m_xCipherContext.clear();
-
- uno::Sequence< sal_Int8 > aDigestSeq;
- if ( m_xDigestContext.is() )
- {
- aDigestSeq = m_xDigestContext->finalizeDigestAndDispose();
- m_xDigestContext.clear();
- }
-
- if ( m_pCurrentStream )
- m_pCurrentStream->setDigest( aDigestSeq );
- }
- pCurrentEntry = NULL;
- m_pCurrentStream = NULL;
- }
-}
-
-void SAL_CALL ZipOutputStream::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
- throw(IOException, RuntimeException)
-{
- switch (pCurrentEntry->nMethod)
- {
- case DEFLATED:
- if (!aDeflater.finished())
- {
- aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength);
- while (!aDeflater.needsInput())
- doDeflate();
- if (!bEncryptCurrentEntry)
- aCRC.updateSegment(rBuffer, nNewOffset, nNewLength);
- }
- break;
- case STORED:
- {
- Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength );
- aChucker.WriteBytes( aTmpBuffer );
- }
- break;
- }
-}
-
-void SAL_CALL ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength )
- throw(IOException, RuntimeException)
-{
- Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength );
- aChucker.WriteBytes( aTmpBuffer );
-}
-
-void SAL_CALL ZipOutputStream::rawCloseEntry( )
- throw(IOException, RuntimeException)
-{
- if ( pCurrentEntry->nMethod == DEFLATED && ( pCurrentEntry->nFlag & 8 ) )
- writeEXT(*pCurrentEntry);
- pCurrentEntry = NULL;
-}
-
-void SAL_CALL ZipOutputStream::finish( )
- throw(IOException, RuntimeException)
-{
- if (bFinished)
- return;
-
- if (pCurrentEntry != NULL)
- closeEntry();
-
- if (aZipList.size() < 1)
- OSL_FAIL("Zip file must have at least one entry!\n");
-
- sal_Int32 nOffset= static_cast < sal_Int32 > (aChucker.GetPosition());
- for (sal_Int32 i =0, nEnd = aZipList.size(); i < nEnd; i++)
- writeCEN( *aZipList[i] );
- writeEND( nOffset, static_cast < sal_Int32 > (aChucker.GetPosition()) - nOffset);
- bFinished = sal_True;
- xStream->flush();
-}
-
-void ZipOutputStream::doDeflate()
-{
- sal_Int32 nLength = aDeflater.doDeflateSegment(m_aDeflateBuffer, 0, m_aDeflateBuffer.getLength());
-
- if ( nLength > 0 )
- {
- uno::Sequence< sal_Int8 > aTmpBuffer( m_aDeflateBuffer.getConstArray(), nLength );
- if ( bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() )
- {
- // Need to update our digest before encryption...
- sal_Int32 nDiff = n_ConstDigestLength - mnDigested;
- if ( nDiff )
- {
- sal_Int32 nEat = ::std::min( nLength, nDiff );
- uno::Sequence< sal_Int8 > aTmpSeq( aTmpBuffer.getConstArray(), nEat );
- m_xDigestContext->updateDigest( aTmpSeq );
- mnDigested = mnDigested + static_cast< sal_Int16 >( nEat );
- }
-
- uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer );
-
- aChucker.WriteBytes( aEncryptionBuffer );
-
- // the sizes as well as checksum for encrypted streams is calculated here
- pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
- pCurrentEntry->nSize = pCurrentEntry->nCompressedSize;
- aCRC.update( aEncryptionBuffer );
- }
- else
- {
- aChucker.WriteBytes ( aTmpBuffer );
- }
- }
-
- if ( aDeflater.finished() && bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() )
- {
- uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose();
- if ( aEncryptionBuffer.getLength() )
- {
- aChucker.WriteBytes( aEncryptionBuffer );
-
- // the sizes as well as checksum for encrypted streams is calculated hier
- pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
- pCurrentEntry->nSize = pCurrentEntry->nCompressedSize;
- aCRC.update( aEncryptionBuffer );
- }
- }
-}
-
-void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
- throw(IOException, RuntimeException)
-{
- aChucker << ENDSIG;
- aChucker << static_cast < sal_Int16 > ( 0 );
- aChucker << static_cast < sal_Int16 > ( 0 );
- aChucker << static_cast < sal_Int16 > ( aZipList.size() );
- aChucker << static_cast < sal_Int16 > ( aZipList.size() );
- aChucker << nLength;
- aChucker << nOffset;
- aChucker << static_cast < sal_Int16 > ( 0 );
-}
-void ZipOutputStream::writeCEN( const ZipEntry &rEntry )
- throw(IOException, RuntimeException)
-{
- if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) )
- throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() );
-
- ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 );
- sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() );
-
- aChucker << CENSIG;
- aChucker << rEntry.nVersion;
- aChucker << rEntry.nVersion;
- if (rEntry.nFlag & (1 << 4) )
- {
- // If it's an encrypted entry, we pretend its stored plain text
- ZipEntry *pEntry = const_cast < ZipEntry * > ( &rEntry );
- pEntry->nFlag &= ~(1 <<4 );
- aChucker << rEntry.nFlag;
- aChucker << static_cast < sal_Int16 > ( STORED );
- }
- else
- {
- aChucker << rEntry.nFlag;
- aChucker << rEntry.nMethod;
- }
- aChucker << static_cast < sal_uInt32> ( rEntry.nTime );
- aChucker << static_cast < sal_uInt32> ( rEntry.nCrc );
- aChucker << rEntry.nCompressedSize;
- aChucker << rEntry.nSize;
- aChucker << nNameLength;
- aChucker << static_cast < sal_Int16> (0);
- aChucker << static_cast < sal_Int16> (0);
- aChucker << static_cast < sal_Int16> (0);
- aChucker << static_cast < sal_Int16> (0);
- aChucker << static_cast < sal_Int32> (0);
- aChucker << rEntry.nOffset;
-
- Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() );
- aChucker.WriteBytes( aSequence );
-}
-void ZipOutputStream::writeEXT( const ZipEntry &rEntry )
- throw(IOException, RuntimeException)
-{
- aChucker << EXTSIG;
- aChucker << static_cast < sal_uInt32> ( rEntry.nCrc );
- aChucker << rEntry.nCompressedSize;
- aChucker << rEntry.nSize;
-}
-
-sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry )
- throw(IOException, RuntimeException)
-{
- if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) )
- throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() );
-
- ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 );
- sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() );
-
- aChucker << LOCSIG;
- aChucker << rEntry.nVersion;
-
- if (rEntry.nFlag & (1 << 4) )
- {
- // If it's an encrypted entry, we pretend its stored plain text
- sal_Int16 nTmpFlag = rEntry.nFlag;
- nTmpFlag &= ~(1 <<4 );
- aChucker << nTmpFlag;
- aChucker << static_cast < sal_Int16 > ( STORED );
- }
- else
- {
- aChucker << rEntry.nFlag;
- aChucker << rEntry.nMethod;
- }
-
- aChucker << static_cast < sal_uInt32 > (rEntry.nTime);
- if ((rEntry.nFlag & 8) == 8 )
- {
- aChucker << static_cast < sal_Int32 > (0);
- aChucker << static_cast < sal_Int32 > (0);
- aChucker << static_cast < sal_Int32 > (0);
- }
- else
- {
- aChucker << static_cast < sal_uInt32 > (rEntry.nCrc);
- aChucker << rEntry.nCompressedSize;
- aChucker << rEntry.nSize;
- }
- aChucker << nNameLength;
- aChucker << static_cast < sal_Int16 > (0);
-
- Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() );
- aChucker.WriteBytes( aSequence );
-
- return LOCHDR + nNameLength;
-}
-sal_uInt32 ZipOutputStream::getCurrentDosTime( )
-{
- oslDateTime aDateTime;
- TimeValue aTimeValue;
- osl_getSystemTime ( &aTimeValue );
- osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime);
-
- sal_uInt32 nYear = static_cast <sal_uInt32> (aDateTime.Year);
-
- if (nYear>1980)
- nYear-=1980;
- else if (nYear>80)
- nYear-=80;
- sal_uInt32 nResult = static_cast < sal_uInt32>( ( ( ( aDateTime.Day) +
- ( 32 * (aDateTime.Month)) +
- ( 512 * nYear ) ) << 16) |
- ( ( aDateTime.Seconds/2) +
- ( 32 * aDateTime.Minutes) +
- ( 2048 * static_cast <sal_uInt32 > (aDateTime.Hours) ) ) );
- return nResult;
-}
-/*
-
- This is actually never used, so I removed it, but thought that the
- implementation details may be useful in the future...mtg 20010307
-
- I stopped using the time library and used the OSL version instead, but
- it might still be useful to have this code here..
-
-void ZipOutputStream::dosDateToTMDate ( tm &rTime, sal_uInt32 nDosDate)
-{
- sal_uInt32 nDate = static_cast < sal_uInt32 > (nDosDate >> 16);
- rTime.tm_mday = static_cast < sal_uInt32 > ( nDate & 0x1F);
- rTime.tm_mon = static_cast < sal_uInt32 > ( ( ( (nDate) & 0x1E0)/0x20)-1);
- rTime.tm_year = static_cast < sal_uInt32 > ( ( (nDate & 0x0FE00)/0x0200)+1980);
-
- rTime.tm_hour = static_cast < sal_uInt32 > ( (nDosDate & 0xF800)/0x800);
- rTime.tm_min = static_cast < sal_uInt32 > ( (nDosDate & 0x7E0)/0x20);
- rTime.tm_sec = static_cast < sal_uInt32 > ( 2 * (nDosDate & 0x1F) );
-}
-*/
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zipapi/blowfishcontext.cxx b/package/source/zipapi/blowfishcontext.cxx
deleted file mode 100644
index 6459cc4e4..000000000
--- a/package/source/zipapi/blowfishcontext.cxx
+++ /dev/null
@@ -1,122 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-
-#include <rtl/cipher.h>
-#include <rtl/ref.hxx>
-
-#include "blowfishcontext.hxx"
-
-using namespace ::com::sun::star;
-
-// static
-uno::Reference< xml::crypto::XCipherContext > BlowfishCFB8CipherContext::Create( const uno::Sequence< sal_Int8 >& aDerivedKey, const uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt )
-{
- ::rtl::Reference< BlowfishCFB8CipherContext > xResult = new BlowfishCFB8CipherContext();
- xResult->m_pCipher = rtl_cipher_create( rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream );
- if ( !xResult->m_pCipher )
- throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not create cipher!")),
- uno::Reference< XInterface >() );
-
- if ( rtl_Cipher_E_None != rtl_cipher_init(
- xResult->m_pCipher,
- bEncrypt ? rtl_Cipher_DirectionEncode : rtl_Cipher_DirectionDecode,
- reinterpret_cast< const sal_uInt8* >( aDerivedKey.getConstArray() ),
- aDerivedKey.getLength(),
- reinterpret_cast< const sal_uInt8* >( aInitVector.getConstArray() ),
- aInitVector.getLength() ) )
- {
- throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not initialize cipher!") ),
- uno::Reference< XInterface >() );
- }
-
- xResult->m_bEncrypt = bEncrypt;
-
- return uno::Reference< xml::crypto::XCipherContext >( xResult.get() );
-}
-
-BlowfishCFB8CipherContext::~BlowfishCFB8CipherContext()
-{
- if ( m_pCipher )
- {
- rtl_cipher_destroy ( m_pCipher );
- m_pCipher = NULL;
- }
-}
-
-uno::Sequence< sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::convertWithCipherContext( const uno::Sequence< ::sal_Int8 >& aData )
- throw( lang::IllegalArgumentException, lang::DisposedException, uno::RuntimeException )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if ( !m_pCipher )
- throw lang::DisposedException();
-
- uno::Sequence< sal_Int8 > aResult( aData.getLength() );
- rtlCipherError nError = rtl_Cipher_E_None;
-
- if ( m_bEncrypt )
- {
- rtl_cipher_encode( m_pCipher,
- aData.getConstArray(),
- aData.getLength(),
- reinterpret_cast< sal_uInt8* >( aResult.getArray() ),
- aResult.getLength() );
- }
- else
- {
- rtl_cipher_decode( m_pCipher,
- aData.getConstArray(),
- aData.getLength(),
- reinterpret_cast< sal_uInt8* >( aResult.getArray() ),
- aResult.getLength() );
- }
-
- if ( rtl_Cipher_E_None != nError )
- {
- throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not decrypt/encrypt with cipher!") ),
- uno::Reference< uno::XInterface >() );
- }
-
- return aResult;
-}
-
-uno::Sequence< ::sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::finalizeCipherContextAndDispose()
- throw( lang::DisposedException, uno::RuntimeException )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if ( !m_pCipher )
- throw lang::DisposedException();
-
- rtl_cipher_destroy ( m_pCipher );
- m_pCipher = NULL;
-
- return uno::Sequence< sal_Int8 >();
-}
-
-
diff --git a/package/source/zipapi/blowfishcontext.hxx b/package/source/zipapi/blowfishcontext.hxx
deleted file mode 100644
index 49cce2fc0..000000000
--- a/package/source/zipapi/blowfishcontext.hxx
+++ /dev/null
@@ -1,58 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-#ifndef _BLOWFISHCONTEXT_HXX
-#define _BLOWFISHCONTEXT_HXX
-
-#include <com/sun/star/xml/crypto/XCipherContext.hpp>
-
-#include <cppuhelper/implbase1.hxx>
-#include <osl/mutex.hxx>
-
-class BlowfishCFB8CipherContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XCipherContext >
-{
- ::osl::Mutex m_aMutex;
- void* m_pCipher;
- bool m_bEncrypt;
-
- BlowfishCFB8CipherContext()
- : m_pCipher( NULL )
- , m_bEncrypt( false )
- {}
-
-public:
-
- virtual ~BlowfishCFB8CipherContext();
-
- static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext >
- Create( const ::com::sun::star::uno::Sequence< sal_Int8 >& aDerivedKey, const ::com::sun::star::uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt );
-
- virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL convertWithCipherContext( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
- virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeCipherContextAndDispose( ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
-};
-
-#endif // _BLOWFISHCONTEXT_HXX
-
diff --git a/package/source/zipapi/makefile.mk b/package/source/zipapi/makefile.mk
deleted file mode 100644
index 8a07d448d..000000000
--- a/package/source/zipapi/makefile.mk
+++ /dev/null
@@ -1,62 +0,0 @@
-#*************************************************************************
-#
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# Copyright 2000, 2010 Oracle and/or its affiliates.
-#
-# OpenOffice.org - a multi-platform office productivity suite
-#
-# This file is part of OpenOffice.org.
-#
-# OpenOffice.org is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License version 3
-# only, as published by the Free Software Foundation.
-#
-# OpenOffice.org is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License version 3 for more details
-# (a copy is included in the LICENSE file that accompanied this code).
-#
-# You should have received a copy of the GNU Lesser General Public License
-# version 3 along with OpenOffice.org. If not, see
-# <http://www.openoffice.org/license.html>
-# for a copy of the LGPLv3 License.
-#
-#*************************************************************************
-
-PRJ=..$/..
-PRJNAME=package
-TARGET=zipapi
-
-ENABLE_EXCEPTIONS=TRUE
-
-# --- Settings -----------------------------------------------------
-
-.INCLUDE : settings.mk
-.INCLUDE : $(PRJ)$/util$/package.pmk
-
-# --- Files --------------------------------------------------------
-.IF "$(L10N_framework)"==""
-.IF "$(SYSTEM_ZLIB)" == "YES"
-CFLAGS+=-DSYSTEM_ZLIB
-.ENDIF
-
-SLOFILES= \
- $(SLO)$/CRC32.obj \
- $(SLO)$/ByteChucker.obj \
- $(SLO)$/ByteGrabber.obj \
- $(SLO)$/blowfishcontext.obj \
- $(SLO)$/Inflater.obj \
- $(SLO)$/Deflater.obj \
- $(SLO)$/sha1context.obj \
- $(SLO)$/ZipEnumeration.obj \
- $(SLO)$/ZipFile.obj \
- $(SLO)$/ZipOutputStream.obj \
- $(SLO)$/XUnbufferedStream.obj
-
-.ENDIF # L10N_framework
-
-# --- Targets ------------------------------------------------------
-
-.INCLUDE : target.mk
diff --git a/package/source/zipapi/sha1context.cxx b/package/source/zipapi/sha1context.cxx
deleted file mode 100644
index 0e34fd4a9..000000000
--- a/package/source/zipapi/sha1context.cxx
+++ /dev/null
@@ -1,97 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_package.hxx"
-
-#include <rtl/digest.h>
-#include <rtl/ref.hxx>
-
-#include "sha1context.hxx"
-
-using namespace ::com::sun::star;
-
-// static
-uno::Reference< xml::crypto::XDigestContext > SHA1DigestContext::Create()
-{
- ::rtl::Reference< SHA1DigestContext > xResult = new SHA1DigestContext();
- xResult->m_pDigest = rtl_digest_createSHA1();
- if ( !xResult->m_pDigest )
- throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not create cipher!") ),
- uno::Reference< XInterface >() );
-
- return uno::Reference< xml::crypto::XDigestContext >( xResult.get() );
-}
-
-SHA1DigestContext::~SHA1DigestContext()
-{
- if ( m_pDigest )
- {
- rtl_digest_destroySHA1( m_pDigest );
- m_pDigest = NULL;
- }
-}
-
-void SAL_CALL SHA1DigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData )
- throw( lang::DisposedException, uno::RuntimeException )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if ( !m_pDigest )
- throw lang::DisposedException();
-
- if ( rtl_Digest_E_None != rtl_digest_updateSHA1( m_pDigest, aData.getConstArray(), aData.getLength() ) )
- {
- rtl_digest_destroySHA1( m_pDigest );
- m_pDigest = NULL;
-
- throw uno::RuntimeException();
- }
-}
-
-uno::Sequence< ::sal_Int8 > SAL_CALL SHA1DigestContext::finalizeDigestAndDispose()
- throw( lang::DisposedException, uno::RuntimeException )
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- if ( !m_pDigest )
- throw lang::DisposedException();
-
- uno::Sequence< sal_Int8 > aResult( RTL_DIGEST_LENGTH_SHA1 );
- if ( rtl_Digest_E_None != rtl_digest_getSHA1( m_pDigest, reinterpret_cast< sal_uInt8* >( aResult.getArray() ), aResult.getLength() ) )
- {
- rtl_digest_destroySHA1( m_pDigest );
- m_pDigest = NULL;
-
- throw uno::RuntimeException();
- }
-
- rtl_digest_destroySHA1( m_pDigest );
- m_pDigest = NULL;
-
- return aResult;
-}
-
-
diff --git a/package/source/zipapi/sha1context.hxx b/package/source/zipapi/sha1context.hxx
deleted file mode 100644
index 6d9374db8..000000000
--- a/package/source/zipapi/sha1context.hxx
+++ /dev/null
@@ -1,59 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-#ifndef _SHA1CONTEXT_HXX
-#define _SHA1CONTEXT_HXX
-
-#include <com/sun/star/xml/crypto/XDigestContext.hpp>
-
-#include <cppuhelper/implbase1.hxx>
-#include <osl/mutex.hxx>
-
-class SHA1DigestContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XDigestContext >
-{
- ::osl::Mutex m_aMutex;
- void* m_pDigest;
-
- SHA1DigestContext()
- : m_pDigest( NULL )
- {}
-
-public:
-
- virtual ~SHA1DigestContext();
-
- static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext >
- Create();
-
- virtual void SAL_CALL updateDigest( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
- virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeDigestAndDispose() throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
-
-};
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */