summaryrefslogtreecommitdiff
path: root/src/c14n.c
blob: 5967a35e70808ea340f4a8ba43c2fee729dce38d (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
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
/**
 * XML Security Library (http://www.aleksey.com/xmlsec).
 *
 * Canonicalization transforms.
 *
 * This is free software; see Copyright file in the source
 * distribution for preciese wording.
 *
 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com>
 */
#include "globals.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <libxml/tree.h>
#include <libxml/c14n.h>

#include <xmlsec/xmlsec.h>
#include <xmlsec/keys.h>
#include <xmlsec/list.h>
#include <xmlsec/transforms.h>
#include <xmlsec/xmltree.h>
#include <xmlsec/errors.h>

/******************************************************************************
 *
 * C14N transforms
 *
 * Inclusive namespaces list for ExclC14N (xmlSecStringList) is located
 * after xmlSecTransform structure
 *
 *****************************************************************************/
#define xmlSecTransformC14NSize \
    (sizeof(xmlSecTransform) + sizeof(xmlSecPtrList))
#define xmlSecTransformC14NGetNsList(transform) \
    ((xmlSecTransformCheckSize((transform), xmlSecTransformC14NSize)) ? \
        (xmlSecPtrListPtr)(((xmlSecByte*)(transform)) + sizeof(xmlSecTransform)) : \
        (xmlSecPtrListPtr)NULL)

#define xmlSecTransformC14NCheckId(transform) \
    (xmlSecTransformInclC14NCheckId((transform)) || \
     xmlSecTransformInclC14N11CheckId((transform)) || \
     xmlSecTransformExclC14NCheckId((transform)) || \
     xmlSecTransformCheckId((transform), xmlSecTransformRemoveXmlTagsC14NId))
#define xmlSecTransformInclC14NCheckId(transform) \
    (xmlSecTransformCheckId((transform), xmlSecTransformInclC14NId) || \
     xmlSecTransformCheckId((transform), xmlSecTransformInclC14NWithCommentsId))
#define xmlSecTransformInclC14N11CheckId(transform) \
    (xmlSecTransformCheckId((transform), xmlSecTransformInclC14N11Id) || \
     xmlSecTransformCheckId((transform), xmlSecTransformInclC14N11WithCommentsId))
#define xmlSecTransformExclC14NCheckId(transform) \
    (xmlSecTransformCheckId((transform), xmlSecTransformExclC14NId) || \
     xmlSecTransformCheckId((transform), xmlSecTransformExclC14NWithCommentsId) )


static int              xmlSecTransformC14NInitialize   (xmlSecTransformPtr transform);
static void             xmlSecTransformC14NFinalize     (xmlSecTransformPtr transform);
static int              xmlSecTransformC14NNodeRead     (xmlSecTransformPtr transform,
                                                         xmlNodePtr node,
                                                         xmlSecTransformCtxPtr transformCtx);
static int              xmlSecTransformC14NPushXml      (xmlSecTransformPtr transform,
                                                         xmlSecNodeSetPtr nodes,
                                                         xmlSecTransformCtxPtr transformCtx);
static int              xmlSecTransformC14NPopBin       (xmlSecTransformPtr transform,
                                                         xmlSecByte* data,
                                                         xmlSecSize maxDataSize,
                                                         xmlSecSize* dataSize,
                                                         xmlSecTransformCtxPtr transformCtx);
static int              xmlSecTransformC14NExecute      (xmlSecTransformId id,
                                                         xmlSecNodeSetPtr nodes,
                                                         xmlChar** nsList,
                                                         xmlOutputBufferPtr buf);
static int
xmlSecTransformC14NInitialize(xmlSecTransformPtr transform) {
    xmlSecPtrListPtr nsList;
    int ret;

    xmlSecAssert2(xmlSecTransformC14NCheckId(transform), -1);

    nsList = xmlSecTransformC14NGetNsList(transform);
    xmlSecAssert2(nsList != NULL, -1);

    ret = xmlSecPtrListInitialize(nsList, xmlSecStringListId);
    if(ret < 0) {
        xmlSecError(XMLSEC_ERRORS_HERE,
                    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                    "xmlSecPtrListInitialize",
                    XMLSEC_ERRORS_R_XMLSEC_FAILED,
                    XMLSEC_ERRORS_NO_MESSAGE);
        return(-1);
    }
    return(0);
}

static void
xmlSecTransformC14NFinalize(xmlSecTransformPtr transform) {
    xmlSecPtrListPtr nsList;

    xmlSecAssert(xmlSecTransformC14NCheckId(transform));

    nsList = xmlSecTransformC14NGetNsList(transform);
    xmlSecAssert(xmlSecPtrListCheckId(nsList, xmlSecStringListId));

    xmlSecPtrListFinalize(nsList);
}

static int
xmlSecTransformC14NNodeRead(xmlSecTransformPtr transform, xmlNodePtr node, xmlSecTransformCtxPtr transformCtx) {
    xmlSecPtrListPtr nsList;
    xmlNodePtr cur;
    xmlChar *list;
    xmlChar *p, *n, *tmp;
    int ret;

    /* we have something to read only for exclusive c14n transforms */
    xmlSecAssert2(xmlSecTransformExclC14NCheckId(transform), -1);
    xmlSecAssert2(node != NULL, -1);
    xmlSecAssert2(transformCtx != NULL, -1);

    nsList = xmlSecTransformC14NGetNsList(transform);
    xmlSecAssert2(xmlSecPtrListCheckId(nsList, xmlSecStringListId), -1);
    xmlSecAssert2(xmlSecPtrListGetSize(nsList) == 0, -1);

    /* there is only one optional node */
    cur = xmlSecGetNextElementNode(node->children);
    if(cur != NULL) {
        if(!xmlSecCheckNodeName(cur, xmlSecNodeInclusiveNamespaces, xmlSecNsExcC14N)) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
                        XMLSEC_ERRORS_R_INVALID_NODE,
                        XMLSEC_ERRORS_NO_MESSAGE);
            return(-1);
        }

        list = xmlGetProp(cur, xmlSecAttrPrefixList);
        if(list == NULL) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        xmlSecErrorsSafeString(xmlSecAttrPrefixList),
                        XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE,
                        "node=%s",
                        xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
            return(-1);
        }

        /* the list of namespaces is space separated */
        for(p = n = list; ((p != NULL) && ((*p) != '\0')); p = n) {
            n = (xmlChar*)xmlStrchr(p, ' ');
            if(n != NULL) {
                *(n++) = '\0';
            }

            tmp = xmlStrdup(p);
            if(tmp == NULL) {
                xmlSecError(XMLSEC_ERRORS_HERE,
                            xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                            NULL,
                            XMLSEC_ERRORS_R_STRDUP_FAILED,
                            "len=%d", xmlStrlen(p));
                xmlFree(list);
                return(-1);
            }

            ret = xmlSecPtrListAdd(nsList, tmp);
            if(ret < 0) {
                xmlSecError(XMLSEC_ERRORS_HERE,
                            xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                            "xmlSecPtrListAdd",
                            XMLSEC_ERRORS_R_XMLSEC_FAILED,
                            XMLSEC_ERRORS_NO_MESSAGE);
                xmlFree(tmp);
                xmlFree(list);
                return(-1);
            }
        }
        xmlFree(list);

        /* add NULL at the end */
        ret = xmlSecPtrListAdd(nsList, NULL);
        if(ret < 0) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        "xmlSecPtrListAdd",
                        XMLSEC_ERRORS_R_XMLSEC_FAILED,
                        XMLSEC_ERRORS_NO_MESSAGE);
            return(-1);
        }

        cur = xmlSecGetNextElementNode(cur->next);
    }

    /* check that we have nothing else */
    if(cur != NULL) {
        xmlSecError(XMLSEC_ERRORS_HERE,
                    NULL,
                    xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
                    XMLSEC_ERRORS_R_UNEXPECTED_NODE,
                    XMLSEC_ERRORS_NO_MESSAGE);
        return(-1);
    }

    return(0);
}

