comphelper/qa/unit/test_hash.cxx | 10 ++--- comphelper/source/misc/hash.cxx | 34 ++++++------------ comphelper/source/misc/storagehelper.cxx | 4 +- connectivity/source/commontools/ConnectionWrapper.cxx | 10 ++--- desktop/source/app/updater.cxx | 2 - filter/source/msfilter/svdfppt.cxx | 6 +-- include/comphelper/hash.hxx | 8 ++-- package/source/zipapi/sha1context.cxx | 2 - sd/source/filter/eppt/pptx-epptooxml.cxx | 2 - sdext/source/pdfimport/pdfparse/pdfentries.cxx | 6 +-- svl/source/crypto/cryptosign.cxx | 2 - svl/source/misc/PasswordHelper.cxx | 4 +- sw/source/filter/basflt/iodetect.cxx | 10 +---- vcl/source/filter/png/PngImageReader.cxx | 5 -- vcl/source/gdi/pdfwriter_impl.cxx | 7 +-- xmloff/source/style/XMLFontAutoStylePool.cxx | 2 - 16 files changed, 47 insertions(+), 67 deletions(-)
New commits: commit 83ed6aa69c100617763987f7cb063bdda13ef033 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Jun 25 19:06:05 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Jun 26 06:39:06 2025 +0200 Use OSL_SWAPWORD and friends, instead of ad-hoc code Unifies and simplifies the code a bit. Change-Id: I6c6286a0193cf1dc9d2926df8fa86d2d5b25db88 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186983 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx index 1bee212dda6d..513372bf8b01 100644 --- a/comphelper/source/misc/hash.cxx +++ b/comphelper/source/misc/hash.cxx @@ -243,10 +243,7 @@ std::vector<unsigned char> Hash::calculateHash( if (nAddIter) { #ifdef OSL_BIGENDIAN - sal_uInt32 be = i; - sal_uInt8* p = reinterpret_cast<sal_uInt8*>(&be); - std::swap( p[0], p[3] ); - std::swap( p[1], p[2] ); + sal_uInt32 be = OSL_SWAPDWORD(i); memcpy( data.data() + nIterPos, &be, nAddIter); #else memcpy( data.data() + nIterPos, &i, nAddIter); @@ -274,17 +271,12 @@ std::vector<unsigned char> Hash::calculateHash( const size_t nPassBytesLen = rPassword.length() * 2; #ifdef OSL_BIGENDIAN // Swap UTF16-BE to UTF16-LE - std::vector<unsigned char> vPass; + std::vector<char16_t> vPass; if (nPassBytesLen) { - vPass.resize( nPassBytesLen); - std::copy( pPassBytes, pPassBytes + nPassBytesLen, vPass.begin()); - unsigned char* p = vPass.data(); - unsigned char const * const pEnd = p + nPassBytesLen; - for ( ; p < pEnd; p += 2 ) - { - std::swap( p[0], p[1] ); - } + vPass.insert(vPass.begin(), rPassword.begin(), rPassword.end()); + for (char16_t& ch : vPass) + ch = OSL_SWAPWORD(ch); pPassBytes = vPass.data(); } #endif diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx index d39674ce2eb3..0a6789b33882 100644 --- a/filter/source/msfilter/svdfppt.cxx +++ b/filter/source/msfilter/svdfppt.cxx @@ -446,7 +446,7 @@ SvStream& ReadPptFontEntityAtom( SvStream& rIn, PptFontEntityAtom& rAtom ) if ( !nTemp ) break; #ifdef OSL_BIGENDIAN - cData[ i ] = ( nTemp >> 8 ) | ( nTemp << 8 ); + cData[i] = OSL_SWAPWORD(nTemp); #endif } rAtom.aName = OUString(cData, i); @@ -5196,11 +5196,9 @@ void PPTStyleTextPropReader::Init( SvStream& rIn, const DffRecordHeader& rTextHe sal_Unicode* pPtr = aBuf.data(); #ifdef OSL_BIGENDIAN - sal_Unicode nTemp; for ( i = 0; i < nMaxLen; i++ ) { - nTemp = *pPtr; - *pPtr++ = ( nTemp << 8 ) | ( nTemp >> 8 ); + *pPtr++ = OSL_SWAPWORD(*pPtr); } pPtr = aBuf.data(); #endif diff --git a/sw/source/filter/basflt/iodetect.cxx b/sw/source/filter/basflt/iodetect.cxx index 144bc1c86bb0..104067ac2eb8 100644 --- a/sw/source/filter/basflt/iodetect.cxx +++ b/sw/source/filter/basflt/iodetect.cxx @@ -359,14 +359,8 @@ bool SwIoSystem::IsDetectableText(const char* pBuf, sal_uLong &rLen, if (bLE != bNativeLE) { bSwap = true; - char* pF = reinterpret_cast<char*>(pNewBuf); - char* pN = pF+1; - for(sal_uLong n = 0; n < nNewLen; ++n, pF+=2, pN+=2 ) - { - char c = *pF; - *pF = *pN; - *pN = c; - } + for (sal_uLong n = 0; n < nNewLen; ++n) + pNewBuf[n] = OSL_SWAPWORD(pNewBuf[n]); } } diff --git a/vcl/source/filter/png/PngImageReader.cxx b/vcl/source/filter/png/PngImageReader.cxx index eff637cdddf1..1af01a71610e 100644 --- a/vcl/source/filter/png/PngImageReader.cxx +++ b/vcl/source/filter/png/PngImageReader.cxx @@ -824,10 +824,7 @@ BinaryDataContainer getMsGifChunk(SvStream& rStream) if (type == PNGCHUNK_msOG && length > MSGifHeaderSize) { // calculate chunktype CRC (swap it back to original byte order) - sal_uInt32 typeForCrc = type; -#if defined(__LITTLEENDIAN) || defined(OSL_LITENDIAN) - typeForCrc = OSL_SWAPDWORD(typeForCrc); -#endif + sal_uInt32 typeForCrc = OSL_NETDWORD(type); sal_uInt32 computedCrc = rtl_crc32(0, &typeForCrc, 4); const sal_uInt64 pos = rStream.Tell(); if (pos + length >= rStream.TellEnd()) commit 35256f5b366feafea718af1dbf02ca144899cef4 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Jun 25 18:50:10 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Jun 26 06:38:59 2025 +0200 Let Hash take const void* instead of const unsigned char* It makes no sense to insist on a random type, only to reinterpret_cast it everywhere. An opaque void fits the case perfectly. Change-Id: If945b1c59d98c5f561350db649f29fe8036e7cdb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186982 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/comphelper/qa/unit/test_hash.cxx b/comphelper/qa/unit/test_hash.cxx index af239006b7e5..504d7926e67f 100644 --- a/comphelper/qa/unit/test_hash.cxx +++ b/comphelper/qa/unit/test_hash.cxx @@ -51,7 +51,7 @@ void TestHash::testMD5() { comphelper::Hash aHash(comphelper::HashType::MD5); const char* const pInput = ""; - aHash.update(reinterpret_cast<const unsigned char*>(pInput), 0); + aHash.update(pInput, 0); std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(16), calculate_hash.size()); CPPUNIT_ASSERT_EQUAL(std::string("d41d8cd98f00b204e9800998ecf8427e"), comphelper::hashToString(calculate_hash)); @@ -61,7 +61,7 @@ void TestHash::testSHA1() { comphelper::Hash aHash(comphelper::HashType::SHA1); const char* const pInput = ""; - aHash.update(reinterpret_cast<const unsigned char*>(pInput), 0); + aHash.update(pInput, 0); std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(20), calculate_hash.size()); CPPUNIT_ASSERT_EQUAL(std::string("da39a3ee5e6b4b0d3255bfef95601890afd80709"), comphelper::hashToString(calculate_hash)); @@ -71,7 +71,7 @@ void TestHash::testSHA256() { comphelper::Hash aHash(comphelper::HashType::SHA256); const char* const pInput = ""; - aHash.update(reinterpret_cast<const unsigned char*>(pInput), 0); + aHash.update(pInput, 0); std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(32), calculate_hash.size()); CPPUNIT_ASSERT_EQUAL(std::string("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), comphelper::hashToString(calculate_hash)); @@ -81,7 +81,7 @@ void TestHash::testSHA512() { comphelper::Hash aHash(comphelper::HashType::SHA512); const char* const pInput = ""; - aHash.update(reinterpret_cast<const unsigned char*>(pInput), 0); + aHash.update(pInput, 0); std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(64), calculate_hash.size()); std::string aStr("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); @@ -93,7 +93,7 @@ void TestHash::testSHA512_NoSaltNoSpin() { const char* const pInput = ""; std::vector<unsigned char> calculate_hash = - comphelper::Hash::calculateHash( reinterpret_cast<const unsigned char*>(pInput), 0, + comphelper::Hash::calculateHash(pInput, 0, nullptr, 0, 0, comphelper::Hash::IterCount::NONE, comphelper::HashType::SHA512); CPPUNIT_ASSERT_EQUAL(size_t(64), calculate_hash.size()); std::string aStr("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx index 96c8804bf6fc..1bee212dda6d 100644 --- a/comphelper/source/misc/hash.cxx +++ b/comphelper/source/misc/hash.cxx @@ -140,10 +140,10 @@ Hash::~Hash() { } -void Hash::update(const unsigned char* pInput, size_t length) +void Hash::update(const void* pInput, size_t length) { #if USE_TLS_NSS - HASH_Update(mpImpl->mpContext, pInput, length); + HASH_Update(mpImpl->mpContext, static_cast<const unsigned char*>(pInput), length); #elif USE_TLS_OPENSSL EVP_DigestUpdate(mpImpl->mpContext, pInput, length); #else @@ -191,7 +191,7 @@ size_t Hash::getLength() const return 0; } -std::vector<unsigned char> Hash::calculateHash(const unsigned char* pInput, size_t length, HashType eType) +std::vector<unsigned char> Hash::calculateHash(const void* pInput, size_t length, HashType eType) { Hash aHash(eType); aHash.update(pInput, length); @@ -199,8 +199,8 @@ std::vector<unsigned char> Hash::calculateHash(const unsigned char* pInput, size } std::vector<unsigned char> Hash::calculateHash( - const unsigned char* pInput, size_t nLength, - const unsigned char* pSalt, size_t nSaltLen, + const void* pInput, size_t nLength, + const void* pSalt, size_t nSaltLen, sal_uInt32 nSpinCount, IterCount eIterCount, HashType eType) @@ -215,8 +215,8 @@ std::vector<unsigned char> Hash::calculateHash( if (nSaltLen) { std::vector<unsigned char> initialData( nSaltLen + nLength); - std::copy( pSalt, pSalt + nSaltLen, initialData.begin()); - std::copy( pInput, pInput + nLength, initialData.begin() + nSaltLen); + std::copy_n(static_cast<const unsigned char*>(pSalt), nSaltLen, initialData.begin()); + std::copy_n(static_cast<const unsigned char*>(pInput), nLength, initialData.begin() + nSaltLen); aHash.update( initialData.data(), initialData.size()); rtl_secureZeroMemory( initialData.data(), initialData.size()); } @@ -270,7 +270,7 @@ std::vector<unsigned char> Hash::calculateHash( IterCount eIterCount, HashType eType) { - const unsigned char* pPassBytes = reinterpret_cast<const unsigned char*>(rPassword.data()); + const void* pPassBytes = rPassword.data(); const size_t nPassBytesLen = rPassword.length() * 2; #ifdef OSL_BIGENDIAN // Swap UTF16-BE to UTF16-LE diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index 8304effe6693..b504aef0be61 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -375,7 +375,7 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( { OString aUTF8Password( OUStringToOString( aPassword, RTL_TEXTENCODING_UTF8 ) ); std::vector<unsigned char> const hash(comphelper::Hash::calculateHash( - reinterpret_cast<unsigned char const*>(aUTF8Password.getStr()), aUTF8Password.getLength(), + aUTF8Password.getStr(), aUTF8Password.getLength(), comphelper::HashType::SHA256)); uno::Sequence<sal_Int8> aDigest(reinterpret_cast<const sal_Int8*>(hash.data()), hash.size()); @@ -423,7 +423,7 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( pEncryptionData[nSha1Ind + 2].Name = PACKAGE_ENCRYPTIONDATA_SHA1CORRECT; OString aByteStrPass = OUStringToOString(aPassword, RTL_TEXTENCODING_UTF8); std::vector<unsigned char> const sha1(::comphelper::Hash::calculateHash( - reinterpret_cast<unsigned char const*>(aByteStrPass.getStr()), aByteStrPass.getLength(), + aByteStrPass.getStr(), aByteStrPass.getLength(), ::comphelper::HashType::SHA1)); pEncryptionData[nSha1Ind + 2].Value <<= uno::Sequence<sal_Int8>( reinterpret_cast<sal_Int8 const*>(sha1.data()), sha1.size()); diff --git a/connectivity/source/commontools/ConnectionWrapper.cxx b/connectivity/source/commontools/ConnectionWrapper.cxx index 12e3645ed27b..ec244af8130b 100644 --- a/connectivity/source/commontools/ConnectionWrapper.cxx +++ b/connectivity/source/commontools/ConnectionWrapper.cxx @@ -201,11 +201,11 @@ void OConnectionWrapper::createUniqueId( const OUString& _rURL { // first we create the digest we want to have ::comphelper::Hash sha1(::comphelper::HashType::SHA1); - sha1.update(reinterpret_cast<unsigned char const*>(_rURL.getStr()), _rURL.getLength() * sizeof(sal_Unicode)); + sha1.update(_rURL.getStr(), _rURL.getLength() * sizeof(sal_Unicode)); if ( !_rUserName.isEmpty() ) - sha1.update(reinterpret_cast<unsigned char const*>(_rUserName.getStr()), _rUserName.getLength() * sizeof(sal_Unicode)); + sha1.update(_rUserName.getStr(), _rUserName.getLength() * sizeof(sal_Unicode)); if ( !_rPassword.isEmpty() ) - sha1.update(reinterpret_cast<unsigned char const*>(_rPassword.getStr()), _rPassword.getLength() * sizeof(sal_Unicode)); + sha1.update(_rPassword.getStr(), _rPassword.getLength() * sizeof(sal_Unicode)); // now we need to sort the properties auto [begin, end] = asNonConstRange(_rInfo); std::sort(begin,end,TPropertyValueLessFunctor()); @@ -227,14 +227,14 @@ void OConnectionWrapper::createUniqueId( const OUString& _rURL if ( prop.Value >>= aSeq ) { for (OUString const& s : aSeq) - sha1.update(reinterpret_cast<unsigned char const*>(s.getStr()), s.getLength() * sizeof(sal_Unicode)); + sha1.update(s.getStr(), s.getLength() * sizeof(sal_Unicode)); } } } if ( !sValue.isEmpty() ) { // we don't have to convert this into UTF8 because we don't store on a file system - sha1.update(reinterpret_cast<unsigned char const*>(sValue.getStr()), sValue.getLength() * sizeof(sal_Unicode)); + sha1.update(sValue.getStr(), sValue.getLength() * sizeof(sal_Unicode)); } } diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx index 061d9ceebd81..d0e90ec5c03e 100644 --- a/desktop/source/app/updater.cxx +++ b/desktop/source/app/updater.cxx @@ -543,7 +543,7 @@ size_t WriteCallbackFile(void *ptr, size_t size, WriteDataFile* response = static_cast<WriteDataFile *>(userp); size_t real_size = size * nmemb; response->mpStream->WriteBytes(ptr, real_size); - response->maHash.update(static_cast<const unsigned char*>(ptr), real_size); + response->maHash.update(ptr, real_size); return real_size; } diff --git a/include/comphelper/hash.hxx b/include/comphelper/hash.hxx index b6c226f82c84..7e49b7d2efec 100644 --- a/include/comphelper/hash.hxx +++ b/include/comphelper/hash.hxx @@ -59,7 +59,7 @@ public: Hash(HashType eType); ~Hash(); - void update(const unsigned char* pInput, size_t length); + void update(const void* pInput, size_t length); void update(std::vector<unsigned char> const& rInput) { @@ -70,7 +70,7 @@ public: std::vector<unsigned char> finalize(); - static std::vector<unsigned char> calculateHash(const unsigned char* pInput, size_t length, HashType eType); + static std::vector<unsigned char> calculateHash(const void* pInput, size_t length, HashType eType); /** Calculate hash value with salt (pSalt,nSaltLen) prepended to password (pInput,nLength) and repeated iterations run if nSpinCount>0. @@ -102,8 +102,8 @@ public: @return the raw hash value */ static std::vector<unsigned char> calculateHash( - const unsigned char* pInput, size_t nLength, - const unsigned char* pSalt, size_t nSaltLen, + const void* pInput, size_t nLength, + const void* pSalt, size_t nSaltLen, sal_uInt32 nSpinCount, IterCount eIterCount, HashType eType); diff --git a/package/source/zipapi/sha1context.cxx b/package/source/zipapi/sha1context.cxx index 6706259a6666..bbe5386bb893 100644 --- a/package/source/zipapi/sha1context.cxx +++ b/package/source/zipapi/sha1context.cxx @@ -102,7 +102,7 @@ void SAL_CALL CorrectSHA1DigestContext::updateDigest(const uno::Sequence<::sal_I if (m_bDisposed) throw lang::DisposedException(); - m_Hash.update(reinterpret_cast<unsigned char const*>(rData.getConstArray()), rData.getLength()); + m_Hash.update(rData.getConstArray(), rData.getLength()); } uno::Sequence<::sal_Int8> SAL_CALL CorrectSHA1DigestContext::finalizeDigestAndDispose() diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index 2174b6c32ebe..963263ddb2a6 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -788,7 +788,7 @@ void PowerPointExport::WriteEmbeddedFontList() break; rFontData.insert(rFontData.end(), buffer.data(), buffer.data() + readSize); - aHashCalc.update(reinterpret_cast<const unsigned char*>(buffer.data()), readSize); + aHashCalc.update(buffer.data(), readSize); } std::string aHash = comphelper::hashToString(aHashCalc.finalize()); diff --git a/sdext/source/pdfimport/pdfparse/pdfentries.cxx b/sdext/source/pdfimport/pdfparse/pdfentries.cxx index 856dc373bf36..6f781149c3e8 100644 --- a/sdext/source/pdfimport/pdfparse/pdfentries.cxx +++ b/sdext/source/pdfimport/pdfparse/pdfentries.cxx @@ -1118,7 +1118,7 @@ static sal_uInt32 password_to_key( const OString& rPwd, sal_uInt8* pOutKey, PDFF char aPadPwd[ENCRYPTION_BUF_LEN]; pad_or_truncate_to_32( rPwd, aPadPwd ); ::comphelper::Hash aDigest(::comphelper::HashType::MD5); - aDigest.update(reinterpret_cast<unsigned char const*>(aPadPwd), sizeof(aPadPwd)); + aDigest.update(aPadPwd, sizeof(aPadPwd)); if( ! bComputeO ) { aDigest.update(pData->m_aOEntry, 32); @@ -1128,7 +1128,7 @@ static sal_uInt32 password_to_key( const OString& rPwd, sal_uInt8* pOutKey, PDFF aPEntry[2] = static_cast<sal_uInt8>((pData->m_nPEntry >> 16) & 0xff); aPEntry[3] = static_cast<sal_uInt8>((pData->m_nPEntry >> 24) & 0xff); aDigest.update(aPEntry, sizeof(aPEntry)); - aDigest.update(reinterpret_cast<unsigned char const*>(pData->m_aDocID.getStr()), pData->m_aDocID.getLength()); + aDigest.update(pData->m_aDocID.getStr(), pData->m_aDocID.getLength()); } ::std::vector<unsigned char> nSum(aDigest.finalize()); if( pData->m_nStandardRevision == 3 ) @@ -1175,7 +1175,7 @@ static bool check_user_password( const OString& rPwd, PDFFileImplData* pData ) // see PDF reference 1.4 Algorithm 3.5 ::comphelper::Hash aDigest(::comphelper::HashType::MD5); aDigest.update(nPadString, sizeof(nPadString)); - aDigest.update(reinterpret_cast<unsigned char const*>(pData->m_aDocID.getStr()), pData->m_aDocID.getLength()); + aDigest.update(pData->m_aDocID.getStr(), pData->m_aDocID.getLength()); ::std::vector<unsigned char> nEncryptedEntry(aDigest.finalize()); if (rtl_cipher_initARCFOUR( pData->m_aCipher, rtl_Cipher_DirectionEncode, aKey, sizeof(aKey), nullptr, 0 ) diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx index 08240d62517e..e2edcb29496d 100644 --- a/svl/source/crypto/cryptosign.cxx +++ b/svl/source/crypto/cryptosign.cxx @@ -911,7 +911,7 @@ bool Signing::Sign(OStringBuffer& rCMSHexBuffer) comphelper::Hash aHash(comphelper::HashType::SHA256); for (const auto& pair : m_dataBlocks) - aHash.update(static_cast<const unsigned char*>(pair.first), pair.second); + aHash.update(pair.first, pair.second); aHashResult = aHash.finalize(); } diff --git a/svl/source/misc/PasswordHelper.cxx b/svl/source/misc/PasswordHelper.cxx index c98a26eff4af..f2775ae90077 100644 --- a/svl/source/misc/PasswordHelper.cxx +++ b/svl/source/misc/PasswordHelper.cxx @@ -34,7 +34,7 @@ void SvPasswordHelper::GetHashPasswordSHA256(uno::Sequence<sal_Int8>& rPassHash, { OString const tmp(OUStringToOString(rPassword, RTL_TEXTENCODING_UTF8)); ::std::vector<unsigned char> const hash(::comphelper::Hash::calculateHash( - reinterpret_cast<unsigned char const*>(tmp.getStr()), tmp.getLength(), + tmp.getStr(), tmp.getLength(), ::comphelper::HashType::SHA256)); rPassHash.realloc(hash.size()); ::std::copy(hash.begin(), hash.end(), rPassHash.getArray()); @@ -45,7 +45,7 @@ void SvPasswordHelper::GetHashPasswordSHA1UTF8(uno::Sequence<sal_Int8>& rPassHas { OString const tmp(OUStringToOString(rPassword, RTL_TEXTENCODING_UTF8)); ::std::vector<unsigned char> const hash(::comphelper::Hash::calculateHash( - reinterpret_cast<unsigned char const*>(tmp.getStr()), tmp.getLength(), + tmp.getStr(), tmp.getLength(), ::comphelper::HashType::SHA1)); rPassHash.realloc(hash.size()); ::std::copy(hash.begin(), hash.end(), rPassHash.getArray()); diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 88722e9bcfd4..bf564d0571e0 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -631,9 +631,8 @@ void computeDocumentIdentifier(std::vector<sal_uInt8>& o_rIdentifier, o_rCString2 = aCreationMetaDateString.makeStringAndClear(); ::comphelper::Hash aDigest(::comphelper::HashType::MD5); - aDigest.update(reinterpret_cast<unsigned char const*>(&aGMT), sizeof(aGMT)); - aDigest.update(reinterpret_cast<unsigned char const*>(aInfoValuesOut.getStr()), - aInfoValuesOut.getLength()); + aDigest.update(&aGMT, sizeof(aGMT)); + aDigest.update(aInfoValuesOut.getStr(), aInfoValuesOut.getLength()); //the binary form of the doc id is needed for encryption stuff o_rIdentifier = aDigest.finalize(); } @@ -1505,7 +1504,7 @@ bool PDFWriterImpl::writeBufferBytes( const void* pBuffer, sal_uInt64 nBytes ) } const void* pWriteBuffer = bStreamEncryption ? m_vEncryptionBuffer.data() : pBuffer; - m_DocDigest.update(static_cast<unsigned char const*>(pWriteBuffer), sal_uInt32(nActualSize)); + m_DocDigest.update(pWriteBuffer, sal_uInt32(nActualSize)); if (m_aFile.write(pWriteBuffer, nActualSize, nWritten) != osl::File::E_None) diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx b/xmloff/source/style/XMLFontAutoStylePool.cxx index 3034aef14ee9..410ff63c8b45 100644 --- a/xmloff/source/style/XMLFontAutoStylePool.cxx +++ b/xmloff/source/style/XMLFontAutoStylePool.cxx @@ -592,7 +592,7 @@ static OString getFileHash(OUString const & rFileUrl) } if (nReadSize == 0) break; - aHashEngine.update(reinterpret_cast<unsigned char*>(aBuffer), nReadSize); + aHashEngine.update(aBuffer, nReadSize); } return convertToHashString(aHashEngine.finalize()); }