split MSCodec_Std97 into a baseclass MSCodec97
Change-Id: Ia3c41a048169c78684800def94e53fc9f3201e30
diff --git a/filter/source/msfilter/mscodec.cxx b/filter/source/msfilter/mscodec.cxx
index 9b9d243..20a1f4a 100644
--- a/filter/source/msfilter/mscodec.cxx
+++ b/filter/source/msfilter/mscodec.cxx
@@ -245,27 +245,31 @@ void MSCodec_Xor95::Skip( std::size_t nBytes )
mnOffset = (mnOffset + nBytes) & 0x0F;
}
MSCodec_Std97::MSCodec_Std97 ()
MSCodec97::MSCodec97(rtlCipher hCipher)
: m_hCipher(hCipher)
{
m_hCipher = rtl_cipher_create (
rtl_Cipher_AlgorithmARCFOUR, rtl_Cipher_ModeStream);
OSL_ASSERT(m_hCipher != nullptr);
}
m_hDigest = rtl_digest_create (
rtl_Digest_AlgorithmMD5);
OSL_ASSERT(m_hDigest != nullptr);
MSCodec_Std97::MSCodec_Std97()
: MSCodec97(rtl_cipher_create(rtl_Cipher_AlgorithmARCFOUR, rtl_Cipher_ModeStream))
{
assert(m_hCipher != nullptr);
m_hDigest = rtl_digest_create(rtl_Digest_AlgorithmMD5);
assert(m_hDigest != nullptr);
(void)memset (m_pDigestValue, 0, sizeof(m_pDigestValue));
(void)memset (m_pDocId, 0, sizeof(m_pDocId));
}
MSCodec_Std97::~MSCodec_Std97 ()
MSCodec97::~MSCodec97()
{
rtl_cipher_destroy(m_hCipher);
}
MSCodec_Std97::~MSCodec_Std97()
{
(void)memset (m_pDigestValue, 0, sizeof(m_pDigestValue));
(void)memset (m_pDocId, 0, sizeof(m_pDocId));
rtl_digest_destroy (m_hDigest);
rtl_cipher_destroy (m_hCipher);
rtl_digest_destroy(m_hDigest);
}
#if DEBUG_MSO_ENCRYPTION_STD97
@@ -431,7 +435,7 @@ void MSCodec_Std97::CreateSaltDigest( const sal_uInt8 nSaltData[16], sal_uInt8 n
}
}
bool MSCodec_Std97::Encode (
bool MSCodec97::Encode (
const void *pData, std::size_t nDatLen,
sal_uInt8 *pBuffer, std::size_t nBufLen)
{
@@ -441,7 +445,7 @@ bool MSCodec_Std97::Encode (
return (result == rtl_Cipher_E_None);
}
bool MSCodec_Std97::Decode (
bool MSCodec97::Decode (
const void *pData, std::size_t nDatLen,
sal_uInt8 *pBuffer, std::size_t nBufLen)
{
@@ -451,7 +455,7 @@ bool MSCodec_Std97::Decode (
return (result == rtl_Cipher_E_None);
}
bool MSCodec_Std97::Skip( std::size_t nDatLen )
bool MSCodec97::Skip(std::size_t nDatLen)
{
sal_uInt8 pnDummy[ 1024 ];
std::size_t nDatLeft = nDatLen;
diff --git a/include/filter/msfilter/mscodec.hxx b/include/filter/msfilter/mscodec.hxx
index fa71a15..afdf163 100644
--- a/include/filter/msfilter/mscodec.hxx
+++ b/include/filter/msfilter/mscodec.hxx
@@ -174,6 +174,117 @@ public:
virtual void Decode( sal_uInt8* pnData, std::size_t nBytes ) override;
};
class MSFILTER_DLLPUBLIC MSCodec97
{
public:
MSCodec97(rtlCipher m_hCipher);
virtual ~MSCodec97();
/** Initializes the algorithm with the encryption data.
@param aData
The sequence contains the necessary data to initialize
the codec.
*/
virtual bool InitCodec(const css::uno::Sequence< css::beans::NamedValue >& aData) = 0;
/** Retrieves the encryption data
@return
The sequence contains the necessary data to initialize
the codec.
*/
virtual css::uno::Sequence< css::beans::NamedValue > GetEncryptionData() = 0;
/** Rekeys the codec using the specified counter.
After reading a specific amount of data the cipher algorithm needs to
be rekeyed using a counter that counts the data blocks.
The block size is for example 512 Bytes for Word files and 1024 Bytes
for Excel files.
@precond
The codec must be initialized with InitKey() before this function
can be used.
@param nCounter
Block counter used to rekey the cipher.
*/
virtual bool InitCipher(sal_uInt32 nCounter) = 0;
/** Encodes a block of memory.
@see rtl_cipher_encode()
@precond
The codec must be initialized with InitKey() before this function
can be used. The destination buffer must be able to take all
unencoded data from the source buffer (usually this means it must be
as long as or longer than the source buffer).
@param pData
Unencrypted source data block.
@param nDatLen
Size of the passed source data block.
@param pBuffer
Destination buffer for the encrypted data.
@param nBufLen
Size of the destination buffer.
@return
true = Encoding was successful (no error occurred).
*/
bool Encode(const void* pData, std::size_t nDatLen,
sal_uInt8* pBuffer, std::size_t nBufLen);
/** Decodes a block of memory.
@see rtl_cipher_decode()
@precond
The codec must be initialized with InitKey() before this function
can be used. The destination buffer must be able to take all
encoded data from the source buffer (usually this means it must be
as long as or longer than the source buffer).
@param pData
Encrypted source data block.
@param nDatLen
Size of the passed source data block.
@param pBuffer
Destination buffer for the decrypted data.
@param nBufLen
Size of the destination buffer.
@return
true = Decoding was successful (no error occurred).
*/
bool Decode(const void* pData, std::size_t nDatLen,
sal_uInt8* pBuffer, std::size_t nBufLen);
/** Lets the cipher skip a specific amount of bytes.
This function sets the cipher to the same state as if the specified
amount of data has been decoded with one or more calls of Decode().
@precond
The codec must be initialized with InitKey() before this function
can be used.
@param nDatLen
Number of bytes to be skipped (cipher "seeks" forward).
*/
bool Skip(std::size_t nDatLen);
private:
MSCodec97(const MSCodec97&) = delete;
MSCodec97& operator=(const MSCodec97&) = delete;
protected:
rtlCipher m_hCipher;
};
/** Encodes and decodes data from protected MSO 97+ documents.
@@ -181,7 +292,7 @@ public:
Implementation is based on the wvDecrypt package by Caolan McNamara:
http://www.csn.ul.ie/~caolan/docs/wvDecrypt.html
*/
class MSFILTER_DLLPUBLIC MSCodec_Std97
class MSFILTER_DLLPUBLIC MSCodec_Std97 : public MSCodec97
{
public:
explicit MSCodec_Std97();
@@ -193,7 +304,7 @@ public:
The sequence contains the necessary data to initialize
the codec.
*/
bool InitCodec( const css::uno::Sequence< css::beans::NamedValue >& aData );
virtual bool InitCodec(const css::uno::Sequence< css::beans::NamedValue >& aData) override;
/** Retrieves the encryption data
@@ -201,7 +312,7 @@ public:
The sequence contains the necessary data to initialize
the codec.
*/
css::uno::Sequence< css::beans::NamedValue > GetEncryptionData();
virtual css::uno::Sequence<css::beans::NamedValue> GetEncryptionData() override;
/** Initializes the algorithm with the specified password and document ID.
@@ -249,78 +360,12 @@ public:
@param nCounter
Block counter used to rekey the cipher.
*/
bool InitCipher( sal_uInt32 nCounter );
virtual bool InitCipher(sal_uInt32 nCounter) override;
/** Creates an MD5 digest of salt digest. */
void CreateSaltDigest(
const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] );
/** Encodes a block of memory.
@see rtl_cipher_encode()
@precond
The codec must be initialized with InitKey() before this function
can be used. The destination buffer must be able to take all
unencoded data from the source buffer (usually this means it must be
as long as or longer than the source buffer).
@param pData
Unencrypted source data block.
@param nDatLen
Size of the passed source data block.
@param pBuffer
Destination buffer for the encrypted data.
@param nBufLen
Size of the destination buffer.
@return
true = Encoding was successful (no error occurred).
*/
bool Encode(
const void* pData, std::size_t nDatLen,
sal_uInt8* pBuffer, std::size_t nBufLen );
/** Decodes a block of memory.
@see rtl_cipher_decode()
@precond
The codec must be initialized with InitKey() before this function
can be used. The destination buffer must be able to take all
encoded data from the source buffer (usually this means it must be
as long as or longer than the source buffer).
@param pData
Encrypted source data block.
@param nDatLen
Size of the passed source data block.
@param pBuffer
Destination buffer for the decrypted data.
@param nBufLen
Size of the destination buffer.
@return
true = Decoding was successful (no error occurred).
*/
bool Decode(
const void* pData, std::size_t nDatLen,
sal_uInt8* pBuffer, std::size_t nBufLen );
/** Lets the cipher skip a specific amount of bytes.
This function sets the cipher to the same state as if the specified
amount of data has been decoded with one or more calls of Decode().
@precond
The codec must be initialized with InitKey() before this function
can be used.
@param nDatLen
Number of bytes to be skipped (cipher "seeks" forward).
*/
bool Skip( std::size_t nDatLen );
/** Gets salt data and salt digest.
@precond
@@ -349,7 +394,6 @@ private:
MSCodec_Std97( const MSCodec_Std97& ) = delete;
MSCodec_Std97& operator=( const MSCodec_Std97& ) = delete;
rtlCipher m_hCipher;
rtlDigest m_hDigest;
sal_uInt8 m_pDigestValue[ RTL_DIGEST_LENGTH_MD5 ];
sal_uInt8 m_pDocId[16];