static int
xmlSecTransformC14NPushXml(xmlSecTransformPtr transform, xmlSecNodeSetPtr nodes,
                            xmlSecTransformCtxPtr transformCtx) {
    xmlOutputBufferPtr buf;
    xmlSecPtrListPtr nsList;
    int ret;

    xmlSecAssert2(xmlSecTransformC14NCheckId(transform), -1);
    xmlSecAssert2(nodes != NULL, -1);
    xmlSecAssert2(nodes->doc != NULL, -1);
    xmlSecAssert2(transformCtx != NULL, -1);

    /* check/update current transform status */
    switch(transform->status) {
    case xmlSecTransformStatusNone:
        transform->status = xmlSecTransformStatusWorking;
        break;
    case xmlSecTransformStatusWorking:
    case xmlSecTransformStatusFinished:
        return(0);
    default:
        xmlSecError(XMLSEC_ERRORS_HERE,
                    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                    NULL,
                    XMLSEC_ERRORS_R_INVALID_STATUS,
                    "status=%d", transform->status);
        return(-1);
    }
    xmlSecAssert2(transform->status == xmlSecTransformStatusWorking, -1);

    /* prepare output buffer: next transform or ourselves */
    if(transform->next != NULL) {
        buf = xmlSecTransformCreateOutputBuffer(transform->next, transformCtx);
        if(buf == NULL) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        "xmlSecTransformCreateOutputBuffer",
                        XMLSEC_ERRORS_R_XMLSEC_FAILED,
                        XMLSEC_ERRORS_NO_MESSAGE);
            return(-1);
        }
    } else {
        buf = xmlSecBufferCreateOutputBuffer(&(transform->outBuf));
        if(buf == NULL) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        "xmlSecBufferCreateOutputBuffer",
                        XMLSEC_ERRORS_R_XMLSEC_FAILED,
                        XMLSEC_ERRORS_NO_MESSAGE);
            return(-1);
        }
    }

    /* we are using a semi-hack here: we know that xmlSecPtrList keeps
     * all pointers in the big array */
    nsList = xmlSecTransformC14NGetNsList(transform);
    xmlSecAssert2(xmlSecPtrListCheckId(nsList, xmlSecStringListId), -1);

    ret = xmlSecTransformC14NExecute(transform->id, nodes, (xmlChar**)(nsList->data), buf);
    if(ret < 0) {
        xmlSecError(XMLSEC_ERRORS_HERE,
                    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                    "xmlSecTransformC14NExecute",
                    XMLSEC_ERRORS_R_XMLSEC_FAILED,
                    XMLSEC_ERRORS_NO_MESSAGE);
        xmlOutputBufferClose(buf);
        return(-1);
    }

    ret = xmlOutputBufferClose(buf);
    if(ret < 0) {
        xmlSecError(XMLSEC_ERRORS_HERE,
                    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                    "xmlOutputBufferClose",
                    XMLSEC_ERRORS_R_XML_FAILED,
                    XMLSEC_ERRORS_NO_MESSAGE);
        return(-1);
    }
    transform->status = xmlSecTransformStatusFinished;
    return(0);
}

