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-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
10  */
11 #ifndef __XMLSEC_KEYSDATA_H__
12 #define __XMLSEC_KEYSDATA_H__
13 
14 #include <libxml/tree.h>
15 
16 #include <xmlsec/xmlsec.h>
17 #include <xmlsec/buffer.h>
18 #include <xmlsec/list.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
24 /****************************************************************************
25  *
26  * Forward declarations
27  *
28  ****************************************************************************/
29 typedef const struct _xmlSecKeyDataKlass                xmlSecKeyDataKlass,
30                                                         *xmlSecKeyDataId;
31 typedef const struct _xmlSecKeyDataStoreKlass           xmlSecKeyDataStoreKlass,
32                                                         *xmlSecKeyDataStoreId;
33 typedef struct _xmlSecKeyDataList                       xmlSecKeyDataList,
34                                                         *xmlSecKeyDataListPtr;
35 
36 
37 /**************************************************************************
38  *
39  * xmlSecKeyDataUsage
40  *
41  *************************************************************************/
42 /**
43  * xmlSecKeyDataUsage:
44  *
45  * The bits mask that determines possible keys data usage.
46  */
47 typedef unsigned int                                    xmlSecKeyDataUsage;
48 
49 /**
50  * xmlSecKeyDataUsageUnknown:
51  *
52  * The key data usage is unknown.
53  */
54 #define xmlSecKeyDataUsageUnknown                       0x00000
55 
56 /**
57  * xmlSecKeyDataUsageKeyInfoNodeRead:
58  *
59  * The key data could be read from a <dsig:KeyInfo/> child.
60  */
61 #define xmlSecKeyDataUsageKeyInfoNodeRead               0x00001
62 
63 /**
64  * xmlSecKeyDataUsageKeyInfoNodeWrite:
65  *
66  * The key data could be written to a <dsig:KeyInfo /> child.
67  */
68 #define xmlSecKeyDataUsageKeyInfoNodeWrite              0x00002
69 
70 /**
71  * xmlSecKeyDataUsageKeyValueNodeRead:
72  *
73  * The key data could be read from a <dsig:KeyValue /> child.
74  */
75 #define xmlSecKeyDataUsageKeyValueNodeRead              0x00004
76 
77 /**
78  * xmlSecKeyDataUsageKeyValueNodeWrite:
79  *
80  * The key data could be written to a <dsig:KeyValue /> child.
81  */
82 #define xmlSecKeyDataUsageKeyValueNodeWrite             0x00008
83 
84 /**
85  * xmlSecKeyDataUsageRetrievalMethodNodeXml:
86  *
87  * The key data could be retrieved using <dsig:RetrievalMethod /> node
88  * in XML format.
89  */
90 #define xmlSecKeyDataUsageRetrievalMethodNodeXml        0x00010
91 
92 /**
93  * xmlSecKeyDataUsageRetrievalMethodNodeBin:
94  *
95  * The key data could be retrieved using <dsig:RetrievalMethod /> node
96  * in binary format.
97  */
98 #define xmlSecKeyDataUsageRetrievalMethodNodeBin        0x00020
99 
100 /**
101  * xmlSecKeyDataUsageAny:
102  *
103  * Any key data usage.
104  */
105 #define xmlSecKeyDataUsageAny                           0xFFFFF
106 
107 /**
108  * xmlSecKeyDataUsageKeyInfoNode:
109  *
110  * The key data could be read and written from/to a <dsig:KeyInfo /> child.
111  */
112 #define xmlSecKeyDataUsageKeyInfoNode                   \
113         (xmlSecKeyDataUsageKeyInfoNodeRead | xmlSecKeyDataUsageKeyInfoNodeWrite)
114 
115 /**
116  * xmlSecKeyDataUsageKeyValueNode:
117  *
118  * The key data could be read and written from/to a <dsig:KeyValue /> child.
119  */
120 #define xmlSecKeyDataUsageKeyValueNode                  \
121         (xmlSecKeyDataUsageKeyValueNodeRead | xmlSecKeyDataUsageKeyValueNodeWrite)
122 
123 /**
124  * xmlSecKeyDataUsageRetrievalMethodNode:
125  *
126  * The key data could be retrieved using <dsig:RetrievalMethod /> node
127  * in any format.
128  */
129 #define xmlSecKeyDataUsageRetrievalMethodNode           \
130         (xmlSecKeyDataUsageRetrievalMethodNodeXml | xmlSecKeyDataUsageRetrievalMethodNodeBin)
131 
132 /**************************************************************************
133  *
134  * xmlSecKeyDataType
135  *
136  *************************************************************************/
137 /**
138  * xmlSecKeyDataType:
139  *
140  * The key data type (public/private, session/permanent, etc.).
141  */
142 typedef unsigned int                            xmlSecKeyDataType;
143 
144 /**
145  * xmlSecKeyDataTypeUnknown:
146  *
147  * The key data type is unknown (same as #xmlSecKeyDataTypeNone).
148  */
149 #define xmlSecKeyDataTypeUnknown                        0x0000
150 
151 /**
152  * xmlSecKeyDataTypeNone:
153  *
154  * The key data type is unknown (same as #xmlSecKeyDataTypeUnknown).
155  */
156 #define xmlSecKeyDataTypeNone                           xmlSecKeyDataTypeUnknown
157 
158 /**
159  * xmlSecKeyDataTypePublic:
160  *
161  * The key data contain a public key.
162  */
163 #define xmlSecKeyDataTypePublic                         0x0001
164 
165 /**
166  * xmlSecKeyDataTypePrivate:
167  *
168  * The key data contain a private key.
169  */
170 #define xmlSecKeyDataTypePrivate                        0x0002
171 
172 /**
173  * xmlSecKeyDataTypeSymmetric:
174  *
175  * The key data contain a symmetric key.
176  */
177 #define xmlSecKeyDataTypeSymmetric                      0x0004
178 
179 /**
180  * xmlSecKeyDataTypeSession:
181  *
182  * The key data contain session key (one time key, not stored in keys manager).
183  */
184 #define xmlSecKeyDataTypeSession                        0x0008
185 
186 /**
187  * xmlSecKeyDataTypePermanent:
188  *
189  * The key data contain permanent key (stored in keys manager).
190  */
191 #define xmlSecKeyDataTypePermanent                      0x0010
192 
193 /**
194  * xmlSecKeyDataTypeTrusted:
195  *
196  * The key data is trusted.
197  */
198 #define xmlSecKeyDataTypeTrusted                        0x0100
199 
200 /**
201  * xmlSecKeyDataTypeAny:
202  *
203  * Any key data.
204  */
205 #define xmlSecKeyDataTypeAny                            0xFFFF
206 
207 /**************************************************************************
208  *
209  * xmlSecKeyDataFormat
210  *
211  *************************************************************************/
212 /**
213  * xmlSecKeyDataFormat:
214  * @xmlSecKeyDataFormatUnknown:         the key data format is unknown.
215  * @xmlSecKeyDataFormatBinary:          the binary key data.
216  * @xmlSecKeyDataFormatPem:             the PEM key data (cert or public/private key).
217  * @xmlSecKeyDataFormatDer:             the DER key data (cert or public/private key).
218  * @xmlSecKeyDataFormatPkcs8Pem:        the PKCS8 PEM private key.
219  * @xmlSecKeyDataFormatPkcs8Der:        the PKCS8 DER private key.
220  * @xmlSecKeyDataFormatPkcs12:          the PKCS12 format (bag of keys and certs)
221  * @xmlSecKeyDataFormatCertPem:         the PEM cert.
222  * @xmlSecKeyDataFormatCertDer:         the DER cert.
223  *
224  * The key data format (binary, der, pem, etc.).
225  */
226 typedef enum {
227     xmlSecKeyDataFormatUnknown = 0,
228     xmlSecKeyDataFormatBinary,
229     xmlSecKeyDataFormatPem,
230     xmlSecKeyDataFormatDer,
231     xmlSecKeyDataFormatPkcs8Pem,
232     xmlSecKeyDataFormatPkcs8Der,
233     xmlSecKeyDataFormatPkcs12,
234     xmlSecKeyDataFormatCertPem,
235     xmlSecKeyDataFormatCertDer
236 } xmlSecKeyDataFormat;
237 
238 /**************************************************************************
239  *
240  * Global xmlSecKeyDataIds methods
241  *
242  *************************************************************************/
243 XMLSEC_EXPORT xmlSecPtrListPtr  xmlSecKeyDataIdsGet             (void);
244 XMLSEC_EXPORT int               xmlSecKeyDataIdsInit            (void);
245 XMLSEC_EXPORT void              xmlSecKeyDataIdsShutdown        (void);
246 XMLSEC_EXPORT int               xmlSecKeyDataIdsRegisterDefault (void);
247 XMLSEC_EXPORT int               xmlSecKeyDataIdsRegister        (xmlSecKeyDataId id);
248 
249 /**************************************************************************
250  *
251  * xmlSecKeyData
252  *
253  *************************************************************************/
254 /**
255  * xmlSecKeyData:
256  * @id:                 the data id (#xmlSecKeyDataId).
257  * @reserved0:          reserved for the future.
258  * @reserved1:          reserved for the future.
259  *
260  * The key data: key value (crypto material), x509 data, pgp data, etc.
261  */
262 struct _xmlSecKeyData {
263     xmlSecKeyDataId                     id;
264     void*                               reserved0;
265     void*                               reserved1;
266 };
267 
268 XMLSEC_EXPORT xmlSecKeyDataPtr  xmlSecKeyDataCreate             (xmlSecKeyDataId id);
269 XMLSEC_EXPORT xmlSecKeyDataPtr  xmlSecKeyDataDuplicate          (xmlSecKeyDataPtr data);
270 XMLSEC_EXPORT void              xmlSecKeyDataDestroy            (xmlSecKeyDataPtr data);
271 XMLSEC_EXPORT int               xmlSecKeyDataGenerate           (xmlSecKeyDataPtr data,
272                                                                  xmlSecSize sizeBits,
273                                                                  xmlSecKeyDataType type);
274 XMLSEC_EXPORT xmlSecKeyDataType xmlSecKeyDataGetType            (xmlSecKeyDataPtr data);
275 XMLSEC_EXPORT xmlSecSize        xmlSecKeyDataGetSize            (xmlSecKeyDataPtr data);
276 XMLSEC_EXPORT const xmlChar*    xmlSecKeyDataGetIdentifier      (xmlSecKeyDataPtr data);
277 XMLSEC_EXPORT void              xmlSecKeyDataDebugDump          (xmlSecKeyDataPtr data,
278                                                                  FILE *output);
279 XMLSEC_EXPORT void              xmlSecKeyDataDebugXmlDump       (xmlSecKeyDataPtr data,
280                                                                  FILE *output);
281 XMLSEC_EXPORT int               xmlSecKeyDataXmlRead            (xmlSecKeyDataId id,
282                                                                  xmlSecKeyPtr key,
283                                                                  xmlNodePtr node,
284                                                                  xmlSecKeyInfoCtxPtr keyInfoCtx);
285 XMLSEC_EXPORT int               xmlSecKeyDataXmlWrite           (xmlSecKeyDataId id,
286                                                                  xmlSecKeyPtr key,
287                                                                  xmlNodePtr node,
288                                                                  xmlSecKeyInfoCtxPtr keyInfoCtx);
289 XMLSEC_EXPORT int               xmlSecKeyDataBinRead            (xmlSecKeyDataId id,
290                                                                  xmlSecKeyPtr key,
291                                                                  const xmlSecByte* buf,
292                                                                  xmlSecSize bufSize,
293                                                                  xmlSecKeyInfoCtxPtr keyInfoCtx);
294 XMLSEC_EXPORT int               xmlSecKeyDataBinWrite           (xmlSecKeyDataId id,
295                                                                  xmlSecKeyPtr key,
296                                                                  xmlSecByte** buf,
297                                                                  xmlSecSize* bufSize,
298                                                                  xmlSecKeyInfoCtxPtr keyInfoCtx);
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 pointer 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 #ifdef XMLSEC_PRIVATE
833 XMLSEC_EXPORT void xmlSecImportSetPersistKey                            (void);
834 XMLSEC_EXPORT int xmlSecImportGetPersistKey                             (void);
835 #endif
836 
837 #ifdef __cplusplus
838 }
839 #endif /* __cplusplus */
840 
841 #endif /* __XMLSEC_KEYSDATA_H__ */
842