|
1 /** |
|
2 * XML Security Library (http://www.aleksey.com/xmlsec). |
|
3 * |
|
4 * Key data. |
|
5 * |
|
6 * This is free software; see Copyright file in the source |
|
7 * distribution for preciese wording. |
|
8 * |
|
9 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> |
|
10 * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
11 */ |
|
12 #ifndef __XMLSEC_KEYSDATA_H__ |
|
13 #define __XMLSEC_KEYSDATA_H__ |
|
14 |
|
15 #ifdef __cplusplus |
|
16 extern "C" { |
|
17 #endif /* __cplusplus */ |
|
18 |
|
19 #include <libxml2_tree.h> |
|
20 #include "xmlsec_config.h" |
|
21 #include "xmlsec_xmlsec.h" |
|
22 #include "xmlsec_buffer.h" |
|
23 #include "xmlsec_list.h" |
|
24 |
|
25 /** |
|
26 * Forward declarations |
|
27 */ |
|
28 typedef const struct _xmlSecKeyDataKlass xmlSecKeyDataKlass, |
|
29 *xmlSecKeyDataId; |
|
30 typedef const struct _xmlSecKeyDataStoreKlass xmlSecKeyDataStoreKlass, |
|
31 *xmlSecKeyDataStoreId; |
|
32 typedef struct _xmlSecKeyDataList xmlSecKeyDataList, |
|
33 *xmlSecKeyDataListPtr; |
|
34 |
|
35 |
|
36 /************************************************************************** |
|
37 * |
|
38 * xmlSecKeyDataUsage |
|
39 * |
|
40 *************************************************************************/ |
|
41 /** |
|
42 * xmlSecKeyDataUsage: |
|
43 * |
|
44 * The bits mask that determines possible keys data usage. |
|
45 */ |
|
46 typedef unsigned int xmlSecKeyDataUsage; |
|
47 |
|
48 /** |
|
49 * xmlSecKeyDataUsageUnknown: |
|
50 * |
|
51 * The key data usage is unknown. |
|
52 */ |
|
53 #define xmlSecKeyDataUsageUnknown 0x00000 |
|
54 |
|
55 /** |
|
56 * xmlSecKeyDataUsageKeyInfoNodeRead: |
|
57 * |
|
58 * The key data could be read from a <dsig:KeyInfo/> child. |
|
59 */ |
|
60 #define xmlSecKeyDataUsageKeyInfoNodeRead 0x00001 |
|
61 |
|
62 /** |
|
63 * xmlSecKeyDataUsageKeyInfoNodeWrite: |
|
64 * |
|
65 * The key data could be written to a <dsig:KeyInfo /> child. |
|
66 */ |
|
67 #define xmlSecKeyDataUsageKeyInfoNodeWrite 0x00002 |
|
68 |
|
69 /** |
|
70 * xmlSecKeyDataUsageKeyValueNodeRead: |
|
71 * |
|
72 * The key data could be read from a <dsig:KeyValue /> child. |
|
73 */ |
|
74 #define xmlSecKeyDataUsageKeyValueNodeRead 0x00004 |
|
75 |
|
76 /** |
|
77 * xmlSecKeyDataUsageKeyValueNodeWrite: |
|
78 * |
|
79 * The key data could be written to a <dsig:KeyValue /> child. |
|
80 */ |
|
81 #define xmlSecKeyDataUsageKeyValueNodeWrite 0x00008 |
|
82 |
|
83 /** |
|
84 * xmlSecKeyDataUsageRetrievalMethodNodeXml: |
|
85 * |
|
86 * The key data could be retrieved using <dsig:RetrievalMethod /> node |
|
87 * in XML format. |
|
88 */ |
|
89 #define xmlSecKeyDataUsageRetrievalMethodNodeXml 0x00010 |
|
90 |
|
91 /** |
|
92 * xmlSecKeyDataUsageRetrievalMethodNodeBin: |
|
93 * |
|
94 * The key data could be retrieved using <dsig:RetrievalMethod /> node |
|
95 * in binary format. |
|
96 */ |
|
97 #define xmlSecKeyDataUsageRetrievalMethodNodeBin 0x00020 |
|
98 |
|
99 /** |
|
100 * xmlSecKeyDataUsageAny: |
|
101 * |
|
102 * Any key data usage. |
|
103 */ |
|
104 #define xmlSecKeyDataUsageAny 0xFFFFF |
|
105 |
|
106 /** |
|
107 * xmlSecKeyDataUsageKeyInfoNode: |
|
108 * |
|
109 * The key data could be read and written from/to a <dsig:KeyInfo /> child. |
|
110 */ |
|
111 #define xmlSecKeyDataUsageKeyInfoNode \ |
|
112 (xmlSecKeyDataUsageKeyInfoNodeRead | xmlSecKeyDataUsageKeyInfoNodeWrite) |
|
113 |
|
114 /** |
|
115 * xmlSecKeyDataUsageKeyValueNode: |
|
116 * |
|
117 * The key data could be read and written from/to a <dsig:KeyValue /> child. |
|
118 */ |
|
119 #define xmlSecKeyDataUsageKeyValueNode \ |
|
120 (xmlSecKeyDataUsageKeyValueNodeRead | xmlSecKeyDataUsageKeyValueNodeWrite) |
|
121 |
|
122 /** |
|
123 * xmlSecKeyDataUsageRetrievalMethodNode: |
|
124 * |
|
125 * The key data could be retrieved using <dsig:RetrievalMethod /> node |
|
126 * in any format. |
|
127 */ |
|
128 #define xmlSecKeyDataUsageRetrievalMethodNode \ |
|
129 (xmlSecKeyDataUsageRetrievalMethodNodeXml | xmlSecKeyDataUsageRetrievalMethodNodeBin) |
|
130 |
|
131 /************************************************************************** |
|
132 * |
|
133 * xmlSecKeyDataType |
|
134 * |
|
135 *************************************************************************/ |
|
136 /** |
|
137 * xmlSecKeyDataType: |
|
138 * |
|
139 * The key data type (public/private, session/permanet, etc.). |
|
140 */ |
|
141 typedef unsigned int xmlSecKeyDataType; |
|
142 |
|
143 /** |
|
144 * xmlSecKeyDataTypeUnknown: |
|
145 * |
|
146 * The key data type is unknown (same as #xmlSecKeyDataTypeNone). |
|
147 */ |
|
148 #define xmlSecKeyDataTypeUnknown 0x0000 |
|
149 |
|
150 /** |
|
151 * xmlSecKeyDataTypeNone: |
|
152 * |
|
153 * The key data type is unknown (same as #xmlSecKeyDataTypeUnknown). |
|
154 */ |
|
155 #define xmlSecKeyDataTypeNone xmlSecKeyDataTypeUnknown |
|
156 |
|
157 /** |
|
158 * xmlSecKeyDataTypePublic: |
|
159 * |
|
160 * The key data contain a public key. |
|
161 */ |
|
162 #define xmlSecKeyDataTypePublic 0x0001 |
|
163 |
|
164 /** |
|
165 * xmlSecKeyDataTypePrivate: |
|
166 * |
|
167 * The key data contain a private key. |
|
168 */ |
|
169 #define xmlSecKeyDataTypePrivate 0x0002 |
|
170 |
|
171 /** |
|
172 * xmlSecKeyDataTypeSymmetric: |
|
173 * |
|
174 * The key data contain a symmetric key. |
|
175 */ |
|
176 #define xmlSecKeyDataTypeSymmetric 0x0004 |
|
177 |
|
178 /** |
|
179 * xmlSecKeyDataTypeSession: |
|
180 * |
|
181 * The key data contain session key (one time key, not stored in keys manager). |
|
182 */ |
|
183 #define xmlSecKeyDataTypeSession 0x0008 |
|
184 |
|
185 /** |
|
186 * xmlSecKeyDataTypePermanent: |
|
187 * |
|
188 * The key data contain permanent key (stored in keys manager). |
|
189 */ |
|
190 #define xmlSecKeyDataTypePermanent 0x0010 |
|
191 |
|
192 /** |
|
193 * xmlSecKeyDataTypeTrusted: |
|
194 * |
|
195 * The key data is trusted. |
|
196 */ |
|
197 #define xmlSecKeyDataTypeTrusted 0x0100 |
|
198 |
|
199 /** |
|
200 * xmlSecKeyDataTypeAny: |
|
201 * |
|
202 * Any key data. |
|
203 */ |
|
204 #define xmlSecKeyDataTypeAny 0xFFFF |
|
205 |
|
206 /************************************************************************** |
|
207 * |
|
208 * xmlSecKeyDataFormat |
|
209 * |
|
210 *************************************************************************/ |
|
211 /** |
|
212 * xmlSecKeyDataFormat: |
|
213 * @xmlSecKeyDataFormatUnknown: the key data format is unknown. |
|
214 * @xmlSecKeyDataFormatBinary: the binary key data. |
|
215 * @xmlSecKeyDataFormatPem: the PEM key data (cert or public/private key). |
|
216 * @xmlSecKeyDataFormatDer: the DER key data (cert or public/private key). |
|
217 * @xmlSecKeyDataFormatPkcs8Pem: the PKCS#8 PEM private key. |
|
218 * @xmlSecKeyDataFormatPkcs8Der: the PKCS#8 DER private key. |
|
219 * @xmlSecKeyDataFormatPkcs12: the PKCS12 format (bag of keys and certs) |
|
220 * @xmlSecKeyDataFormatCertPem: the PEM cert. |
|
221 * @xmlSecKeyDataFormatCertDer: the DER cert. |
|
222 * |
|
223 * The key data format (binary, der, pem, etc.). |
|
224 */ |
|
225 typedef enum { |
|
226 xmlSecKeyDataFormatUnknown = 0, |
|
227 xmlSecKeyDataFormatBinary, |
|
228 xmlSecKeyDataFormatPem, |
|
229 xmlSecKeyDataFormatDer, |
|
230 xmlSecKeyDataFormatPkcs8Pem, |
|
231 xmlSecKeyDataFormatPkcs8Der, |
|
232 xmlSecKeyDataFormatPkcs12, |
|
233 xmlSecKeyDataFormatCertPem, |
|
234 xmlSecKeyDataFormatCertDer |
|
235 } xmlSecKeyDataFormat; |
|
236 |
|
237 /************************************************************************** |
|
238 * |
|
239 * Global xmlSecKeyDataIds methods |
|
240 * |
|
241 *************************************************************************/ |
|
242 XMLSEC_EXPORT xmlSecPtrListPtr xmlSecKeyDataIdsGet (void); |
|
243 XMLSEC_EXPORT int xmlSecKeyDataIdsInit (void); |
|
244 XMLSEC_EXPORT void xmlSecKeyDataIdsShutdown (void); |
|
245 XMLSEC_EXPORT int xmlSecKeyDataIdsRegisterDefault (void); |
|
246 XMLSEC_EXPORT int xmlSecKeyDataIdsRegister (xmlSecKeyDataId id); |
|
247 |
|
248 /************************************************************************** |
|
249 * |
|
250 * xmlSecKeyData |
|
251 * |
|
252 *************************************************************************/ |
|
253 /** |
|
254 * xmlSecKeyData: |
|
255 * @id: the data id (#xmlSecKeyDataId). |
|
256 * @reserved0: reserved for the future. |
|
257 * @reserved1: reserved for the future. |
|
258 * |
|
259 * The key data: key value (crypto material), x509 data, pgp data, etc. |
|
260 */ |
|
261 struct _xmlSecKeyData { |
|
262 xmlSecKeyDataId id; |
|
263 void* reserved0; |
|
264 void* reserved1; |
|
265 }; |
|
266 |
|
267 XMLSEC_EXPORT xmlSecKeyDataPtr xmlSecKeyDataCreate (xmlSecKeyDataId id); |
|
268 XMLSEC_EXPORT xmlSecKeyDataPtr xmlSecKeyDataDuplicate (xmlSecKeyDataPtr data); |
|
269 XMLSEC_EXPORT void xmlSecKeyDataDestroy (xmlSecKeyDataPtr data); |
|
270 XMLSEC_EXPORT int xmlSecKeyDataGenerate (xmlSecKeyDataPtr data, |
|
271 xmlSecSize sizeBits, |
|
272 xmlSecKeyDataType type); |
|
273 XMLSEC_EXPORT xmlSecKeyDataType xmlSecKeyDataGetType (xmlSecKeyDataPtr data); |
|
274 XMLSEC_EXPORT xmlSecSize xmlSecKeyDataGetSize (xmlSecKeyDataPtr data); |
|
275 XMLSEC_EXPORT const xmlChar* xmlSecKeyDataGetIdentifier (xmlSecKeyDataPtr data); |
|
276 XMLSEC_EXPORT void xmlSecKeyDataDebugDump (xmlSecKeyDataPtr data, |
|
277 FILE *output); |
|
278 XMLSEC_EXPORT void xmlSecKeyDataDebugXmlDump (xmlSecKeyDataPtr data, |
|
279 FILE *output); |
|
280 XMLSEC_EXPORT int xmlSecKeyDataXmlRead (xmlSecKeyDataId id, |
|
281 xmlSecKeyPtr key, |
|
282 xmlNodePtr node, |
|
283 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
284 XMLSEC_EXPORT int xmlSecKeyDataXmlWrite (xmlSecKeyDataId id, |
|
285 xmlSecKeyPtr key, |
|
286 xmlNodePtr node, |
|
287 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
288 XMLSEC_EXPORT int xmlSecKeyDataBinRead (xmlSecKeyDataId id, |
|
289 xmlSecKeyPtr key, |
|
290 const xmlSecByte* buf, |
|
291 xmlSecSize bufSize, |
|
292 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
293 XMLSEC_EXPORT int xmlSecKeyDataBinWrite (xmlSecKeyDataId id, |
|
294 xmlSecKeyPtr key, |
|
295 xmlSecByte** buf, |
|
296 xmlSecSize* bufSize, |
|
297 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
298 |
|
299 |
|
300 /** |
|
301 * xmlSecKeyDataGetName: |
|
302 * @data: the pointer to key data. |
|
303 * |
|
304 * Macro. Returns the key data name. |
|
305 */ |
|
306 #define xmlSecKeyDataGetName(data) \ |
|
307 ((xmlSecKeyDataIsValid((data))) ? \ |
|
308 xmlSecKeyDataKlassGetName((data)->id) : NULL) |
|
309 |
|
310 /** |
|
311 * xmlSecKeyDataIsValid: |
|
312 * @data: the pointer to data. |
|
313 * |
|
314 * Macro. Returns 1 if @data is not NULL and @data->id is not NULL |
|
315 * or 0 otherwise. |
|
316 */ |
|
317 #define xmlSecKeyDataIsValid(data) \ |
|
318 ((( data ) != NULL) && \ |
|
319 (( data )->id != NULL) && \ |
|
320 (( data )->id->klassSize >= sizeof(xmlSecKeyDataKlass)) && \ |
|
321 (( data )->id->objSize >= sizeof(xmlSecKeyData)) && \ |
|
322 (( data )->id->name != NULL)) |
|
323 /** |
|
324 * xmlSecKeyDataCheckId: |
|
325 * @data: the pointer to data. |
|
326 * @dataId: the data Id. |
|
327 * |
|
328 * Macro. Returns 1 if @data is valid and @data's id is equal to @dataId. |
|
329 */ |
|
330 #define xmlSecKeyDataCheckId(data, dataId) \ |
|
331 (xmlSecKeyDataIsValid(( data )) && \ |
|
332 ((( data )->id) == ( dataId ))) |
|
333 |
|
334 /** |
|
335 * xmlSecKeyDataCheckUsage: |
|
336 * @data: the pointer to data. |
|
337 * @usg: the data usage. |
|
338 * |
|
339 * Macro. Returns 1 if @data is valid and could be used for @usg. |
|
340 */ |
|
341 #define xmlSecKeyDataCheckUsage(data, usg) \ |
|
342 (xmlSecKeyDataIsValid(( data )) && \ |
|
343 (((( data )->id->usage) & ( usg )) != 0)) |
|
344 |
|
345 /** |
|
346 * xmlSecKeyDataCheckSize: |
|
347 * @data: the pointer to data. |
|
348 * @size: the expected size. |
|
349 * |
|
350 * Macro. Returns 1 if @data is valid and @data's object has at least @size bytes. |
|
351 */ |
|
352 #define xmlSecKeyDataCheckSize(data, size) \ |
|
353 (xmlSecKeyDataIsValid(( data )) && \ |
|
354 (( data )->id->objSize >= size)) |
|
355 |
|
356 /************************************************************************** |
|
357 * |
|
358 * xmlSecKeyDataKlass |
|
359 * |
|
360 *************************************************************************/ |
|
361 /** |
|
362 * xmlSecKeyDataIdUnknown: |
|
363 * |
|
364 * The "unknown" id. |
|
365 */ |
|
366 #define xmlSecKeyDataIdUnknown ((xmlSecKeyDataId)NULL) |
|
367 |
|
368 /** |
|
369 * xmlSecKeyDataInitMethod: |
|
370 * @data: the pointer to key data. |
|
371 * |
|
372 * Key data specific initialization method. |
|
373 * |
|
374 * Returns 0 on success or a negative value if an error occurs. |
|
375 */ |
|
376 typedef int (*xmlSecKeyDataInitMethod) (xmlSecKeyDataPtr data); |
|
377 |
|
378 /** |
|
379 * xmlSecKeyDataDuplicateMethod: |
|
380 * @dst: the pointer to destination key data. |
|
381 * @src: the poiniter to source key data. |
|
382 * |
|
383 * Key data specific duplication (copy) method. |
|
384 * |
|
385 * Returns 0 on success or a negative value if an error occurs. |
|
386 */ |
|
387 typedef int (*xmlSecKeyDataDuplicateMethod) (xmlSecKeyDataPtr dst, |
|
388 xmlSecKeyDataPtr src); |
|
389 |
|
390 /** |
|
391 * xmlSecKeyDataFinalizeMethod: |
|
392 * @data: the data. |
|
393 * |
|
394 * Key data specific finalization method. All the objects and resources allocated |
|
395 * by the key data object must be freed inside this method. |
|
396 */ |
|
397 typedef void (*xmlSecKeyDataFinalizeMethod) (xmlSecKeyDataPtr data); |
|
398 |
|
399 /** |
|
400 * xmlSecKeyDataXmlReadMethod: |
|
401 * @id: the data id. |
|
402 * @key: the key. |
|
403 * @node: the pointer to data's value XML node. |
|
404 * @keyInfoCtx: the <dsig:KeyInfo/> node processing context. |
|
405 * |
|
406 * Key data specific method for reading XML node. |
|
407 * |
|
408 * Returns 0 on success or a negative value if an error occurs. |
|
409 */ |
|
410 typedef int (*xmlSecKeyDataXmlReadMethod) (xmlSecKeyDataId id, |
|
411 xmlSecKeyPtr key, |
|
412 xmlNodePtr node, |
|
413 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
414 /** |
|
415 * xmlSecKeyDataXmlWriteMethod: |
|
416 * @id: the data id. |
|
417 * @key: the key. |
|
418 * @node: the pointer to data's value XML node. |
|
419 * @keyInfoCtx: the <dsig:KeyInfo> node processing context. |
|
420 * |
|
421 * Key data specific method for writing XML node. |
|
422 * |
|
423 * Returns 0 on success or a negative value if an error occurs. |
|
424 */ |
|
425 typedef int (*xmlSecKeyDataXmlWriteMethod) (xmlSecKeyDataId id, |
|
426 xmlSecKeyPtr key, |
|
427 xmlNodePtr node, |
|
428 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
429 /** |
|
430 * xmlSecKeyDataBinReadMethod: |
|
431 * @id: the data id. |
|
432 * @key: the key. |
|
433 * @buf: the input buffer. |
|
434 * @bufSize: the buffer size. |
|
435 * @keyInfoCtx: the <dsig:KeyInfo/> node processing context. |
|
436 * |
|
437 * Key data specific method for reading binary buffer. |
|
438 * |
|
439 * Returns 0 on success or a negative value if an error occurs. |
|
440 */ |
|
441 typedef int (*xmlSecKeyDataBinReadMethod) (xmlSecKeyDataId id, |
|
442 xmlSecKeyPtr key, |
|
443 const xmlSecByte* buf, |
|
444 xmlSecSize bufSize, |
|
445 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
446 /** |
|
447 * xmlSecKeyDataBinWriteMethod: |
|
448 * @id: the data id. |
|
449 * @key: the key. |
|
450 * @buf: the output buffer. |
|
451 * @bufSize: the buffer size. |
|
452 * @keyInfoCtx: the <dsig:KeyInfo/> node processing context. |
|
453 * |
|
454 * Key data specific method for reading binary buffer. |
|
455 * |
|
456 * Returns 0 on success or a negative value if an error occurs. |
|
457 */ |
|
458 typedef int (*xmlSecKeyDataBinWriteMethod) (xmlSecKeyDataId id, |
|
459 xmlSecKeyPtr key, |
|
460 xmlSecByte** buf, |
|
461 xmlSecSize* bufSize, |
|
462 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
463 |
|
464 /** |
|
465 * xmlSecKeyDataGenerateMethod: |
|
466 * @data: the pointer to key data. |
|
467 * @sizeBits: the key data specific size. |
|
468 * @type: the required key type (session/permanent, etc.) |
|
469 * |
|
470 * Key data specific method for generating new key data. |
|
471 * |
|
472 * Returns 0 on success or a negative value if an error occurs. |
|
473 */ |
|
474 typedef int (*xmlSecKeyDataGenerateMethod) (xmlSecKeyDataPtr data, |
|
475 xmlSecSize sizeBits, |
|
476 xmlSecKeyDataType type); |
|
477 |
|
478 /** |
|
479 * xmlSecKeyDataGetTypeMethod: |
|
480 * @data: the data. |
|
481 * |
|
482 * Key data specific method to get the key type. |
|
483 * |
|
484 * Returns the key type. |
|
485 */ |
|
486 typedef xmlSecKeyDataType (*xmlSecKeyDataGetTypeMethod) (xmlSecKeyDataPtr data); |
|
487 |
|
488 /** |
|
489 * xmlSecKeyDataGetSizeMethod: |
|
490 * @data: the pointer to key data. |
|
491 * |
|
492 * Key data specific method to get the key size. |
|
493 * |
|
494 * Returns the key size in bits. |
|
495 */ |
|
496 typedef xmlSecSize (*xmlSecKeyDataGetSizeMethod) (xmlSecKeyDataPtr data); |
|
497 |
|
498 /** |
|
499 * xmlSecKeyDataGetIdentifierMethod: |
|
500 * @data: the pointer to key data. |
|
501 * |
|
502 * Key data specific method to get the key data identifier string (for example, |
|
503 * X509 data identifier is the subject of the verified cert). |
|
504 * |
|
505 * Returns the identifier string or NULL if an error occurs. |
|
506 */ |
|
507 typedef const xmlChar* (*xmlSecKeyDataGetIdentifierMethod) (xmlSecKeyDataPtr data); |
|
508 |
|
509 /** |
|
510 * xmlSecKeyDataDebugDumpMethod: |
|
511 * @data: the data. |
|
512 * @output: the FILE to print debug info (should be open for writing). |
|
513 * |
|
514 * Key data specific method for printing debug info. |
|
515 */ |
|
516 typedef void (*xmlSecKeyDataDebugDumpMethod) (xmlSecKeyDataPtr data, |
|
517 FILE* output); |
|
518 |
|
519 /** |
|
520 * xmlSecKeyDataKlass: |
|
521 * @klassSize: the klass size. |
|
522 * @objSize: the object size. |
|
523 * @name: the object name. |
|
524 * @usage: the allowed data usage. |
|
525 * @href: the identification string (href). |
|
526 * @dataNodeName: the data's XML node name. |
|
527 * @dataNodeNs: the data's XML node namespace. |
|
528 * @initialize: the initialization method. |
|
529 * @duplicate: the duplicate (copy) method. |
|
530 * @finalize: the finalization (destroy) method. |
|
531 * @generate: the new data generation method. |
|
532 * @getType: the method to access data's type information. |
|
533 * @getSize: the method to access data's size. |
|
534 * @getIdentifier: the method to access data's string identifier. |
|
535 * @xmlRead: the method for reading data from XML node. |
|
536 * @xmlWrite: the method for writing data to XML node. |
|
537 * @binRead: the method for reading data from a binary buffer. |
|
538 * @binWrite: the method for writing data to binary buffer. |
|
539 * @debugDump: the method for printing debug data information. |
|
540 * @debugXmlDump: the method for printing debug data information in XML format. |
|
541 * @reserved0: reserved for the future. |
|
542 * @reserved1: reserved for the future. |
|
543 * |
|
544 * The data id (klass). |
|
545 */ |
|
546 struct _xmlSecKeyDataKlass { |
|
547 xmlSecSize klassSize; |
|
548 xmlSecSize objSize; |
|
549 |
|
550 /* data */ |
|
551 const xmlChar* name; |
|
552 xmlSecKeyDataUsage usage; |
|
553 const xmlChar* href; |
|
554 const xmlChar* dataNodeName; |
|
555 const xmlChar* dataNodeNs; |
|
556 |
|
557 /* constructors/destructor */ |
|
558 xmlSecKeyDataInitMethod initialize; |
|
559 xmlSecKeyDataDuplicateMethod duplicate; |
|
560 xmlSecKeyDataFinalizeMethod finalize; |
|
561 xmlSecKeyDataGenerateMethod generate; |
|
562 |
|
563 /* get info */ |
|
564 xmlSecKeyDataGetTypeMethod getType; |
|
565 xmlSecKeyDataGetSizeMethod getSize; |
|
566 xmlSecKeyDataGetIdentifierMethod getIdentifier; |
|
567 |
|
568 /* read/write */ |
|
569 xmlSecKeyDataXmlReadMethod xmlRead; |
|
570 xmlSecKeyDataXmlWriteMethod xmlWrite; |
|
571 xmlSecKeyDataBinReadMethod binRead; |
|
572 xmlSecKeyDataBinWriteMethod binWrite; |
|
573 |
|
574 /* debug */ |
|
575 xmlSecKeyDataDebugDumpMethod debugDump; |
|
576 xmlSecKeyDataDebugDumpMethod debugXmlDump; |
|
577 |
|
578 /* for the future */ |
|
579 void* reserved0; |
|
580 void* reserved1; |
|
581 }; |
|
582 |
|
583 /** |
|
584 * xmlSecKeyDataKlassGetName: |
|
585 * @klass: the data klass. |
|
586 * |
|
587 * Macro. Returns data klass name. |
|
588 */ |
|
589 #define xmlSecKeyDataKlassGetName(klass) \ |
|
590 (((klass)) ? ((klass)->name) : NULL) |
|
591 |
|
592 /*********************************************************************** |
|
593 * |
|
594 * Key Data list |
|
595 * |
|
596 **********************************************************************/ |
|
597 /** |
|
598 * xmlSecKeyDataListId: |
|
599 * |
|
600 * |
|
601 * The key data klasses list klass id. |
|
602 */ |
|
603 #define xmlSecKeyDataListId xmlSecKeyDataListGetKlass() |
|
604 XMLSEC_EXPORT xmlSecPtrListId xmlSecKeyDataListGetKlass (void); |
|
605 |
|
606 /*********************************************************************** |
|
607 * |
|
608 * Key Data Ids list |
|
609 * |
|
610 **********************************************************************/ |
|
611 /** |
|
612 * xmlSecKeyDataIdListId: |
|
613 * |
|
614 * |
|
615 * The key data list klass id. |
|
616 */ |
|
617 #define xmlSecKeyDataIdListId xmlSecKeyDataIdListGetKlass() |
|
618 XMLSEC_EXPORT xmlSecPtrListId xmlSecKeyDataIdListGetKlass (void); |
|
619 XMLSEC_EXPORT int xmlSecKeyDataIdListFind (xmlSecPtrListPtr list, |
|
620 xmlSecKeyDataId dataId); |
|
621 XMLSEC_EXPORT xmlSecKeyDataId xmlSecKeyDataIdListFindByNode (xmlSecPtrListPtr list, |
|
622 const xmlChar* nodeName, |
|
623 const xmlChar* nodeNs, |
|
624 xmlSecKeyDataUsage usage); |
|
625 XMLSEC_EXPORT xmlSecKeyDataId xmlSecKeyDataIdListFindByHref (xmlSecPtrListPtr list, |
|
626 const xmlChar* href, |
|
627 xmlSecKeyDataUsage usage); |
|
628 XMLSEC_EXPORT xmlSecKeyDataId xmlSecKeyDataIdListFindByName (xmlSecPtrListPtr list, |
|
629 const xmlChar* name, |
|
630 xmlSecKeyDataUsage usage); |
|
631 XMLSEC_EXPORT void xmlSecKeyDataIdListDebugDump (xmlSecPtrListPtr list, |
|
632 FILE* output); |
|
633 XMLSEC_EXPORT void xmlSecKeyDataIdListDebugXmlDump (xmlSecPtrListPtr list, |
|
634 FILE* output); |
|
635 |
|
636 /************************************************************************** |
|
637 * |
|
638 * xmlSecKeyDataBinary |
|
639 * |
|
640 * key (xmlSecBuffer) is located after xmlSecKeyData structure |
|
641 * |
|
642 *************************************************************************/ |
|
643 /** |
|
644 * xmlSecKeyDataBinarySize: |
|
645 * |
|
646 * The binary key data object size. |
|
647 */ |
|
648 #define xmlSecKeyDataBinarySize \ |
|
649 (sizeof(xmlSecKeyData) + sizeof(xmlSecBuffer)) |
|
650 |
|
651 XMLSEC_EXPORT int xmlSecKeyDataBinaryValueInitialize (xmlSecKeyDataPtr data); |
|
652 XMLSEC_EXPORT int xmlSecKeyDataBinaryValueDuplicate (xmlSecKeyDataPtr dst, |
|
653 xmlSecKeyDataPtr src); |
|
654 XMLSEC_EXPORT void xmlSecKeyDataBinaryValueFinalize (xmlSecKeyDataPtr data); |
|
655 XMLSEC_EXPORT int xmlSecKeyDataBinaryValueXmlRead (xmlSecKeyDataId id, |
|
656 xmlSecKeyPtr key, |
|
657 xmlNodePtr node, |
|
658 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
659 XMLSEC_EXPORT int xmlSecKeyDataBinaryValueXmlWrite (xmlSecKeyDataId id, |
|
660 xmlSecKeyPtr key, |
|
661 xmlNodePtr node, |
|
662 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
663 XMLSEC_EXPORT int xmlSecKeyDataBinaryValueBinRead (xmlSecKeyDataId id, |
|
664 xmlSecKeyPtr key, |
|
665 const xmlSecByte* buf, |
|
666 xmlSecSize bufSize, |
|
667 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
668 XMLSEC_EXPORT int xmlSecKeyDataBinaryValueBinWrite (xmlSecKeyDataId id, |
|
669 xmlSecKeyPtr key, |
|
670 xmlSecByte** buf, |
|
671 xmlSecSize* bufSize, |
|
672 xmlSecKeyInfoCtxPtr keyInfoCtx); |
|
673 XMLSEC_EXPORT void xmlSecKeyDataBinaryValueDebugDump (xmlSecKeyDataPtr data, |
|
674 FILE* output); |
|
675 XMLSEC_EXPORT void xmlSecKeyDataBinaryValueDebugXmlDump (xmlSecKeyDataPtr data, |
|
676 FILE* output); |
|
677 |
|
678 XMLSEC_EXPORT xmlSecSize xmlSecKeyDataBinaryValueGetSize (xmlSecKeyDataPtr data); |
|
679 XMLSEC_EXPORT xmlSecBufferPtr xmlSecKeyDataBinaryValueGetBuffer (xmlSecKeyDataPtr data); |
|
680 XMLSEC_EXPORT int xmlSecKeyDataBinaryValueSetBuffer (xmlSecKeyDataPtr data, |
|
681 const xmlSecByte* buf, |
|
682 xmlSecSize bufSize); |
|
683 |
|
684 /************************************************************************** |
|
685 * |
|
686 * xmlSecKeyDataStore |
|
687 * |
|
688 *************************************************************************/ |
|
689 /** |
|
690 * xmlSecKeyDataStore: |
|
691 * @id: the store id (#xmlSecKeyDataStoreId). |
|
692 * @reserved0: reserved for the future. |
|
693 * @reserved1: reserved for the future. |
|
694 * |
|
695 * The key data store. Key data store holds common key data specific information |
|
696 * required for key data processing. For example, X509 data store may hold |
|
697 * information about trusted (root) certificates. |
|
698 */ |
|
699 struct _xmlSecKeyDataStore { |
|
700 xmlSecKeyDataStoreId id; |
|
701 |
|
702 /* for the future */ |
|
703 void* reserved0; |
|
704 void* reserved1; |
|
705 }; |
|
706 |
|
707 XMLSEC_EXPORT xmlSecKeyDataStorePtr xmlSecKeyDataStoreCreate (xmlSecKeyDataStoreId id); |
|
708 XMLSEC_EXPORT void xmlSecKeyDataStoreDestroy (xmlSecKeyDataStorePtr store); |
|
709 |
|
710 /** |
|
711 * xmlSecKeyDataStoreGetName: |
|
712 * @store: the pointer to store. |
|
713 * |
|
714 * Macro. Returns key data store name. |
|
715 */ |
|
716 #define xmlSecKeyDataStoreGetName(store) \ |
|
717 ((xmlSecKeyDataStoreIsValid((store))) ? \ |
|
718 xmlSecKeyDataStoreKlassGetName((store)->id) : NULL) |
|
719 |
|
720 /** |
|
721 * xmlSecKeyDataStoreIsValid: |
|
722 * @store: the pointer to store. |
|
723 * |
|
724 * Macro. Returns 1 if @store is not NULL and @store->id is not NULL |
|
725 * or 0 otherwise. |
|
726 */ |
|
727 #define xmlSecKeyDataStoreIsValid(store) \ |
|
728 ((( store ) != NULL) && ((( store )->id) != NULL)) |
|
729 /** |
|
730 * xmlSecKeyDataStoreCheckId: |
|
731 * @store: the pointer to store. |
|
732 * @storeId: the store Id. |
|
733 * |
|
734 * Macro. Returns 1 if @store is valid and @store's id is equal to @storeId. |
|
735 */ |
|
736 #define xmlSecKeyDataStoreCheckId(store, storeId) \ |
|
737 (xmlSecKeyDataStoreIsValid(( store )) && \ |
|
738 ((( store )->id) == ( storeId ))) |
|
739 |
|
740 /** |
|
741 * xmlSecKeyDataStoreCheckSize: |
|
742 * @store: the pointer to store. |
|
743 * @size: the expected size. |
|
744 * |
|
745 * Macro. Returns 1 if @data is valid and @stores's object has at least @size bytes. |
|
746 */ |
|
747 #define xmlSecKeyDataStoreCheckSize(store, size) \ |
|
748 (xmlSecKeyDataStoreIsValid(( store )) && \ |
|
749 (( store )->id->objSize >= size)) |
|
750 |
|
751 |
|
752 /************************************************************************** |
|
753 * |
|
754 * xmlSecKeyDataStoreKlass |
|
755 * |
|
756 *************************************************************************/ |
|
757 /** |
|
758 * xmlSecKeyDataStoreIdUnknown: |
|
759 * |
|
760 * The "unknown" id. |
|
761 */ |
|
762 #define xmlSecKeyDataStoreIdUnknown NULL |
|
763 |
|
764 /** |
|
765 * xmlSecKeyDataStoreInitializeMethod: |
|
766 * @store: the data store. |
|
767 * |
|
768 * Key data store specific initialization method. |
|
769 * |
|
770 * Returns 0 on success or a negative value if an error occurs. |
|
771 */ |
|
772 typedef int (*xmlSecKeyDataStoreInitializeMethod) (xmlSecKeyDataStorePtr store); |
|
773 |
|
774 /** |
|
775 * xmlSecKeyDataStoreFinalizeMethod: |
|
776 * @store: the data store. |
|
777 * |
|
778 * Key data store specific finalization (destroy) method. |
|
779 */ |
|
780 typedef void (*xmlSecKeyDataStoreFinalizeMethod) (xmlSecKeyDataStorePtr store); |
|
781 |
|
782 /** |
|
783 * xmlSecKeyDataStoreKlass: |
|
784 * @klassSize: the data store klass size. |
|
785 * @objSize: the data store obj size. |
|
786 * @name: the store's name. |
|
787 * @initialize: the store's initialization method. |
|
788 * @finalize: the store's finalization (destroy) method. |
|
789 * @reserved0: reserved for the future. |
|
790 * @reserved1: reserved for the future. |
|
791 * |
|
792 * The data store id (klass). |
|
793 */ |
|
794 struct _xmlSecKeyDataStoreKlass { |
|
795 xmlSecSize klassSize; |
|
796 xmlSecSize objSize; |
|
797 |
|
798 /* data */ |
|
799 const xmlChar* name; |
|
800 |
|
801 /* constructors/destructor */ |
|
802 xmlSecKeyDataStoreInitializeMethod initialize; |
|
803 xmlSecKeyDataStoreFinalizeMethod finalize; |
|
804 |
|
805 /* for the future */ |
|
806 void* reserved0; |
|
807 void* reserved1; |
|
808 }; |
|
809 |
|
810 /** |
|
811 * xmlSecKeyDataStoreKlassGetName: |
|
812 * @klass: the pointer to store klass. |
|
813 * |
|
814 * Macro. Returns store klass name. |
|
815 */ |
|
816 #define xmlSecKeyDataStoreKlassGetName(klass) \ |
|
817 (((klass)) ? ((klass)->name) : NULL) |
|
818 |
|
819 /*********************************************************************** |
|
820 * |
|
821 * Key Data Store list |
|
822 * |
|
823 **********************************************************************/ |
|
824 /** |
|
825 * xmlSecKeyDataStorePtrListId: |
|
826 * |
|
827 * The data store list id (klass). |
|
828 */ |
|
829 #define xmlSecKeyDataStorePtrListId xmlSecKeyDataStorePtrListGetKlass() |
|
830 XMLSEC_EXPORT xmlSecPtrListId xmlSecKeyDataStorePtrListGetKlass (void); |
|
831 |
|
832 |
|
833 #ifdef __cplusplus |
|
834 } |
|
835 #endif /* __cplusplus */ |
|
836 |
|
837 #endif /* __XMLSEC_KEYSDATA_H__ */ |