00001
00002
00003
00004
00005
00006 #ifndef H_CPPSDFSecurityHandler
00007 #define H_CPPSDFSecurityHandler
00008
00009
00010 #include <vector>
00011 #include <Filters/Filter.h>
00012
00013
00014 namespace pdftron {
00015 namespace SDF {
00016
00017 class Obj;
00018 class SDFDoc;
00019
00020
00024 class SecurityHandler
00025 {
00026 public:
00027
00028 enum Permission
00029 {
00030 e_owner = 1,
00031 e_doc_open,
00032 e_doc_modify,
00033 e_print,
00034 e_print_high,
00035 e_extract_content,
00036 e_mod_annot,
00037 e_fill_forms,
00038 e_access_support,
00039 e_assemble_doc
00040 };
00041
00053 bool GetPermission(Permission p);
00054
00059 int GetKeyLength() const;
00060
00067 int GetEncryptionAlgorithmID() const;
00068
00073 const char* GetHandlerDocName() const;
00074
00082 bool IsModified () const;
00083
00089 void SetModified (bool is_modified = true);
00090
00091
00095 enum AlgorithmType {
00096 e_RC4_40 = 1,
00097 e_RC4_128,
00098 e_AES
00099 };
00100
00106 SecurityHandler (AlgorithmType crypt_type);
00107
00123 SecurityHandler (const char* name, int key_len, int enc_code);
00124 SecurityHandler ();
00125
00126 SecurityHandler (const SecurityHandler& s);
00127 SecurityHandler& operator= (const SecurityHandler&);
00128 virtual ~SecurityHandler ();
00129
00134 void ChangeUserPassword(const char* password);
00135
00139 const char* GetUserPassword();
00140
00145 void ChangeMasterPassword(const char* password);
00146
00150 const char* GetMasterPassword();
00151
00168 void SetPermission (Permission perm, bool value);
00169
00182 void ChangeRevisionNumber (int rev_num);
00183
00195 void SetEncryptMetadata(bool encrypt_metadata);
00196
00200 int GetRevisionNumber ();
00201
00205 bool IsUserPasswordRequired ();
00206
00210 bool IsMasterPasswordRequired ();
00211
00216 bool IsAES() const;
00217
00225 bool IsAES(Obj stream) const;
00226
00230 bool IsRC4() const;
00231
00235 operator bool () { return mp_handler!=0;}
00236
00242 virtual void AuthorizeFailed();
00243
00259 virtual bool Authorize (Permission p);
00260
00272 virtual bool GetAuthorizationData (Permission req_opr);
00273
00280 virtual bool EditSecurityData(SDFDoc& doc);
00281
00304 virtual Obj FillEncryptDict(class SDFDoc& doc);
00305
00310 virtual SecurityHandler* Clone(TRN_SecurityHandler base) const;
00311
00316 void InitPassword(const char* password);
00317
00318
00319 enum {
00320 has_CloneProc = 0x01,
00321 has_AuthProc = 0x02,
00322 has_AuthFailedProc = 0x04,
00323 has_GetAuthDataProc = 0x08,
00324 has_EditSecurDataProc = 0x10,
00325 has_FillEncDictProc = 0x20
00326 };
00327
00336 void SetDerived(UInt32 overloaded_funct);
00337
00341 SecurityHandler* GetDerived() const;
00342
00344 SecurityHandler(TRN_SecurityHandler impl, bool owner, UInt32 derived_procs);
00345 TRN_SecurityHandler mp_handler;
00346 bool m_owner;
00347 UInt32 m_derived_procs;
00349 };
00350
00351
00352 };
00353 };
00354
00355 #include <Impl/SDFDoc.inl>
00356 #endif
00357