Loading...
Searching...
No Matches
SecurityHandler.h
Go to the documentation of this file.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5#ifndef PDFTRON_H_CPPSDFSecurityHandler
6#define PDFTRON_H_CPPSDFSecurityHandler
7
8#include <vector>
9#include <Common/UString.h>
10#include <Filters/Filter.h>
11
12 namespace pdftron {
13 namespace SDF {
14
15 class Obj;
16 class SDFDoc;
17
18
22 class SecurityHandler
23{
24 public:
25
26 enum Permission
27 {
28 e_owner = 1,
29 e_doc_open,
30 e_doc_modify,
31 e_print,
32 e_print_high,
33 e_extract_content,
34 e_mod_annot,
35 e_fill_forms,
36 e_access_support,
37 e_assemble_doc
38 };
39
51 bool GetPermission(Permission p);
52
57 int GetKeyLength() const;
58
65 int GetEncryptionAlgorithmID() const;
66
71 const char* GetHandlerDocName() const;
72
80 bool IsModified () const;
81
86 bool IsValid () const;
87
88
95 void SetModified (bool is_modified = true);
96
97
101 enum AlgorithmType {
102 e_RC4_40 = 1,
103 e_RC4_128,
104 e_AES,
105 e_AES_256
106 };
107
113 SecurityHandler (AlgorithmType crypt_type);
114
131 SecurityHandler (const char* name, int key_len, int enc_code);
132 SecurityHandler ();
133
134 SecurityHandler (const SecurityHandler& s);
135 SecurityHandler& operator= (const SecurityHandler&);
136 virtual ~SecurityHandler ();
137
144 void ChangeUserPasswordASCII(const char* password);
145
152 void ChangeUserPassword(const char* password, size_t pwd_length );
153
158 void ChangeUserPassword(const pdftron::UString& password);
159
164 void ChangeUserPassword(const std::vector<pdftron::UInt8>& password_buf);
165
169 const char* GetUserPassword();
170
175 size_t GetUserPasswordSize() const;
176
183 void ChangeMasterPasswordASCII(const char* password);
184
191 void ChangeMasterPassword(const char* password, size_t pwd_length);
192
197 void ChangeMasterPassword(const pdftron::UString& password);
198
203 void ChangeMasterPassword(const std::vector<pdftron::UInt8>& password_buf);
204
208 const char* GetMasterPassword();
209
214 size_t GetMasterPasswordSize() const;
215
232 void SetPermission (Permission perm, bool value);
233
246 void ChangeRevisionNumber (int rev_num);
247
259 void SetEncryptMetadata(bool encrypt_metadata);
260
264 int GetRevisionNumber ();
265
269 bool IsUserPasswordRequired ();
270
274 bool IsMasterPasswordRequired ();
275
280 bool IsAES() const;
281
289 bool IsAES(Obj stream) const;
290
294 bool IsRC4() const;
295
299 operator bool () { return mp_handler!=0;}
300
306 virtual void AuthorizeFailed();
307
323 virtual bool Authorize (Permission p);
324
336 virtual bool GetAuthorizationData (Permission req_opr);
337
344 virtual bool EditSecurityData(SDFDoc& doc);
345
368 virtual Obj FillEncryptDict(class SDFDoc& doc);
369
374 virtual SecurityHandler* Clone(TRN_SecurityHandler base) const;
375
382 void InitPasswordASCII(const char* password);
383
390 void InitPassword(const char* password, size_t pwd_length);
391
396 void InitPassword(const pdftron::UString& password);
397
402 void InitPassword(const std::vector<pdftron::UInt8>& password_buf);
403
404
405 enum OverloadedFunction {
406 has_CloneProc = 0x01,
407 has_AuthProc = 0x02,
408 has_AuthFailedProc = 0x04,
409 has_GetAuthDataProc = 0x08,
410 has_EditSecurDataProc = 0x10,
411 has_FillEncDictProc = 0x20
412 };
413
422 void SetDerived(UInt32 overloaded_funct);
423
427 SecurityHandler* GetDerived() const;
428
429// @cond PRIVATE_DOC
430#ifndef SWIGHIDDEN
431 SecurityHandler(TRN_SecurityHandler impl, bool owner, UInt32 derived_procs);
432 TRN_SecurityHandler mp_handler;
433 bool m_owner;
434 UInt32 m_derived_procs;
435#endif
436// @endcond
437};
438
439
440 }; // namespace SDF
441}; // namespace pdftron
442
443#include <Impl/SDFDoc.inl>
444
445#endif // PDFTRON_H_CPPSDFSecurityHandler
Filter.h
UString.h
pdftron::SDF::Obj
Definition Obj.h:41
pdftron::SDF::SDFDoc
Definition SDFDoc.h:68
pdftron::SDF::SecurityHandler::AlgorithmType
AlgorithmType
Definition SecurityHandler.h:101
pdftron::SDF::SecurityHandler::e_RC4_128
@ e_RC4_128
128-bit RC4 algorithm.
Definition SecurityHandler.h:103
pdftron::SDF::SecurityHandler::e_AES
@ e_AES
Use Crypt filters with 128-bit AES (Advanced Encryption Standard) algorithm.
Definition SecurityHandler.h:104
pdftron::SDF::SecurityHandler::e_AES_256
@ e_AES_256
Use Crypt filters with 256-bit AES (Advanced Encryption Standard) algorithm.
Definition SecurityHandler.h:105
pdftron::SDF::SecurityHandler::e_RC4_40
@ e_RC4_40
40-bit RC4 algorithm.
Definition SecurityHandler.h:102
pdftron::SDF::SecurityHandler::ChangeUserPassword
void ChangeUserPassword(const pdftron::UString &password)
pdftron::SDF::SecurityHandler::Permission
Permission
Definition SecurityHandler.h:27
pdftron::SDF::SecurityHandler::e_doc_modify
@ e_doc_modify
edit the document more than adding or modifying text notes.
Definition SecurityHandler.h:30
pdftron::SDF::SecurityHandler::e_access_support
@ e_access_support
content access for the visually impaired.
Definition SecurityHandler.h:36
pdftron::SDF::SecurityHandler::e_owner
@ e_owner
the user has 'owner' rights (e.g. rights to change the document's security settings).
Definition SecurityHandler.h:28
pdftron::SDF::SecurityHandler::e_print_high
@ e_print_high
high resolution print.
Definition SecurityHandler.h:32
pdftron::SDF::SecurityHandler::e_extract_content
@ e_extract_content
enable content extraction
Definition SecurityHandler.h:33
pdftron::SDF::SecurityHandler::e_mod_annot
@ e_mod_annot
allow modifications to annotations
Definition SecurityHandler.h:34
pdftron::SDF::SecurityHandler::e_assemble_doc
@ e_assemble_doc
allow document assembly
Definition SecurityHandler.h:37
pdftron::SDF::SecurityHandler::e_fill_forms
@ e_fill_forms
allow changes to fill in forms
Definition SecurityHandler.h:35
pdftron::SDF::SecurityHandler::e_doc_open
@ e_doc_open
open and decrypt the document.
Definition SecurityHandler.h:29
pdftron::SDF::SecurityHandler::e_print
@ e_print
print the document.
Definition SecurityHandler.h:31
pdftron::SDF::SecurityHandler::GetUserPassword
const char * GetUserPassword()
pdftron::SDF::SecurityHandler::ChangeUserPasswordASCII
void ChangeUserPasswordASCII(const char *password)
pdftron::SDF::SecurityHandler::SecurityHandler
SecurityHandler(const SecurityHandler &s)
pdftron::SDF::SecurityHandler::SecurityHandler
SecurityHandler(const char *name, int key_len, int enc_code)
pdftron::SDF::SecurityHandler::IsUserPasswordRequired
bool IsUserPasswordRequired()
pdftron::SDF::SecurityHandler::GetDerived
SecurityHandler * GetDerived() const
pdftron::SDF::SecurityHandler::ChangeRevisionNumber
void ChangeRevisionNumber(int rev_num)
pdftron::SDF::SecurityHandler::GetPermission
bool GetPermission(Permission p)
pdftron::SDF::SecurityHandler::IsModified
bool IsModified() const
pdftron::SDF::SecurityHandler::SetEncryptMetadata
void SetEncryptMetadata(bool encrypt_metadata)
pdftron::SDF::SecurityHandler::GetMasterPasswordSize
size_t GetMasterPasswordSize() const
pdftron::SDF::SecurityHandler::ChangeUserPassword
void ChangeUserPassword(const char *password, size_t pwd_length)
pdftron::SDF::SecurityHandler::InitPasswordASCII
void InitPasswordASCII(const char *password)
pdftron::SDF::SecurityHandler::IsRC4
bool IsRC4() const
pdftron::SDF::SecurityHandler::EditSecurityData
virtual bool EditSecurityData(SDFDoc &doc)
pdftron::SDF::SecurityHandler::SecurityHandler
SecurityHandler()
pdftron::SDF::SecurityHandler::GetKeyLength
int GetKeyLength() const
pdftron::SDF::SecurityHandler::ChangeUserPassword
void ChangeUserPassword(const std::vector< pdftron::UInt8 > &password_buf)
pdftron::SDF::SecurityHandler::AuthorizeFailed
virtual void AuthorizeFailed()
pdftron::SDF::SecurityHandler::Clone
virtual SecurityHandler * Clone(TRN_SecurityHandler base) const
pdftron::SDF::SecurityHandler::OverloadedFunction
OverloadedFunction
Definition SecurityHandler.h:405
pdftron::SDF::SecurityHandler::has_EditSecurDataProc
@ has_EditSecurDataProc
Definition SecurityHandler.h:410
pdftron::SDF::SecurityHandler::has_GetAuthDataProc
@ has_GetAuthDataProc
Definition SecurityHandler.h:409
pdftron::SDF::SecurityHandler::has_AuthProc
@ has_AuthProc
Definition SecurityHandler.h:407
pdftron::SDF::SecurityHandler::has_CloneProc
@ has_CloneProc
Definition SecurityHandler.h:406
pdftron::SDF::SecurityHandler::has_AuthFailedProc
@ has_AuthFailedProc
Definition SecurityHandler.h:408
pdftron::SDF::SecurityHandler::has_FillEncDictProc
@ has_FillEncDictProc
Definition SecurityHandler.h:411
pdftron::SDF::SecurityHandler::ChangeMasterPassword
void ChangeMasterPassword(const pdftron::UString &password)
pdftron::SDF::SecurityHandler::GetEncryptionAlgorithmID
int GetEncryptionAlgorithmID() const
pdftron::SDF::SecurityHandler::Authorize
virtual bool Authorize(Permission p)
pdftron::SDF::SecurityHandler::FillEncryptDict
virtual Obj FillEncryptDict(class SDFDoc &doc)
pdftron::SDF::SecurityHandler::IsMasterPasswordRequired
bool IsMasterPasswordRequired()
pdftron::SDF::SecurityHandler::IsValid
bool IsValid() const
pdftron::SDF::SecurityHandler::GetUserPasswordSize
size_t GetUserPasswordSize() const
pdftron::SDF::SecurityHandler::ChangeMasterPasswordASCII
void ChangeMasterPasswordASCII(const char *password)
pdftron::SDF::SecurityHandler::SetPermission
void SetPermission(Permission perm, bool value)
pdftron::SDF::SecurityHandler::GetMasterPassword
const char * GetMasterPassword()
pdftron::SDF::SecurityHandler::ChangeMasterPassword
void ChangeMasterPassword(const char *password, size_t pwd_length)
pdftron::SDF::SecurityHandler::~SecurityHandler
virtual ~SecurityHandler()
pdftron::SDF::SecurityHandler::SecurityHandler
SecurityHandler(AlgorithmType crypt_type)
pdftron::SDF::SecurityHandler::IsAES
bool IsAES() const
pdftron::SDF::SecurityHandler::GetAuthorizationData
virtual bool GetAuthorizationData(Permission req_opr)
pdftron::SDF::SecurityHandler::IsAES
bool IsAES(Obj stream) const
pdftron::SDF::SecurityHandler::InitPassword
void InitPassword(const std::vector< pdftron::UInt8 > &password_buf)
pdftron::SDF::SecurityHandler::ChangeMasterPassword
void ChangeMasterPassword(const std::vector< pdftron::UInt8 > &password_buf)
pdftron::SDF::SecurityHandler::GetRevisionNumber
int GetRevisionNumber()
pdftron::SDF::SecurityHandler::GetHandlerDocName
const char * GetHandlerDocName() const
pdftron::SDF::SecurityHandler::operator=
SecurityHandler & operator=(const SecurityHandler &)
pdftron::SDF::SecurityHandler::InitPassword
void InitPassword(const pdftron::UString &password)
pdftron::SDF::SecurityHandler::SetModified
void SetModified(bool is_modified=true)
pdftron::SDF::SecurityHandler::InitPassword
void InitPassword(const char *password, size_t pwd_length)
pdftron::SDF::SecurityHandler::SetDerived
void SetDerived(UInt32 overloaded_funct)
pdftron::UString
Definition UString.h:28
pdftron::SDF
Definition DictIterator.h:12
pdftron
Definition BasicTypes.h:10
pdftron::UInt32
TRN_UInt32 UInt32
Definition BasicTypes.h:13