SVN_SILENT made messages (.desktop file)
[kdegraphics.git] / okular / generators / ooo / manifest.h
blobd75d28e4ed9563a53febb99262082384ed748784
1 /***************************************************************************
2 * Copyright (C) 2007 by Brad Hards <bradh@frogmouth.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #ifndef OOO_MANIFEST_H
11 #define OOO_MANIFEST_H
13 #include <QtCore/QByteArray>
14 #include <QtCore/QMap>
15 #include <QtCore/QString>
17 #ifdef QCA2
18 #include <QtCrypto>
19 #endif
21 namespace OOO {
23 /**
24 OOO document manifest entry
26 This class holds the manifest information for a single file-entry element.
27 An example of the XML that could be passed in is shown below, although
28 not all manifest entries will have encryption-data.
29 \code
30 <manifest:file-entry manifest:media-type="image/jpeg" manifest:full-path="Pictures/100000000000032000000258912EB1C3.jpg" manifest:size="66704">
31 <manifest:encryption-data>
32 <manifest:algorithm manifest:algorithm-name="Blowfish CFB" manifest:initialisation-vector="T+miu403484="/>
33 <manifest:key-derivation manifest:key-derivation-name="PBKDF2" manifest:iteration-count="1024" manifest:salt="aNYdmqv4cObAJSJjm4RzqA=="/>
34 </manifest:encryption-data>
35 </manifest:file-entry>
36 \endcode
38 class ManifestEntry
40 public:
41 /**
42 Create a new manifest entry
44 ManifestEntry( const QString &fileName );
46 /**
47 Set the mimetype of the file.
49 void setMimeType( const QString &mimeType );
51 /**
52 Get the file name
54 QString fileName() const;
56 /**
57 Set the file size.
59 This is only required for files with encryption
61 void setSize( const QString &size );
63 /**
64 Get the mime type
66 QString mimeType() const;
68 /**
69 Get the file size
71 This is only meaningful for files with encryption
73 QString size() const;
75 /**
76 Set the checksum type.
78 This is only required for files with encryption
80 void setChecksumType( const QString &checksumType );
82 /**
83 Set the checksum.
85 \param checksum the checksum in base64 encoding.
87 This is only required for files with encryption
89 void setChecksum( const QString &checksum );
91 /**
92 Get the checksum type
94 This is only meaningful for files with encryption
96 QString checksumType() const;
98 /**
99 Get the checksum
101 This is only meaningful for files with encryption
103 QByteArray checksum() const;
106 Set the algorithm name
108 This is only required for files with encryption
110 void setAlgorithm( const QString &algorithm );
113 Get the algorithm name
115 This is only meaningful for files with encryption
117 QString algorithm() const;
120 Set the initialisation vector for the cipher algorithm
122 \param initialisationVector the IV in base64 encoding.
124 This is only required for files with encryption
126 void setInitialisationVector( const QString &initialisationVector );
129 Get the initialisation vector for the cipher algorithm
131 This is only meaningful for files with encryption
133 QByteArray initialisationVector() const;
136 Set the name of the key derivation function
138 This is only required for files with encryption
140 void setKeyDerivationName( const QString &keyDerivationName );
143 Get the name of the key derivation function
145 This is only meaningful for files with encryption
147 QString keyDerivationName() const;
150 Set the iteration count for the key derivation function
152 This is only required for files with encryption
154 void setIterationCount( const QString &iterationCount );
157 Get the iteration count for the key derivation function
159 This is only meaningful for files with encryption
161 int iterationCount() const;
164 Set the salt for the key derivation function
166 \param salt the salt in base64 encoding.
168 This is only required for files with encryption
170 void setSalt( const QString &salt );
173 Get the salt for the key derivation function
175 This is only meaningful for files with encryption
177 QByteArray salt() const;
179 private:
180 const QString m_fileName;
181 QString m_mimeType;
182 QString m_size;
183 QString m_checksumType;
184 QByteArray m_checksum;
185 QString m_algorithm;
186 QByteArray m_initialisationVector;
187 QString m_keyDerivationName;
188 int m_iterationCount;
189 QByteArray m_salt;
194 OOO document manifest
196 The document manifest is described in the OASIS Open Office Specification
197 (Version 1.1) section 17.7. This class represents the same data.
199 class Manifest
201 public:
203 Create a new manifest.
205 \param odfFileName the name of the parent ODF file
206 \param manifestData the data from the manifest file, as a byte array
207 of the XML format data.
209 Manifest( const QString &odfFileName, const QByteArray &manifestData );
211 ~Manifest();
214 Check if the manifest indicates that a file is encrypted
216 bool testIfEncrypted( const QString &filename );
219 Decrypt data associated with a specific file
221 QByteArray decryptFile( const QString &filename, const QByteArray &fileData );
223 private:
225 Retrieve the manifest data for a particular file
227 ManifestEntry* entryByName( const QString &filename );
230 Try to get the password for this file from the wallet
232 void getPasswordFromWallet();
235 Save the password for this file to the wallet
237 void savePasswordToWallet();
240 Verify whether the password we have is the right one.
242 This verifies the provided checksum
244 void checkPassword( ManifestEntry *entry, const QByteArray &fileData, QByteArray *decryptedData );
247 Ask the user for a password
249 void getPasswordFromUser();
251 #ifdef QCA2
252 QCA::Initializer m_init;
253 #endif
254 const QString m_odfFileName;
255 QMap<QString, ManifestEntry*> mEntries;
256 bool m_haveGoodPassword;
257 bool m_userCancelled;
258 QString m_password;
263 #endif