include/vcl/pdfwriter.hxx | 16 ++++++++++++++++ vcl/source/pdf/PDFEncryptor.cxx | 25 +++++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-)
New commits: commit 28e613e050b617a322ddca4a77ff599ec8e94aef Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Nov 20 22:41:28 2024 +0900 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Dec 6 13:26:40 2024 +0100 pdf: move creating access permissions to common place The access permission are needed independent to the kind of PDF encryption so they should be in a common place so they can be reused. PDFEncryptionProperties is the best place to create the value anyway. Change-Id: Ic6e6c3d9a8cb314523c0305eba9e64f3734d52b5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176884 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx index e982761fdc04..6b91ead8bd89 100644 --- a/include/vcl/pdfwriter.hxx +++ b/include/vcl/pdfwriter.hxx @@ -111,6 +111,22 @@ struct PDFEncryptionProperties UValue.clear(); EncryptionKey.clear(); } + + sal_Int32 getAccessPermissions() const + { + sal_Int32 nAccessPermissions = 0xfffff0c0; + + nAccessPermissions |= CanPrintTheDocument ? 1 << 2 : 0; + nAccessPermissions |= CanModifyTheContent ? 1 << 3 : 0; + nAccessPermissions |= CanCopyOrExtract ? 1 << 4 : 0; + nAccessPermissions |= CanAddOrModify ? 1 << 5 : 0; + nAccessPermissions |= CanFillInteractive ? 1 << 8 : 0; + nAccessPermissions |= CanExtractForAccessibility ? 1 << 9 : 0; + nAccessPermissions |= CanAssemble ? 1 << 10 : 0; + nAccessPermissions |= CanPrintFull ? 1 << 11 : 0; + + return nAccessPermissions; + } }; class VCL_DLLPUBLIC PDFWriter diff --git a/vcl/source/pdf/PDFEncryptor.cxx b/vcl/source/pdf/PDFEncryptor.cxx index a5425f014ae0..315a2c6e27cc 100644 --- a/vcl/source/pdf/PDFEncryptor.cxx +++ b/vcl/source/pdf/PDFEncryptor.cxx @@ -289,28 +289,13 @@ bool computeUDictionaryValue(EncryptionHashTransporter* i_pTransporter, sal_Int32 computeAccessPermissions(const vcl::PDFEncryptionProperties& i_rProperties, sal_Int32& o_rKeyLength, sal_Int32& o_rRC4KeyLength) { - /* - 2) compute the access permissions, in numerical form + o_rKeyLength = SECUR_128BIT_KEY; - the default value depends on the revision 2 (40 bit) or 3 (128 bit security): - - for 40 bit security the unused bit must be set to 1, since they are not used - - for 128 bit security the same bit must be preset to 0 and set later if needed - according to the table 3.15, pdf v 1.4 */ - sal_Int32 nAccessPermissions = 0xfffff0c0; + // for this value see PDF spec v 1.4, algorithm 3.1 step 4, where n is 16, + // thus maximum permitted value is 16 + o_rRC4KeyLength = 16; - o_rKeyLength = SECUR_128BIT_KEY; - o_rRC4KeyLength = 16; // for this value see PDF spec v 1.4, algorithm 3.1 step 4, where n is 16, - // thus maximum permitted value is 16 - - nAccessPermissions |= (i_rProperties.CanPrintTheDocument) ? 1 << 2 : 0; - nAccessPermissions |= (i_rProperties.CanModifyTheContent) ? 1 << 3 : 0; - nAccessPermissions |= (i_rProperties.CanCopyOrExtract) ? 1 << 4 : 0; - nAccessPermissions |= (i_rProperties.CanAddOrModify) ? 1 << 5 : 0; - nAccessPermissions |= (i_rProperties.CanFillInteractive) ? 1 << 8 : 0; - nAccessPermissions |= (i_rProperties.CanExtractForAccessibility) ? 1 << 9 : 0; - nAccessPermissions |= (i_rProperties.CanAssemble) ? 1 << 10 : 0; - nAccessPermissions |= (i_rProperties.CanPrintFull) ? 1 << 11 : 0; - return nAccessPermissions; + return i_rProperties.getAccessPermissions(); } } // end anonymous namespace