static int
xmlSecTransformC14NPopBin(xmlSecTransformPtr transform, xmlSecByte* data,
                            xmlSecSize maxDataSize, xmlSecSize* dataSize,
                            xmlSecTransformCtxPtr transformCtx) {
    xmlSecPtrListPtr nsList;
    xmlSecBufferPtr out;
    int ret;

    xmlSecAssert2(xmlSecTransformC14NCheckId(transform), -1);
    xmlSecAssert2(data != NULL, -1);
    xmlSecAssert2(dataSize != NULL, -1);
    xmlSecAssert2(transformCtx != NULL, -1);

    out = &(transform->outBuf);
    if(transform->status == xmlSecTransformStatusNone) {
        xmlOutputBufferPtr buf;

        xmlSecAssert2(transform->inNodes == NULL, -1);

        /* todo: isn't it an error? */
        if(transform->prev == NULL) {
            (*dataSize) = 0;
            transform->status = xmlSecTransformStatusFinished;
            return(0);
        }

        /* get xml data from previous transform */
        ret = xmlSecTransformPopXml(transform->prev, &(transform->inNodes), transformCtx);
        if(ret < 0) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        "xmlSecTransformPopXml",
                        XMLSEC_ERRORS_R_XMLSEC_FAILED,
                        XMLSEC_ERRORS_NO_MESSAGE);
            return(-1);
        }

        /* dump everything to internal buffer */
        buf = xmlSecBufferCreateOutputBuffer(out);
        if(buf == NULL) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        "xmlSecBufferCreateOutputBuffer",
                        XMLSEC_ERRORS_R_XMLSEC_FAILED,
                        XMLSEC_ERRORS_NO_MESSAGE);
            return(-1);
        }

        /* we are using a semi-hack here: we know that xmlSecPtrList keeps
         * all pointers in the big array */
        nsList = xmlSecTransformC14NGetNsList(transform);
        xmlSecAssert2(xmlSecPtrListCheckId(nsList, xmlSecStringListId), -1);

        ret = xmlSecTransformC14NExecute(transform->id, transform->inNodes, (xmlChar**)(nsList->data), buf);
        if(ret < 0) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        "xmlSecTransformC14NExecute",
                        XMLSEC_ERRORS_R_XMLSEC_FAILED,
                        XMLSEC_ERRORS_NO_MESSAGE);
            xmlOutputBufferClose(buf);
            return(-1);
        }
        ret = xmlOutputBufferClose(buf);
        if(ret < 0) {
            xmlSecError(XMLSEC_ERRORS_HERE,
                        xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                        "xmlOutputBufferClose",
                        XMLSEC_ERRORS_R_XML_FAILED,
                        XMLSEC_ERRORS_NO_MESSAGE);
            return(-1);
        }
        transform->status = xmlSecTransformStatusWorking;
    }

    if(transform->status == xmlSecTransformStatusWorking) {
        xmlSecSize outSize;

        /* return chunk after chunk */
        outSize = xmlSecBufferGetSize(out);
        if(outSize > maxDataSize) {
            outSize = maxDataSize;
        }
        if(outSize > XMLSEC_TRANSFORM_BINARY_CHUNK) {
            outSize = XMLSEC_TRANSFORM_BINARY_CHUNK;
        }
        if(outSize > 0) {
            xmlSecAssert2(xmlSecBufferGetData(&(transform->outBuf)), -1);

            memcpy(data, xmlSecBufferGetData(&(transform->outBuf)), outSize);
            ret = xmlSecBufferRemoveHead(&(transform->outBuf), outSize);
            if(ret < 0) {
                xmlSecError(XMLSEC_ERRORS_HERE,
                            xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                            "xmlSecBufferRemoveHead",
                            XMLSEC_ERRORS_R_XMLSEC_FAILED,
                            "size=%d", outSize);
                return(-1);
            }
        } else if(xmlSecBufferGetSize(out) == 0) {
            transform->status = xmlSecTransformStatusFinished;
        }
        (*dataSize) = outSize;
    } else if(transform->status == xmlSecTransformStatusFinished) {
        /* the only way we can get here is if there is no output */
        xmlSecAssert2(xmlSecBufferGetSize(out) == 0, -1);
        (*dataSize) = 0;
    } else {
        xmlSecError(XMLSEC_ERRORS_HERE,
                    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                    NULL,
                    XMLSEC_ERRORS_R_INVALID_STATUS,
                    "status=%d", transform->status);
        return(-1);
    }

    return(0);
}

