diff options
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/pdf/PDFEncryptorR6.hxx | 6 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/PDFEncryptionTest.cxx | 13 | ||||
-rw-r--r-- | vcl/source/pdf/PDFEncryptorR6.cxx | 11 |
3 files changed, 30 insertions, 0 deletions
diff --git a/vcl/inc/pdf/PDFEncryptorR6.hxx b/vcl/inc/pdf/PDFEncryptorR6.hxx index 70f7a3422f3a..219796ccf0a5 100644 --- a/vcl/inc/pdf/PDFEncryptorR6.hxx +++ b/vcl/inc/pdf/PDFEncryptorR6.hxx @@ -101,6 +101,12 @@ VCL_DLLPUBLIC std::vector<sal_uInt8> encryptPerms(std::vector<sal_uInt8>& rPerms VCL_DLLPUBLIC std::vector<sal_uInt8> createPerms(sal_Int32 nAccessPermissions, bool bEncryptMetadata); +/** Padding as described in Internet RFC 8018 + * + * Described in ISO 32000-2:2020(E) - 7.6.3.1 + */ +VCL_DLLPUBLIC size_t addPaddingToVector(std::vector<sal_uInt8>& rVector, size_t nBlockSize); + } // end vcl::pdf /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/pdfexport/PDFEncryptionTest.cxx b/vcl/qa/cppunit/pdfexport/PDFEncryptionTest.cxx index 408735d12ca2..40a4eb94c1b4 100644 --- a/vcl/qa/cppunit/pdfexport/PDFEncryptionTest.cxx +++ b/vcl/qa/cppunit/pdfexport/PDFEncryptionTest.cxx @@ -244,6 +244,19 @@ CPPUNIT_TEST_FIXTURE(PDFEncryptionTest, testPermsEncryption) CPPUNIT_ASSERT_EQUAL(std::string("fcffffffffffffff54616462"), comphelper::hashToString(aPermsWithoutRandomBytes)); } + +CPPUNIT_TEST_FIXTURE(PDFEncryptionTest, testPadding) +{ + constexpr size_t constBlockSize = 16; + std::vector<sal_uInt8> aVector{ 'T', 'e', 's', 't', '!' }; + CPPUNIT_ASSERT_EQUAL(size_t(5), aVector.size()); + size_t nPaddedSize = vcl::pdf::addPaddingToVector(aVector, constBlockSize); + CPPUNIT_ASSERT_EQUAL(size_t(constBlockSize), aVector.size()); + CPPUNIT_ASSERT_EQUAL(size_t(constBlockSize), nPaddedSize); + for (size_t i = 6; i < constBlockSize; i++) + CPPUNIT_ASSERT_EQUAL(sal_uInt8(0x0B), aVector[i]); +} + } // end anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/vcl/source/pdf/PDFEncryptorR6.cxx b/vcl/source/pdf/PDFEncryptorR6.cxx index b3850a5929f8..b3e6f9e3059e 100644 --- a/vcl/source/pdf/PDFEncryptorR6.cxx +++ b/vcl/source/pdf/PDFEncryptorR6.cxx @@ -238,6 +238,17 @@ std::vector<sal_uInt8> computeHashR6(const sal_uInt8* pPassword, size_t nPasswor return std::vector<sal_uInt8>(K.begin(), K.begin() + 32); } +size_t addPaddingToVector(std::vector<sal_uInt8>& rVector, size_t nBlockSize) +{ + size_t nPaddedSize = comphelper::roundUp(rVector.size(), size_t(nBlockSize)); + if (nPaddedSize > rVector.size()) + { + sal_uInt8 nPaddedValue = sal_uInt8(nPaddedSize - rVector.size()); + rVector.resize(nPaddedSize, nPaddedValue); + } + return nPaddedSize; +} + } // end vcl::pdf /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |