summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-11-20 22:41:28 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-12-21 14:10:26 +0100
commit7ea66a327fd8d66350dbb931325104ad19097ec1 (patch)
tree3028721fb6da5b732022f8f8cf2a88cd89b64c0d
parent186e997c559c7e5d4b9462f9b4be6a935cdd04cd (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178758 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--include/vcl/pdfwriter.hxx16
-rw-r--r--vcl/source/pdf/PDFEncryptor.cxx25
2 files changed, 21 insertions, 20 deletions
diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx
index 14c6265f3d88..9c6432203817 100644
--- a/include/vcl/pdfwriter.hxx
+++ b/include/vcl/pdfwriter.hxx
@@ -110,6 +110,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 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