static int
xmlSecTransformC14NExecute(xmlSecTransformId id, xmlSecNodeSetPtr nodes, xmlChar** nsList,
                           xmlOutputBufferPtr buf) {
    int ret;

    xmlSecAssert2(id != xmlSecTransformIdUnknown, -1);
    xmlSecAssert2(nodes != NULL, -1);
    xmlSecAssert2(nodes->doc != NULL, -1);
    xmlSecAssert2(buf != NULL, -1);

    /* execute c14n transform */
    if(id == xmlSecTransformInclC14NId) {
        ret = xmlC14NExecute(nodes->doc,
                        (xmlC14NIsVisibleCallback)xmlSecNodeSetContains,
                        nodes, XML_C14N_1_0, NULL, 0, buf);
    } else if(id == xmlSecTransformInclC14NWithCommentsId) {
         ret = xmlC14NExecute(nodes->doc,
                        (xmlC14NIsVisibleCallback)xmlSecNodeSetContains,
                        nodes, XML_C14N_1_0, NULL, 1, buf);
    } else if(id == xmlSecTransformInclC14N11Id) {
        ret = xmlC14NExecute(nodes->doc,
                        (xmlC14NIsVisibleCallback)xmlSecNodeSetContains,
                        nodes, XML_C14N_1_1, NULL, 0, buf);
    } else if(id == xmlSecTransformInclC14N11WithCommentsId) {
         ret = xmlC14NExecute(nodes->doc,
                        (xmlC14NIsVisibleCallback)xmlSecNodeSetContains,
                        nodes, XML_C14N_1_1, NULL, 1, buf);
    } else if(id == xmlSecTransformExclC14NId) {
        ret = xmlC14NExecute(nodes->doc,
                        (xmlC14NIsVisibleCallback)xmlSecNodeSetContains,
                        nodes, XML_C14N_EXCLUSIVE_1_0, nsList, 0, buf);
    } else if(id == xmlSecTransformExclC14NWithCommentsId) {
        ret = xmlC14NExecute(nodes->doc,
                        (xmlC14NIsVisibleCallback)xmlSecNodeSetContains,
                        nodes, XML_C14N_EXCLUSIVE_1_0, nsList, 1, buf);
    } else if(id == xmlSecTransformRemoveXmlTagsC14NId) {
        ret = xmlSecNodeSetDumpTextNodes(nodes, buf);
    } else {
        /* shoudn't be possible to come here, actually */
        xmlSecError(XMLSEC_ERRORS_HERE,
                    xmlSecErrorsSafeString(xmlSecTransformKlassGetName(id)),
                    NULL,
                    XMLSEC_ERRORS_R_INVALID_TRANSFORM,
                    XMLSEC_ERRORS_NO_MESSAGE);
        return(-1);
    }

    if(ret < 0) {
        xmlSecError(XMLSEC_ERRORS_HERE,
                    xmlSecErrorsSafeString(xmlSecTransformKlassGetName(id)),
                    "xmlC14NExecute",
                    XMLSEC_ERRORS_R_XML_FAILED,
                    XMLSEC_ERRORS_NO_MESSAGE);
        return(-1);
    }

    return(0);
}

