52afb2f6036d118c75151e21fc17404f687ff7ab
[swftools.git] / pdf2swf / xpdf / Decrypt.h
1 //========================================================================
2 //
3 // Decrypt.h
4 //
5 // Copyright 1996-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef DECRYPT_H
10 #define DECRYPT_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include "gtypes.h"
17 #include "GString.h"
18
19 //------------------------------------------------------------------------
20 // Decrypt
21 //------------------------------------------------------------------------
22
23 class Decrypt {
24 public:
25
26   // Initialize the decryptor object.
27   Decrypt(Guchar *fileKey, int keyLength, int objNum, int objGen);
28
29   // Reset decryption.
30   void reset();
31
32   // Decrypt one byte.
33   Guchar decryptByte(Guchar c);
34
35   // Generate a file key.  The <fileKey> buffer must have space for at
36   // least 16 bytes.  Checks <ownerPassword> and then <userPassword>
37   // and returns true if either is correct.  Sets <ownerPasswordOk> if
38   // the owner password was correct.  Either or both of the passwords
39   // may be NULL, which is treated as an empty string.
40   static GBool makeFileKey(int encVersion, int encRevision, int keyLength,
41                            GString *ownerKey, GString *userKey,
42                            int permissions, GString *fileID,
43                            GString *ownerPassword, GString *userPassword,
44                            Guchar *fileKey, GBool *ownerPasswordOk);
45
46 private:
47
48   static GBool makeFileKey2(int encVersion, int encRevision, int keyLength,
49                             GString *ownerKey, GString *userKey,
50                             int permissions, GString *fileID,
51                             GString *userPassword, Guchar *fileKey);
52
53   int objKeyLength;
54   Guchar objKey[21];
55   Guchar state[256];
56   Guchar x, y;
57 };
58
59 #endif