~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to cutestuff/xmlsec/xmlenc.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * xmlenc.h - XML Encryption
3
 
 * Copyright (C) 2003  Justin Karneges
4
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 *
19
 
 */
20
 
 
21
 
#ifndef CS_XMLENC_H
22
 
#define CS_XMLENC_H
23
 
 
24
 
#include<qstring.h>
25
 
#include<qcstring.h>
26
 
#include<qstringlist.h>
27
 
#include<qdom.h>
28
 
#include<qvaluelist.h>
29
 
#include"../util/cipher.h"
30
 
 
31
 
namespace XmlEnc
32
 
{
33
 
        enum Method { None, TripleDES, AES_128, AES_256, RSA_1_5, RSA_OAEP };
34
 
        enum DataType { Arbitrary, Element, Content };
35
 
 
36
 
        class KeyInfo
37
 
        {
38
 
        public:
39
 
                KeyInfo();
40
 
                ~KeyInfo();
41
 
 
42
 
                bool isEmpty() const;
43
 
                QString name() const;
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 &);
51
 
 
52
 
                QDomElement toXml(QDomDocument *) const;
53
 
                bool fromXml(const QDomElement &);
54
 
 
55
 
        private:
56
 
                QString v_name;
57
 
                QByteArray v_value;
58
 
                QStringList v_rmethods;
59
 
                QDomElement v_key;
60
 
        };
61
 
 
62
 
        class Reference
63
 
        {
64
 
        public:
65
 
                Reference() {}
66
 
 
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; }
71
 
 
72
 
        private:
73
 
                QString v_uri;
74
 
                QDomElement v_trans;
75
 
        };
76
 
        typedef QValueList<Reference> ReferenceList;
77
 
 
78
 
        class EncryptionProperty
79
 
        {
80
 
        public:
81
 
                EncryptionProperty(const QString &target="", const QString &id="");
82
 
 
83
 
                QString target() const;
84
 
                QString id() 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);
89
 
 
90
 
                QDomElement toXml(QDomDocument *) const;
91
 
                bool fromXml(QDomElement &);
92
 
 
93
 
        private:
94
 
                QString v_target, v_id;
95
 
                QStringList vars, vals;
96
 
        };
97
 
 
98
 
        class EncryptionProperties : public QValueList<EncryptionProperty>
99
 
        {
100
 
        public:
101
 
                EncryptionProperties(const QString &s="");
102
 
 
103
 
                QString id() const;
104
 
                void setId(const QString &);
105
 
 
106
 
                QDomElement toXml(QDomDocument *) const;
107
 
                bool fromXml(QDomElement &);
108
 
 
109
 
        private:
110
 
                QString v_id;
111
 
        };
112
 
 
113
 
        class Encrypted
114
 
        {
115
 
        public:
116
 
                enum Type { Key, Data };
117
 
                Encrypted();
118
 
                ~Encrypted();
119
 
 
120
 
                void clear();
121
 
 
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; }
133
 
 
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; }
143
 
 
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);
149
 
 
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;
155
 
 
156
 
                QDomElement toXml(QDomDocument *) const;
157
 
                bool fromXml(const QDomElement &);
158
 
 
159
 
        private:
160
 
                Method v_method;
161
 
                QString v_id;
162
 
                DataType v_dataType;
163
 
                Type v_type;
164
 
                QString v_mimeType;
165
 
                KeyInfo v_keyInfo;
166
 
 
167
 
                QString v_cval;
168
 
                Reference v_cref;
169
 
                QString v_carrykeyname;
170
 
                ReferenceList v_reflist;
171
 
                EncryptionProperties v_props;
172
 
 
173
 
                QString baseNS;
174
 
                Method cipherTypeToMethod(Cipher::Type) const;
175
 
                QString methodToAlgorithm(Method, Type) const;
176
 
                Method algorithmToMethod(const QString &) const;
177
 
        };
178
 
};
179
 
 
180
 
#endif