/***************************************************************************
 *
 * C14N
 *
 ***************************************************************************/
static xmlSecTransformKlass xmlSecTransformInclC14NKlass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),               /* xmlSecSize klassSize */
    xmlSecTransformC14NSize,                    /* xmlSecSize objSize */

    xmlSecNameC14N,                             /* const xmlChar* name; */
    xmlSecHrefC14N,                             /* const xmlChar* href; */
    xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform,
                                                /* xmlSecAlgorithmUsage usage; */

    xmlSecTransformC14NInitialize,              /* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformC14NFinalize,                /* xmlSecTransformFinalizeMethod finalize; */
    NULL,                                       /* xmlSecTransformNodeReadMethod readNode; */
    NULL,                                       /* xmlSecTransformNodeWriteMethod writeNode; */
    NULL,                                       /* xmlSecTransformSetKeyReqMethod setKeyReq; */
    NULL,                                       /* xmlSecTransformSetKeyMethod setKey; */
    NULL,                                       /* xmlSecTransformValidateMethod validate; */
    xmlSecTransformDefaultGetDataType,          /* xmlSecTransformGetDataTypeMethod getDataType; */
    NULL,                                       /* xmlSecTransformPushBinMethod pushBin; */
    xmlSecTransformC14NPopBin,                  /* xmlSecTransformPopBinMethod popBin; */
    xmlSecTransformC14NPushXml,                 /* xmlSecTransformPushXmlMethod pushXml; */
    NULL,                                       /* xmlSecTransformPopXmlMethod popXml; */
    NULL,                                       /* xmlSecTransformExecuteMethod execute; */

    NULL,                                       /* void* reserved0; */
    NULL,                                       /* void* reserved1; */
};

/**
 * xmlSecTransformInclC14NGetKlass:
 *
 * Inclusive (regular) canonicalization that omits comments transform klass
 * (http://www.w3.org/TR/xmldsig-core/#sec-c14nAlg and
 * http://www.w3.org/TR/2001/REC-xml-c14n-20010315).
 *
 * Returns: c14n transform id.
 */
xmlSecTransformId
xmlSecTransformInclC14NGetKlass(void) {
    return(&xmlSecTransformInclC14NKlass);
}

/***************************************************************************
 *
 * C14N With Comments
 *
 ***************************************************************************/
