summaryrefslogtreecommitdiff
path: root/docs/api/xmlsec-notes-new-crypto-klasses.html
blob: 1f8b7a3d6c2a6471b8450946970c23b16384f7b8 (plain)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Klasses and objects.: XML Security Library Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="XML Security Library Reference Manual">
<link rel="up" href="xmlsec-notes-new-crypto.html" title="Adding support for new cryptographic library.">
<link rel="prev" href="xmlsec-notes-new-crypto-functions.html" title="xmlSecCryptoApp* functions.">
<link rel="next" href="xmlsec-notes-new-crypto-transforms.html" title="Cryptographic transforms.">
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="xmlsec-notes-new-crypto.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="xmlsec-notes-new-crypto-functions.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="xmlsec-notes-new-crypto-transforms.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="xmlsec-notes-new-crypto-klasses"></a>Klasses and objects.</h2></div></div></div>
<p>The XML Security Library is written in C but it uses some OOP techniques:
	the objects in the library have "klasses" and there is "klasses" inheritance.
	(see <a class="link" href="xmlsec-signature-klasses.html" title="APPENDIX A. XML Security Library Signature Klasses.">signature</a> and
	<a class="link" href="xmlsec-encryption-klasses.html" title="APPENDIX B. XML Security Library Encryption Klasses.">encryption</a> klasses 
	diagrams). The "klass" is different from C++ "class" (btw, this is 
	one of the reasons why it is spelled differently). The idea of "klasses" 
	used in XML Security Library are close to one in the GLIB/GTK/GNOME
	and many other C projects. If you ever seen an OOP code written in C
	you should find everything familiar.
	</p>
<p>XML Security Library "klass" includes three main parts:
	</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>"Klass" declaration structure that defines "klass" interfaces
	and global constant data (for example, the human-readable name of 
	the "klass").
	</p>
<div class="example">
<a name="id-1.2.14.5.3.1.1.1.1"></a><p class="title"><b>Example 30. Base transform "klass" and its child XPath transform "klass" structure.</b></p>
<div class="example-contents"><pre class="programlisting">
struct _xmlSecTransformKlass {
    /* data */
    size_t				klassSize;
    size_t				objSize;
    const xmlChar*			name;
    const xmlChar*			href;
    xmlSecTransformUsage		usage;

    /* methods */
    xmlSecTransformInitializeMethod	initialize;
    xmlSecTransformFinalizeMethod	finalize;

    xmlSecTransformNodeReadMethod	readNode;
    xmlSecTransformNodeWriteMethod	writeNode;

    ...
};

...

static xmlSecTransformKlass xmlSecTransformXPathKlass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),	/* size_t klassSize */
    xmlSecXPathTransformSize,		/* size_t objSize */

    xmlSecNameXPath,			/* const xmlChar* name; */
    xmlSecXPathNs, 			/* const xmlChar* href; */
    xmlSecTransformUsageDSigTransform,	/* xmlSecTransformUsage	usage; */

    xmlSecTransformXPathInitialize,	/* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformXPathFinalize,	/* xmlSecTransformFinalizeMethod finalize; */
    xmlSecTransformXPathNodeRead,	/* xmlSecTransformNodeReadMethod readNode; */
    NULL,				/* xmlSecTransformNodeWriteMethod writeNode; */
    
    ...
};
	    </pre></div>
</div>
<p><br class="example-break">
	</p>
</li>
<li class="listitem">
<p>"Klass" id which is simply a pointer to the "klass"
	declaration strucutre. "Klass" id is used to bind "klass" objects 
	to the "klass" declaration and to pass "klass" strucutre to functions.
	</p>
<div class="example">
<a name="id-1.2.14.5.3.1.2.1.1"></a><p class="title"><b>Example 31. Base transform "klass" id declaration and its child XPath transform "klass" id implementation.</b></p>
<div class="example-contents"><pre class="programlisting">
typedef const struct _xmlSecTransformKlass		xmlSecTransformKlass, *xmlSecTransformId;

...

#define xmlSecTransformXPathId 		xmlSecTransformXPathGetKlass()

...

xmlSecTransformId 
xmlSecTransformXPathGetKlass(void) {
    return(&amp;xmlSecTransformXPathKlass);
}
	    </pre></div>
</div>
<p><br class="example-break">
	</p>
</li>
<li class="listitem">
<p>"Klass" object structure that contains object specific
	data. The child object specific data are placed after the parent "klass"
	object data.
	</p>
<div class="example">
<a name="id-1.2.14.5.3.1.3.1.1"></a><p class="title"><b>Example 32. Base transform object strucutre and its child XPath transform object.</b></p>
<div class="example-contents"><pre class="programlisting">
struct _xmlSecTransform {
    xmlSecTransformId 			id; 
    xmlSecTransformOperation		operation;
    xmlSecTransformStatus		status;
    xmlNodePtr				hereNode;

    /* transforms chain */
    xmlSecTransformPtr			next;
    xmlSecTransformPtr			prev;
    
    ...
};

...

/******************************************************************************
 *
 * XPath/XPointer transforms
 *
 * xmlSecPtrList with XPath expressions is located after xmlSecTransform structure
 * 
 *****************************************************************************/
#define xmlSecXPathTransformSize	\
    (sizeof(xmlSecTransform) + sizeof(xmlSecPtrList))
#define xmlSecXPathTransformGetDataList(transform) \
    ((xmlSecTransformCheckSize((transform), xmlSecXPathTransformSize)) ? \
	(xmlSecPtrListPtr)(((unsigned char*)(transform)) + sizeof(xmlSecTransform)) : \
	(xmlSecPtrListPtr)NULL)
	    </pre></div>
</div>
<p><br class="example-break">
	</p>
</li>
</ul></div>
<p>
	</p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.27</div>
</body>
</html>