diff options
Diffstat (limited to 'sdext/source/pdfimport/pdfparse/pdfentries.cxx')
-rw-r--r-- | sdext/source/pdfimport/pdfparse/pdfentries.cxx | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/sdext/source/pdfimport/pdfparse/pdfentries.cxx b/sdext/source/pdfimport/pdfparse/pdfentries.cxx index a2ff6b996ff2..96d2dabe7c8f 100644 --- a/sdext/source/pdfimport/pdfparse/pdfentries.cxx +++ b/sdext/source/pdfimport/pdfparse/pdfentries.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -59,7 +59,7 @@ struct EmitImplData XRefTable m_aXRefTable; // container of all indirect objects (usually a PDFFile*) const PDFContainer* m_pObjectContainer; - + // returns true if the xref table was updated bool insertXref( unsigned int nObject, unsigned int nGeneration, unsigned int nOffset ) { @@ -78,7 +78,7 @@ struct EmitImplData } return false; } - + EmitImplData( const PDFContainer* pTopContainer ) : m_pObjectContainer( pTopContainer ) {} @@ -211,7 +211,7 @@ OString PDFString::getFilteredString() const { int nLen = m_aString.getLength(); OStringBuffer aBuf( nLen ); - + const sal_Char* pStr = m_aString.getStr(); if( *pStr == '(' ) { @@ -295,7 +295,7 @@ OString PDFString::getFilteredString() const aBuf.append( rResult ); } } - + return aBuf.makeStringAndClear(); } @@ -307,7 +307,7 @@ bool PDFNumber::emit( EmitContext& rWriteContext ) const { rtl::OStringBuffer aBuf( 32 ); aBuf.append( ' ' ); - + double fValue = m_fValue; bool bNeg = false; int nPrecision = 5; @@ -347,7 +347,7 @@ bool PDFNumber::emit( EmitContext& rWriteContext ) const nBound /= 10; } } - + return rWriteContext.write( aBuf.getStr(), aBuf.getLength() ); } @@ -484,7 +484,7 @@ void PDFDict::insertValue( const OString& rName, PDFEntry* pValue ) { if( ! pValue ) eraseValue( rName ); - + std::hash_map<OString,PDFEntry*,OStringHash>::iterator it = m_aMap.find( rName ); if( it == m_aMap.end() ) { @@ -647,7 +647,7 @@ bool PDFObject::getDeflatedStream( char** ppStream, unsigned int* pBytes, const pFilter = dynamic_cast<PDFName*>(pArray->m_aSubElements.front()); } } - + // is the (first) filter FlateDecode ? if( pFilter && pFilter->m_aName.equals( "FlateDecode" ) ) { @@ -691,7 +691,7 @@ static void unzipToBuffer( const char* pBegin, unsigned int nLen, aZStr.zfree = ( free_func )0; aZStr.opaque = ( voidpf )0; inflateInit(&aZStr); - + const unsigned int buf_increment_size = 16384; *pOutBuf = (sal_uInt8*)rtl_reallocateMemory( *pOutBuf, buf_increment_size ); @@ -754,11 +754,11 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const { if( ! rWriteContext.write( "\n", 1 ) ) return false; - + EmitImplData* pEData = getEmitData( rWriteContext ); if( pEData ) pEData->insertXref( m_nNumber, m_nGeneration, rWriteContext.getCurPos() ); - + OStringBuffer aBuf( 32 ); aBuf.append( sal_Int32( m_nNumber ) ); aBuf.append( ' ' ); @@ -766,7 +766,7 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const aBuf.append( " obj\n" ); if( ! rWriteContext.write( aBuf.getStr(), aBuf.getLength() ) ) return false; - + if( rWriteContext.m_bDeflate && pEData ) { char* pStream = NULL; @@ -943,9 +943,9 @@ struct PDFFileImplData OString m_aDocID; rtlCipher m_aCipher; rtlDigest m_aDigest; - + sal_uInt8 m_aDecryptionKey[ENCRYPTION_KEY_LEN+5]; // maximum handled key length - + PDFFileImplData() : m_bIsEncrypted( false ), m_bStandardHandler( false ), @@ -960,7 +960,7 @@ struct PDFFileImplData rtl_zeroMemory( m_aUEntry, sizeof( m_aUEntry ) ); rtl_zeroMemory( m_aDecryptionKey, sizeof( m_aDecryptionKey ) ); } - + ~PDFFileImplData() { if( m_aCipher ) @@ -987,10 +987,10 @@ bool PDFFile::decrypt( const sal_uInt8* pInBuffer, sal_uInt32 nLen, sal_uInt8* p { if( ! isEncrypted() ) return false; - + if( ! m_pData->m_aCipher ) m_pData->m_aCipher = rtl_cipher_createARCFOUR( rtl_Cipher_ModeStream ); - + // modify encryption key sal_uInt32 i = m_pData->m_nKeyLength; m_pData->m_aDecryptionKey[i++] = sal_uInt8(nObject&0xff); @@ -998,11 +998,11 @@ bool PDFFile::decrypt( const sal_uInt8* pInBuffer, sal_uInt32 nLen, sal_uInt8* p m_pData->m_aDecryptionKey[i++] = sal_uInt8((nObject>>16)&0xff); m_pData->m_aDecryptionKey[i++] = sal_uInt8(nGeneration&0xff); m_pData->m_aDecryptionKey[i++] = sal_uInt8((nGeneration>>8)&0xff); - + sal_uInt8 aSum[ENCRYPTION_KEY_LEN]; rtl_digest_updateMD5( m_pData->m_aDigest, m_pData->m_aDecryptionKey, i ); rtl_digest_getMD5( m_pData->m_aDigest, aSum, sizeof( aSum ) ); - + if( i > 16 ) i = 16; @@ -1085,12 +1085,12 @@ static bool check_user_password( const OString& rPwd, PDFFileImplData* pData ) { // see PDF reference 1.4 Algorithm 3.4 // encrypt pad string - rtl_cipher_initARCFOUR( pData->m_aCipher, rtl_Cipher_DirectionEncode, + rtl_cipher_initARCFOUR( pData->m_aCipher, rtl_Cipher_DirectionEncode, aKey, nKeyLen, NULL, 0 ); rtl_cipher_encodeARCFOUR( pData->m_aCipher, nPadString, sizeof( nPadString ), nEncryptedEntry, sizeof( nEncryptedEntry ) ); - bValid = (rtl_compareMemory( nEncryptedEntry, pData->m_aUEntry, 32 ) == 0); + bValid = (rtl_compareMemory( nEncryptedEntry, pData->m_aUEntry, 32 ) == 0); } else if( pData->m_nStandardRevision == 3 ) { @@ -1098,7 +1098,7 @@ static bool check_user_password( const OString& rPwd, PDFFileImplData* pData ) rtl_digest_updateMD5( pData->m_aDigest, nPadString, sizeof( nPadString ) ); rtl_digest_updateMD5( pData->m_aDigest, pData->m_aDocID.getStr(), pData->m_aDocID.getLength() ); rtl_digest_getMD5( pData->m_aDigest, nEncryptedEntry, sizeof(nEncryptedEntry) ); - rtl_cipher_initARCFOUR( pData->m_aCipher, rtl_Cipher_DirectionEncode, + rtl_cipher_initARCFOUR( pData->m_aCipher, rtl_Cipher_DirectionEncode, aKey, sizeof(aKey), NULL, 0 ); rtl_cipher_encodeARCFOUR( pData->m_aCipher, nEncryptedEntry, 16, @@ -1108,14 +1108,14 @@ static bool check_user_password( const OString& rPwd, PDFFileImplData* pData ) sal_uInt8 aTempKey[ENCRYPTION_KEY_LEN]; for( sal_uInt32 j = 0; j < sizeof(aTempKey); j++ ) aTempKey[j] = static_cast<sal_uInt8>( aKey[j] ^ i ); - - rtl_cipher_initARCFOUR( pData->m_aCipher, rtl_Cipher_DirectionEncode, + + rtl_cipher_initARCFOUR( pData->m_aCipher, rtl_Cipher_DirectionEncode, aTempKey, sizeof(aTempKey), NULL, 0 ); rtl_cipher_encodeARCFOUR( pData->m_aCipher, nEncryptedEntry, 16, nEncryptedEntry, 16 ); // encrypt in place } - bValid = (rtl_compareMemory( nEncryptedEntry, pData->m_aUEntry, 16 ) == 0); + bValid = (rtl_compareMemory( nEncryptedEntry, pData->m_aUEntry, 16 ) == 0); } return bValid; } @@ -1124,7 +1124,7 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const { if( !impl_getData()->m_bIsEncrypted ) return rPwd.getLength() == 0; - + // check if we can handle this encryption at all if( ! m_pData->m_bStandardHandler || m_pData->m_nAlgoVersion < 1 || @@ -1132,15 +1132,15 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const m_pData->m_nStandardRevision < 2 || m_pData->m_nStandardRevision > 3 ) return false; - + if( ! m_pData->m_aCipher ) m_pData->m_aCipher = rtl_cipher_createARCFOUR(rtl_Cipher_ModeStream); if( ! m_pData->m_aDigest ) m_pData->m_aDigest = rtl_digest_createMD5(); - + // first try user password bool bValid = check_user_password( rPwd, m_pData ); - + if( ! bValid ) { // try owner password @@ -1151,7 +1151,7 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const sal_uInt32 nKeyLen = password_to_key( rPwd, aKey, m_pData, true ); if( m_pData->m_nStandardRevision == 2 ) { - rtl_cipher_initARCFOUR( m_pData->m_aCipher, rtl_Cipher_DirectionDecode, + rtl_cipher_initARCFOUR( m_pData->m_aCipher, rtl_Cipher_DirectionDecode, aKey, nKeyLen, NULL, 0 ); rtl_cipher_decodeARCFOUR( m_pData->m_aCipher, m_pData->m_aOEntry, 32, @@ -1165,7 +1165,7 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const sal_uInt8 nTempKey[ENCRYPTION_KEY_LEN]; for( unsigned int j = 0; j < sizeof(nTempKey); j++ ) nTempKey[j] = sal_uInt8(aKey[j] ^ i); - rtl_cipher_initARCFOUR( m_pData->m_aCipher, rtl_Cipher_DirectionDecode, + rtl_cipher_initARCFOUR( m_pData->m_aCipher, rtl_Cipher_DirectionDecode, nTempKey, nKeyLen, NULL, 0 ); rtl_cipher_decodeARCFOUR( m_pData->m_aCipher, nPwd, 32, @@ -1315,17 +1315,17 @@ PDFFileImplData* PDFFile::impl_getData() const break; } } - } + } } } - + return m_pData; } bool PDFFile::emit( EmitContext& rWriteContext ) const { setEmitData( rWriteContext, new EmitImplData( this ) ); - + OStringBuffer aBuf( 32 ); aBuf.append( "%PDF-" ); aBuf.append( sal_Int32( m_nMajor ) ); |