static xmlSecTransformKlass xmlSecTransformInclC14NWithCommentsKlass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),               /* xmlSecSize klassSize */
    xmlSecTransformC14NSize,                    /* xmlSecSize objSize */

    /* same as xmlSecTransformId */
    xmlSecNameC14NWithComments,                 /* const xmlChar* name; */
    xmlSecHrefC14NWithComments,                 /* const xmlChar* href; */
    xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform,
                                                /* xmlSecAlgorithmUsage usage; */

    xmlSecTransformC14NInitialize,              /* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformC14NFinalize,                /* xmlSecTransformFinalizeMethod finalize; */
    NULL,                                       /* xmlSecTransformNodeReadMethod read; */
    NULL,                                       /* xmlSecTransformNodeWriteMethod writeNode; */
    NULL,                                       /* xmlSecTransformSetKeyReqMethod setKeyReq; */
    NULL,                                       /* xmlSecTransformSetKeyMethod setKey; */
    NULL,                                       /* xmlSecTransformValidateMethod validate; */
    xmlSecTransformDefaultGetDataType,          /* xmlSecTransformGetDataTypeMethod getDataType; */
    NULL,                                       /* xmlSecTransformPushBinMethod pushBin; */
    xmlSecTransformC14NPopBin,                  /* xmlSecTransformPopBinMethod popBin; */
    xmlSecTransformC14NPushXml,                 /* xmlSecTransformPushXmlMethod pushXml; */
    NULL,                                       /* xmlSecTransformPopXmlMethod popXml; */
    NULL,                                       /* xmlSecTransformExecuteMethod execute; */

    NULL,                                       /* void* reserved0; */
    NULL,                                       /* void* reserved1; */
};

/**
 * xmlSecTransformInclC14NWithCommentsGetKlass:
 *
 * Inclusive (regular) canonicalization that includes comments transform klass
 * (http://www.w3.org/TR/xmldsig-core/#sec-c14nAlg and
 * http://www.w3.org/TR/2001/REC-xml-c14n-20010315).
 *
 * Returns: c14n with comments transform id.
 */
xmlSecTransformId
xmlSecTransformInclC14NWithCommentsGetKlass(void) {
    return(&xmlSecTransformInclC14NWithCommentsKlass);
}

/***************************************************************************
 *
 * C14N v1.1
 *
 ***************************************************************************/
static xmlSecTransformKlass xmlSecTransformInclC14N11Klass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),               /* xmlSecSize klassSize */
    xmlSecTransformC14NSize,                    /* xmlSecSize objSize */

    xmlSecNameC14N11,                           /* const xmlChar* name; */
    xmlSecHrefC14N11,                           /* const xmlChar* href; */
    xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform,
                                                /* xmlSecAlgorithmUsage usage; */

    xmlSecTransformC14NInitialize,              /* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformC14NFinalize,                /* xmlSecTransformFinalizeMethod finalize; */
    NULL,                                       /* xmlSecTransformNodeReadMethod readNode; */
    NULL,                                       /* xmlSecTransformNodeWriteMethod writeNode; */
    NULL,                                       /* xmlSecTransformSetKeyReqMethod setKeyReq; */
    NULL,                                       /* xmlSecTransformSetKeyMethod setKey; */
    NULL,                                       /* xmlSecTransformValidateMethod validate; */
    xmlSecTransformDefaultGetDataType,          /* xmlSecTransformGetDataTypeMethod getDataType; */
    NULL,                                       /* xmlSecTransformPushBinMethod pushBin; */
    xmlSecTransformC14NPopBin,                  /* xmlSecTransformPopBinMethod popBin; */
    xmlSecTransformC14NPushXml,                 /* xmlSecTransformPushXmlMethod pushXml; */
    NULL,                                       /* xmlSecTransformPopXmlMethod popXml; */
    NULL,                                       /* xmlSecTransformExecuteMethod execute; */

    NULL,                                       /* void* reserved0; */
    NULL,                                       /* void* reserved1; */
};

/**
 * xmlSecTransformInclC14N11GetKlass:
 *
 * C14N version 1.1 (http://www.w3.org/TR/xml-c14n11)
 *
 * Returns: c14n v1.1 transform id.
 */
xmlSecTransformId
xmlSecTransformInclC14N11GetKlass(void) {
    return(&xmlSecTransformInclC14N11Klass);
}

/***************************************************************************
 *
 * C14N v1.1 With Comments
 *
 ***************************************************************************/
