forked from frankosterfeld/qtkeychain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
androidkeystore_p.h
371 lines (275 loc) · 7.5 KB
/
androidkeystore_p.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/******************************************************************************
* Copyright (C) 2016 Mathias Hasselmann <mathias.hasselmann@kdab.com> *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. For licensing and distribution *
* details, check the accompanying file 'COPYING'. *
*****************************************************************************/
#ifndef QTKEYCHAIN_ANDROIDKEYSTORE_P_H
#define QTKEYCHAIN_ANDROIDKEYSTORE_P_H
#include <QAndroidJniObject>
namespace QKeychain {
namespace javax {
namespace security {
namespace auth { namespace x500 { class X500Principal; } }
namespace cert { class Certificate; }
}
}
namespace java {
namespace lang {
class Object : protected QAndroidJniObject
{
public:
inline Object(jobject object) : QAndroidJniObject(object) {}
inline Object(const QAndroidJniObject &object) : QAndroidJniObject(object) {}
inline operator bool() const { return isValid(); }
using QAndroidJniObject::object;
using QAndroidJniObject::toString;
protected:
static bool handleExceptions();
template<typename T>
static T handleExceptions(const T &result, const T &resultOnError = T());
};
template<typename T>
inline T Object::handleExceptions(const T &result, const T &resultOnError)
{
if (!handleExceptions())
return resultOnError;
return result;
}
} // namespace lang
namespace io {
class InputStream : public java::lang::Object
{
public:
using Object::Object;
int read() const;
};
class ByteArrayInputStream : public InputStream
{
public:
using InputStream::InputStream;
explicit ByteArrayInputStream(const QByteArray &bytes);
};
class FilterInputStream : public InputStream
{
public:
using InputStream::InputStream;
};
class OutputStream : public java::lang::Object
{
public:
using Object::Object;
bool write(const QByteArray &bytes) const;
bool flush() const;
bool close() const;
};
class ByteArrayOutputStream : public OutputStream
{
public:
using OutputStream::OutputStream;
ByteArrayOutputStream();
QByteArray toByteArray() const;
};
class FilterOutputStream : public OutputStream
{
public:
using OutputStream::OutputStream;
};
} // namespace io
namespace math {
class BigInteger : public java::lang::Object
{
public:
using Object::Object;
static const BigInteger ZERO;
static const BigInteger ONE;
static const BigInteger TEN;
};
} // namespace math
namespace util {
class Date : public java::lang::Object
{
public:
using Object::Object;
};
class Calendar : public java::lang::Object
{
public:
using Object::Object;
static const int YEAR;
static const int MONTH;
static const int DAY;
static const int HOUR;
static const int MINUTE;
static const int SECOND;
static const int MILLISECOND;
static Calendar getInstance();
bool add(int field, int amount) const;
Date getTime() const;
};
} // namespace util
namespace security {
namespace spec {
class AlgorithmParameterSpec : public java::lang::Object
{
public:
using Object::Object;
};
} // namespace spec
class Key : public java::lang::Object
{
public:
using Object::Object;
};
class PrivateKey : public Key
{
public:
using Key::Key;
PrivateKey(const Key &init): Key(init) {}
};
class PublicKey : public Key
{
public:
using Key::Key;
PublicKey(const Key &init): Key(init) {}
};
class KeyPair : public java::lang::Object
{
public:
using Object::Object;
};
class KeyPairGenerator : public java::lang::Object
{
public:
using Object::Object;
static KeyPairGenerator getInstance(const QString &algorithm, const QString &provider);
KeyPair generateKeyPair() const;
bool initialize(const spec::AlgorithmParameterSpec &spec) const;
};
class KeyStore : public java::lang::Object
{
public:
class Entry : public java::lang::Object
{
public:
using Object::Object;
};
class PrivateKeyEntry : public Entry
{
public:
using Entry::Entry;
inline PrivateKeyEntry(const Entry &init): Entry(init) {}
javax::security::cert::Certificate getCertificate() const;
java::security::PrivateKey getPrivateKey() const;
};
class LoadStoreParameter : public java::lang::Object
{
public:
using Object::Object;
};
class ProtectionParameter : public java::lang::Object
{
public:
using Object::Object;
};
using Object::Object;
bool containsAlias(const QString &alias) const;
bool deleteEntry(const QString &alias) const;
static KeyStore getInstance(const QString &type);
Entry getEntry(const QString &alias, const ProtectionParameter ¶m = Q_NULLPTR) const;
bool load(const LoadStoreParameter ¶m = Q_NULLPTR) const;
};
namespace interfaces {
class RSAPrivateKey : public PrivateKey
{
public:
using PrivateKey::PrivateKey;
RSAPrivateKey(const PrivateKey &init): PrivateKey(init) {}
};
class RSAPublicKey : public PublicKey
{
public:
using PublicKey::PublicKey;
RSAPublicKey(const PublicKey &init): PublicKey(init) {}
};
} // namespace interfaces
} // namespace security
} // namespace java
namespace android {
namespace content {
class Context : public java::lang::Object
{
public:
using Object::Object;
};
} // namespace content
namespace security {
class KeyPairGeneratorSpec : public java::security::spec::AlgorithmParameterSpec
{
public:
class Builder : public java::lang::Object
{
public:
using Object::Object;
explicit Builder(const android::content::Context &context);
Builder setAlias(const QString &alias) const;
Builder setSubject(const javax::security::auth::x500::X500Principal &subject) const;
Builder setSerialNumber(const java::math::BigInteger &serial) const;
Builder setStartDate(const java::util::Date &date) const;
Builder setEndDate(const java::util::Date &date) const;
KeyPairGeneratorSpec build() const;
};
using AlgorithmParameterSpec::AlgorithmParameterSpec;
};
} // namespace security
} // namespace android
namespace javax {
namespace crypto {
class Cipher : public java::lang::Object
{
public:
static const int DECRYPT_MODE;
static const int ENCRYPT_MODE;
using Object::Object;
static Cipher getInstance(const QString &transformation);
bool init(int opMode, const java::security::Key &key) const;
};
class CipherInputStream : public java::io::FilterInputStream
{
public:
using FilterInputStream::FilterInputStream;
explicit CipherInputStream(const InputStream &stream, const Cipher &cipher);
};
class CipherOutputStream : public java::io::FilterOutputStream
{
public:
using FilterOutputStream::FilterOutputStream;
explicit CipherOutputStream(const OutputStream &stream, const Cipher &cipher);
};
}
namespace security {
namespace auth {
namespace x500 {
class X500Principal;
class X500Principal : public java::lang::Object
{
public:
using Object::Object;
explicit X500Principal(const QString &name);
};
} // namespace x500
} // namespace auth
namespace cert {
class Certificate : public java::lang::Object
{
public:
using Object::Object;
java::security::PublicKey getPublicKey() const;
};
} // namespace cert
} // namespace security
} // namespace javax
} // namespace QKeychain
#endif // QTKEYCHAIN_ANDROIDKEYSTORE_P_H