2
* xmlenc.h - XML Encryption
3
* Copyright (C) 2003 Justin Karneges
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#include<qstringlist.h>
28
#include<qvaluelist.h>
29
#include"../util/cipher.h"
33
enum Method { None, TripleDES, AES_128, AES_256, RSA_1_5, RSA_OAEP };
34
enum DataType { Arbitrary, Element, Content };
44
QByteArray value () const;
45
QStringList retrievalMethods() const;
46
QDomElement encryptedKey() const;
47
void setName(const QString &);
48
void setValue(const QByteArray &);
49
void setRetrievalMethods(const QStringList &);
50
void attachEncryptedKey(const QDomElement &);
52
QDomElement toXml(QDomDocument *) const;
53
bool fromXml(const QDomElement &);
58
QStringList v_rmethods;
67
QString uri() const { return v_uri; }
68
QDomElement transforms() const { return v_trans; }
69
void setURI(const QString &s) { v_uri = s; }
70
void setTransforms(const QDomElement &e) { v_trans = e; }
76
typedef QValueList<Reference> ReferenceList;
78
class EncryptionProperty
81
EncryptionProperty(const QString &target="", const QString &id="");
83
QString target() const;
85
QString property(const QString &var) const;
86
void setTarget(const QString &);
87
void setId(const QString &);
88
void setProperty(const QString &var, const QString &val);
90
QDomElement toXml(QDomDocument *) const;
91
bool fromXml(QDomElement &);
94
QString v_target, v_id;
95
QStringList vars, vals;
98
class EncryptionProperties : public QValueList<EncryptionProperty>
101
EncryptionProperties(const QString &s="");
104
void setId(const QString &);
106
QDomElement toXml(QDomDocument *) const;
107
bool fromXml(QDomElement &);
116
enum Type { Key, Data };
122
Method method() const { return v_method; }
123
QString id() const { return v_id; }
124
DataType dataType() const { return v_dataType; }
125
Type type() const { return v_type; }
126
QString mimeType() const { return v_mimeType; }
127
const KeyInfo & keyInfo() const { return v_keyInfo; }
128
bool isReference() const { return (!v_cref.uri().isEmpty()); }
129
const Reference & dataReference() const { return v_cref; }
130
QString carriedKeyName() const { return v_carrykeyname; }
131
const ReferenceList & referenceList() const { return v_reflist; }
132
const EncryptionProperties & encryptionProperties() const { return v_props; }
134
void setId(const QString &id) { v_id = id; }
135
void setDataType(DataType t) { v_dataType = t; }
136
void setType(Type t) { v_type = t; }
137
void setMimeType(const QString &mime) { v_mimeType = mime; }
138
void setKeyInfo(const KeyInfo &info) { v_keyInfo = info; }
139
void setDataReference(const Reference &cref, Method m);
140
void setCarriedKeyName(const QString &s) { v_carrykeyname = s; }
141
void setReferenceList(const ReferenceList &rl) { v_reflist = rl; }
142
void setEncryptionProperties(const EncryptionProperties &p) { v_props = p; }
144
bool encryptData(const QByteArray &data, const Cipher::Key &key);
145
bool encryptElement(const QDomElement &data, const Cipher::Key &key);
146
bool encryptContent(const QDomElement &data, const Cipher::Key &key);
147
bool encryptKey(const Cipher::Key &data, const Cipher::Key &key);
148
bool encryptKey(const Cipher::Key &data, const RSAKey &key);
150
QByteArray decryptData(const Cipher::Key &key) const;
151
QDomElement decryptElement(QDomDocument *, const Cipher::Key &key) const;
152
QDomNodeList decryptContent(QDomDocument *, const Cipher::Key &key) const;
153
QByteArray decryptKey(const Cipher::Key &key) const;
154
QByteArray decryptKey(const RSAKey &key) const;
156
QDomElement toXml(QDomDocument *) const;
157
bool fromXml(const QDomElement &);
169
QString v_carrykeyname;
170
ReferenceList v_reflist;
171
EncryptionProperties v_props;
174
Method cipherTypeToMethod(Cipher::Type) const;
175
QString methodToAlgorithm(Method, Type) const;
176
Method algorithmToMethod(const QString &) const;