static xmlSecTransformKlass xmlSecTransformInclC14N11WithCommentsKlass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),               /* xmlSecSize klassSize */
    xmlSecTransformC14NSize,                    /* xmlSecSize objSize */

    /* same as xmlSecTransformId */
    xmlSecNameC14N11WithComments,               /* const xmlChar* name; */
    xmlSecHrefC14N11WithComments,               /* const xmlChar* href; */
    xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform,
                                                /* xmlSecAlgorithmUsage usage; */

    xmlSecTransformC14NInitialize,              /* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformC14NFinalize,                /* xmlSecTransformFinalizeMethod finalize; */
    NULL,                                       /* xmlSecTransformNodeReadMethod read; */
    NULL,                                       /* xmlSecTransformNodeWriteMethod writeNode; */
    NULL,                                       /* xmlSecTransformSetKeyReqMethod setKeyReq; */
    NULL,                                       /* xmlSecTransformSetKeyMethod setKey; */
    NULL,                                       /* xmlSecTransformValidateMethod validate; */
    xmlSecTransformDefaultGetDataType,          /* xmlSecTransformGetDataTypeMethod getDataType; */
    NULL,                                       /* xmlSecTransformPushBinMethod pushBin; */
    xmlSecTransformC14NPopBin,                  /* xmlSecTransformPopBinMethod popBin; */
    xmlSecTransformC14NPushXml,                 /* xmlSecTransformPushXmlMethod pushXml; */
    NULL,                                       /* xmlSecTransformPopXmlMethod popXml; */
    NULL,                                       /* xmlSecTransformExecuteMethod execute; */

    NULL,                                       /* void* reserved0; */
    NULL,                                       /* void* reserved1; */
};

/**
 * xmlSecTransformInclC14N11WithCommentsGetKlass:
 *
 * C14N version 1.1 (http://www.w3.org/TR/xml-c14n11) with comments
 *
 * Returns: c14n v1.1 with comments transform id.
 */
xmlSecTransformId
xmlSecTransformInclC14N11WithCommentsGetKlass(void) {
    return(&xmlSecTransformInclC14N11WithCommentsKlass);
}


/***************************************************************************
 *
 * Excl C14N
 *
 ***************************************************************************/
static xmlSecTransformKlass xmlSecTransformExclC14NKlass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),               /* xmlSecSize klassSize */
    xmlSecTransformC14NSize,                    /* xmlSecSize objSize */

    xmlSecNameExcC14N,                          /* const xmlChar* name; */
    xmlSecHrefExcC14N,                          /* const xmlChar* href; */
    xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform,
                                                /* xmlSecAlgorithmUsage usage; */

    xmlSecTransformC14NInitialize,              /* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformC14NFinalize,                /* xmlSecTransformFinalizeMethod finalize; */
    xmlSecTransformC14NNodeRead,                /* xmlSecTransformNodeReadMethod readNode; */
    NULL,                                       /* xmlSecTransformNodeWriteMethod writeNode; */
    NULL,                                       /* xmlSecTransformSetKeyReqMethod setKeyReq; */
    NULL,                                       /* xmlSecTransformSetKeyMethod setKey; */
    NULL,                                       /* xmlSecTransformValidateMethod validate; */
    xmlSecTransformDefaultGetDataType,          /* xmlSecTransformGetDataTypeMethod getDataType; */
    NULL,                                       /* xmlSecTransformPushBinMethod pushBin; */
    xmlSecTransformC14NPopBin,                  /* xmlSecTransformPopBinMethod popBin; */
    xmlSecTransformC14NPushXml,                 /* xmlSecTransformPushXmlMethod pushXml; */
    NULL,                                       /* xmlSecTransformPopXmlMethod popXml; */
    NULL,                                       /* xmlSecTransformExecuteMethod execute; */

    NULL,                                       /* void* reserved0; */
    NULL,                                       /* void* reserved1; */
};

/**
 * xmlSecTransformExclC14NGetKlass:
 *
 * Exclusive canoncicalization that ommits comments transform klass
 * (http://www.w3.org/TR/xml-exc-c14n/).
 *
 * Returns: exclusive c14n transform id.
 */
xmlSecTransformId
xmlSecTransformExclC14NGetKlass(void) {
    return(&xmlSecTransformExclC14NKlass);
}

/***************************************************************************
 *
 * Excl C14N With Comments
 *
 ***************************************************************************/
static xmlSecTransformKlass xmlSecTransformExclC14NWithCommentsKlass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),               /* xmlSecSize klassSize */
    xmlSecTransformC14NSize,                    /* xmlSecSize objSize */

    xmlSecNameExcC14NWithComments,              /* const xmlChar* name; */
    xmlSecHrefExcC14NWithComments,              /* const xmlChar* href; */
    xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform,
                                                /* xmlSecAlgorithmUsage usage; */

    xmlSecTransformC14NInitialize,              /* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformC14NFinalize,                /* xmlSecTransformFinalizeMethod finalize; */
    xmlSecTransformC14NNodeRead,                /* xmlSecTransformNodeReadMethod readNode; */
    NULL,                                       /* xmlSecTransformNodeWriteMethod writeNode; */
    NULL,                                       /* xmlSecTransformSetKeyReqMethod setKeyReq; */
    NULL,                                       /* xmlSecTransformSetKeyMethod setKey; */
    NULL,                                       /* xmlSecTransformValidateMethod validate; */
    xmlSecTransformDefaultGetDataType,          /* xmlSecTransformGetDataTypeMethod getDataType; */
    NULL,                                       /* xmlSecTransformPushBinMethod pushBin; */
    xmlSecTransformC14NPopBin,                  /* xmlSecTransformPopBinMethod popBin; */
    xmlSecTransformC14NPushXml,                 /* xmlSecTransformPushXmlMethod pushXml; */
    NULL,                                       /* xmlSecTransformPopXmlMethod popXml; */
    NULL,                                       /* xmlSecTransformExecuteMethod execute; */

    NULL,                                       /* void* reserved0; */
    NULL,                                       /* void* reserved1; */
};

/**
 * xmlSecTransformExclC14NWithCommentsGetKlass:
 *
 * Exclusive canoncicalization that includes comments transform klass
 * (http://www.w3.org/TR/xml-exc-c14n/).
 *
 * Returns: exclusive c14n with comments transform id.
 */
xmlSecTransformId
xmlSecTransformExclC14NWithCommentsGetKlass(void) {
    return(&xmlSecTransformExclC14NWithCommentsKlass);
}

/***************************************************************************
 *
 * Remove XML tags C14N
 *
 ***************************************************************************/
static xmlSecTransformKlass xmlSecTransformRemoveXmlTagsC14NKlass = {
    /* klass/object sizes */
    sizeof(xmlSecTransformKlass),               /* xmlSecSize klassSize */
    xmlSecTransformC14NSize,                    /* xmlSecSize objSize */

    BAD_CAST "remove-xml-tags-transform",       /* const xmlChar* name; */
    NULL,                                       /* const xmlChar* href; */
    xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform,
                                                /* xmlSecAlgorithmUsage usage; */

    xmlSecTransformC14NInitialize,              /* xmlSecTransformInitializeMethod initialize; */
    xmlSecTransformC14NFinalize,                /* xmlSecTransformFinalizeMethod finalize; */
    NULL,                                       /* xmlSecTransformNodeReadMethod readNode; */
    NULL,                                       /* xmlSecTransformNodeWriteMethod writeNode; */
    NULL,                                       /* xmlSecTransformSetKeyReqMethod setKeyReq; */
    NULL,                                       /* xmlSecTransformSetKeyMethod setKey; */
    NULL,                                       /* xmlSecTransformValidateMethod validate; */
    xmlSecTransformDefaultGetDataType,          /* xmlSecTransformGetDataTypeMethod getDataType; */
    NULL,                                       /* xmlSecTransformPushBinMethod pushBin; */
    xmlSecTransformC14NPopBin,                  /* xmlSecTransformPopBinMethod popBin; */
    xmlSecTransformC14NPushXml,                 /* xmlSecTransformPushXmlMethod pushXml; */
    NULL,                                       /* xmlSecTransformPopXmlMethod popXml; */
    NULL,                                       /* xmlSecTransformExecuteMethod execute; */

    NULL,                                       /* void* reserved0; */
    NULL,                                       /* void* reserved1; */
};

/**
 * xmlSecTransformRemoveXmlTagsC14NGetKlass:
 *
 * The "remove xml tags" transform klass (http://www.w3.org/TR/xmldsig-core/#sec-Base-64):
 * Base64 transform requires an octet stream for input. If an XPath node-set
 * (or sufficiently functional alternative) is given as input, then it is
 * converted to an octet stream by performing operations logically equivalent
 * to 1) applying an XPath transform with expression self::text(), then 2)
 * taking the string-value of the node-set. Thus, if an XML element is
 * identified by a barename XPointer in the Reference URI, and its content
 * consists solely of base64 encoded character data, then this transform
 * automatically strips away the start and end tags of the identified element
 * and any of its descendant elements as well as any descendant comments and
 * processing instructions. The output of this transform is an octet stream.
 *
 * Returns: "remove xml tags" transform id.
 */
xmlSecTransformId
xmlSecTransformRemoveXmlTagsC14NGetKlass(void) {
    return(&xmlSecTransformRemoveXmlTagsC14NKlass);
}