2 * XML Security Library (http://www.aleksey.com/xmlsec).
6 * This is free software; see Copyright file in the source
7 * distribution for preciese wording.
9 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com>
10 * Copyrigth (C) 2003 Cordys R&D BV, All rights reserved.
18 #include <libxml/tree.h>
20 #include <xmlsec/xmlsec.h>
21 #include <xmlsec/xmltree.h>
22 #include <xmlsec/base64.h>
23 #include <xmlsec/bn.h>
24 #include <xmlsec/errors.h>
26 /* table for converting hex digits back to bytes */
27 static const int xmlSecBnLookupTable[] =
29 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
30 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
31 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
32 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
33 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
34 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
35 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
37 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
38 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
39 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
40 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
47 static const char xmlSecBnRevLookupTable[] =
49 '0', '1', '2', '3', '4', '5', '6', '7',
50 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
53 /*****************************************************************************
57 ****************************************************************************/
60 * @size: the initial allocated BN size.
62 * Creates a new BN object. Caller is responsible for destroying it
63 * by calling @xmlSecBnDestroy function.
65 * Returns: the newly BN or a NULL if an error occurs.
68 xmlSecBnCreate(xmlSecSize size) {
69 return(xmlSecBufferCreate(size));
74 * @bn: the pointer to BN.
76 * Destroys @bn object created with @xmlSecBnCreate function.
79 xmlSecBnDestroy(xmlSecBnPtr bn) {
80 xmlSecBufferDestroy(bn);
85 * @bn: the pointer to BN.
86 * @size: the initial allocated BN size.
88 * Initializes a BN object. Caller is responsible for destroying it
89 * by calling @xmlSecBnFinalize function.
91 * Returns: 0 on success or a negative value if an error occurs.
94 xmlSecBnInitialize(xmlSecBnPtr bn, xmlSecSize size) {
95 return(xmlSecBufferInitialize(bn, size));
100 * @bn: the pointer to BN.
102 * Destroys @bn object created with @xmlSecBnInitialize function.
105 xmlSecBnFinalize(xmlSecBnPtr bn) {
106 xmlSecBufferFinalize(bn);
111 * @bn: the pointer to BN.
113 * Gets pointer to the binary @bn representation.
115 * Returns: pointer to binary BN data or NULL if an error occurs.
118 xmlSecBnGetData(xmlSecBnPtr bn) {
119 return(xmlSecBufferGetData(bn));
124 * @bn: the pointer to BN.
125 * @data: the pointer to new BN binary data.
126 * @size: the size of new BN data.
128 * Sets the value of @bn to @data.
130 * Returns: 0 on success or a negative value if an error occurs.
133 xmlSecBnSetData(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize size) {
134 return(xmlSecBufferSetData(bn, data, size));
139 * @bn: the pointer to BN.
141 * Gets the size of binary data in @bn.
143 * Returns: the size of binary data.
146 xmlSecBnGetSize(xmlSecBnPtr bn) {
147 return(xmlSecBufferGetSize(bn));
152 * @bn: the pointer to BN.
154 * Sets the value of @bn to zero.
157 xmlSecBnZero(xmlSecBnPtr bn) {
158 xmlSecBufferEmpty(bn);
162 * xmlSecBnFromString:
163 * @bn: the pointer to BN.
164 * @str: the string with BN.
165 * @base: the base for @str.
167 * Reads @bn from string @str assuming it has base @base.
169 * Returns: 0 on success or a negative value if an error occurs.
172 xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) {
173 xmlSecSize i, len, size;
180 xmlSecAssert2(bn != NULL, -1);
181 xmlSecAssert2(str != NULL, -1);
182 xmlSecAssert2(base > 1, -1);
183 xmlSecAssert2(base <= sizeof(xmlSecBnRevLookupTable), -1);
186 len = xmlStrlen(str);
191 /* The result size could not exceed the input string length
192 * because each char fits inside a byte in all cases :)
193 * In truth, it would be likely less than 1/2 input string length
194 * because each byte is represented by 2 chars. If needed,
195 * buffer size would be increased by Mul/Add functions.
196 * Finally, we can add one byte for 00 or 10 prefix.
198 ret = xmlSecBufferSetMaxSize(bn, xmlSecBufferGetSize(bn) + len / 2 + 1 + 1);
200 xmlSecError(XMLSEC_ERRORS_HERE,
202 "xmlSecBnRevLookupTable",
203 XMLSEC_ERRORS_R_XMLSEC_FAILED,
204 "size=%d", len / 2 + 1);
208 /* figure out if it is positive or negative number */
219 /* check if it is + or - */
223 } else if(ch == '-') {
228 /* otherwise, it must be start of the number */
229 nn = xmlSecBnLookupTable[ch];
230 if((nn >= 0) && ((xmlSecSize)nn < base)) {
231 xmlSecAssert2(i > 0, -1);
233 /* no sign, positive by default */
235 --i; /* make sure that we will look at this character in next loop */
238 xmlSecError(XMLSEC_ERRORS_HERE,
241 XMLSEC_ERRORS_R_INVALID_DATA,
248 /* now parse the number itself */
255 xmlSecAssert2(ch <= sizeof(xmlSecBnLookupTable), -1);
256 nn = xmlSecBnLookupTable[ch];
257 if((nn < 0) || ((xmlSecSize)nn > base)) {
258 xmlSecError(XMLSEC_ERRORS_HERE,
261 XMLSEC_ERRORS_R_INVALID_DATA,
267 ret = xmlSecBnMul(bn, base);
269 xmlSecError(XMLSEC_ERRORS_HERE,
272 XMLSEC_ERRORS_R_XMLSEC_FAILED,
277 ret = xmlSecBnAdd(bn, nn);
279 xmlSecError(XMLSEC_ERRORS_HERE,
282 XMLSEC_ERRORS_R_XMLSEC_FAILED,
288 /* check if we need to add 00 prefix, do this for empty bn too */
289 data = xmlSecBufferGetData(bn);
290 size = xmlSecBufferGetSize(bn);
291 if(((size > 0) && (data[0] > 127)) || (size == 0)) {
293 ret = xmlSecBufferPrepend(bn, &ch, 1);
295 xmlSecError(XMLSEC_ERRORS_HERE,
297 "xmlSecBufferPrepend",
298 XMLSEC_ERRORS_R_XMLSEC_FAILED,
304 /* do 2's compliment and add 1 to represent negative value */
306 data = xmlSecBufferGetData(bn);
307 size = xmlSecBufferGetSize(bn);
308 for(i = 0; i < size; ++i) {
312 ret = xmlSecBnAdd(bn, 1);
314 xmlSecError(XMLSEC_ERRORS_HERE,
317 XMLSEC_ERRORS_R_XMLSEC_FAILED,
328 * @bn: the pointer to BN.
329 * @base: the base for returned string.
331 * Writes @bn to string with base @base. Caller is responsible for
332 * freeing returned string with @xmlFree.
334 * Returns: the string represenataion if BN or a NULL if an error occurs.
337 xmlSecBnToString(xmlSecBnPtr bn, xmlSecSize base) {
341 xmlSecSize i, len, size;
347 xmlSecAssert2(bn != NULL, NULL);
348 xmlSecAssert2(base > 1, NULL);
349 xmlSecAssert2(base <= sizeof(xmlSecBnRevLookupTable), NULL);
353 data = xmlSecBufferGetData(bn);
354 size = xmlSecBufferGetSize(bn);
355 ret = xmlSecBnInitialize(&bn2, size);
357 xmlSecError(XMLSEC_ERRORS_HERE,
360 XMLSEC_ERRORS_R_XMLSEC_FAILED,
365 ret = xmlSecBnSetData(&bn2, data, size);
367 xmlSecError(XMLSEC_ERRORS_HERE,
370 XMLSEC_ERRORS_R_XMLSEC_FAILED,
372 xmlSecBnFinalize(&bn2);
376 /* check if it is a negative number or not */
377 data = xmlSecBufferGetData(&bn2);
378 size = xmlSecBufferGetSize(&bn2);
379 if((size > 0) && (data[0] > 127)) {
380 /* subtract 1 and do 2's compliment */
381 ret = xmlSecBnAdd(&bn2, -1);
383 xmlSecError(XMLSEC_ERRORS_HERE,
386 XMLSEC_ERRORS_R_XMLSEC_FAILED,
388 xmlSecBnFinalize(&bn2);
391 for(i = 0; i < size; ++i) {
400 /* Result string len is
401 * len = log base (256) * <bn size>
402 * Since the smallest base == 2 then we can get away with
403 * len = 8 * <bn size>
405 len = 8 * size + 1 + 1;
406 res = (xmlChar*)xmlMalloc(len + 1);
408 xmlSecError(XMLSEC_ERRORS_HERE,
411 XMLSEC_ERRORS_R_MALLOC_FAILED,
413 xmlSecBnFinalize(&bn2);
416 memset(res, 0, len + 1);
418 for(i = 0; (xmlSecBufferGetSize(&bn2) > 0) && (i < len); i++) {
419 if(xmlSecBnDiv(&bn2, base, &nn) < 0) {
420 xmlSecError(XMLSEC_ERRORS_HERE,
423 XMLSEC_ERRORS_R_XMLSEC_FAILED,
426 xmlSecBnFinalize(&bn2);
429 xmlSecAssert2((size_t)nn < sizeof(xmlSecBnRevLookupTable), NULL);
430 res[i] = xmlSecBnRevLookupTable[nn];
432 xmlSecAssert2(i < len, NULL);
434 /* we might have '0' at the beggining, remove it but keep one zero */
435 for(len = i; (len > 1) && (res[len - 1] == '0'); len--);
438 /* add "-" for negative numbers */
444 /* swap the string because we wrote it in reverse order */
445 for(i = 0; i < len / 2; i++) {
447 res[i] = res[len - i - 1];
448 res[len - i - 1] = ch;
451 xmlSecBnFinalize(&bn2);
456 * xmlSecBnFromHexString:
457 * @bn: the pointer to BN.
458 * @str: the string with BN.
460 * Reads @bn from hex string @str.
462 * Returns: 0 on success or a negative value if an error occurs.
465 xmlSecBnFromHexString(xmlSecBnPtr bn, const xmlChar* str) {
466 return(xmlSecBnFromString(bn, str, 16));
470 * xmlSecBnToHexString:
471 * @bn: the pointer to BN.
473 * Writes @bn to hex string. Caller is responsible for
474 * freeing returned string with @xmlFree.
476 * Returns: the string represenataion if BN or a NULL if an error occurs.
479 xmlSecBnToHexString(xmlSecBnPtr bn) {
480 return(xmlSecBnToString(bn, 16));
484 * xmlSecBnFromDecString:
485 * @bn: the pointer to BN.
486 * @str: the string with BN.
488 * Reads @bn from decimal string @str.
490 * Returns: 0 on success or a negative value if an error occurs.
493 xmlSecBnFromDecString(xmlSecBnPtr bn, const xmlChar* str) {
494 return(xmlSecBnFromString(bn, str, 10));
498 * xmlSecBnToDecString:
499 * @bn: the pointer to BN.
501 * Writes @bn to decimal string. Caller is responsible for
502 * freeing returned string with @xmlFree.
504 * Returns: the string represenataion if BN or a NULL if an error occurs.
507 xmlSecBnToDecString(xmlSecBnPtr bn) {
508 return(xmlSecBnToString(bn, 10));
513 * @bn: the pointer to BN.
514 * @multiplier: the multiplier.
516 * Multiplies @bn with @multiplier.
518 * Returns: 0 on success or a negative value if an error occurs.
521 xmlSecBnMul(xmlSecBnPtr bn, int multiplier) {
528 xmlSecAssert2(bn != NULL, -1);
529 xmlSecAssert2(multiplier > 0, -1);
531 if(multiplier == 1) {
535 data = xmlSecBufferGetData(bn);
536 i = xmlSecBufferGetSize(bn);
539 xmlSecAssert2(data != NULL, -1);
541 over = over + multiplier * data[--i];
542 data[i] = over % 256;
550 ret = xmlSecBufferPrepend(bn, &ch, 1);
552 xmlSecError(XMLSEC_ERRORS_HERE,
554 "xmlSecBufferPrepend",
555 XMLSEC_ERRORS_R_XMLSEC_FAILED,
566 * @bn: the pointer to BN.
567 * @divider: the divider
568 * @mod: the pointer for modulus result.
570 * Divides @bn by @divider and places modulus into @mod.
572 * Returns: 0 on success or a negative value if an error occurs.
575 xmlSecBnDiv(xmlSecBnPtr bn, int divider, int* mod) {
581 xmlSecAssert2(bn != NULL, -1);
582 xmlSecAssert2(divider > 0, -1);
583 xmlSecAssert2(mod != NULL, -1);
589 data = xmlSecBufferGetData(bn);
590 size = xmlSecBufferGetSize(bn);
591 for(over = 0, i = 0; i < size; i++) {
592 xmlSecAssert2(data != NULL, -1);
594 over = over * 256 + data[i];
595 data[i] = over / divider;
596 over = over % divider;
600 /* remove leading zeros */
601 for(i = 0; i < size; i++) {
602 xmlSecAssert2(data != NULL, -1);
609 ret = xmlSecBufferRemoveHead(bn, i);
611 xmlSecError(XMLSEC_ERRORS_HERE,
613 "xmlSecBufferRemoveHead",
614 XMLSEC_ERRORS_R_XMLSEC_FAILED,
624 * @bn: the pointer to BN.
627 * Adds @delta to @bn.
629 * Returns: 0 on success or a negative value if an error occurs.
632 xmlSecBnAdd(xmlSecBnPtr bn, int delta) {
639 xmlSecAssert2(bn != NULL, -1);
645 data = xmlSecBufferGetData(bn);
647 for(over = delta, i = xmlSecBufferGetSize(bn); (i > 0) && (over > 0) ;) {
648 xmlSecAssert2(data != NULL, -1);
652 data[i] = over % 256;
660 ret = xmlSecBufferPrepend(bn, &ch, 1);
662 xmlSecError(XMLSEC_ERRORS_HERE,
664 "xmlSecBufferPrepend",
665 XMLSEC_ERRORS_R_XMLSEC_FAILED,
671 for(over = -delta, i = xmlSecBufferGetSize(bn); (i > 0) && (over > 0);) {
672 xmlSecAssert2(data != NULL, -1);
677 over = (over - tmp) / 256;
679 data[i] = tmp - over;
689 * @bn: the pointer to BN.
691 * Reverses bytes order in @bn.
693 * Returns: 0 on success or a negative value if an error occurs.
696 xmlSecBnReverse(xmlSecBnPtr bn) {
698 xmlSecSize i, j, size;
701 xmlSecAssert2(bn != NULL, -1);
703 data = xmlSecBufferGetData(bn);
704 size = xmlSecBufferGetSize(bn);
705 for(i = 0, j = size - 1; i < size / 2; ++i, --j) {
706 xmlSecAssert2(data != NULL, -1);
718 * @bn: the pointer to BN.
719 * @data: the data to compare BN to.
720 * @dataSize: the @data size.
722 * Compares the @bn with @data.
724 * Returns: 0 if data is equal, negative value if @bn is less or positive value if @bn
725 * is greater than @data.
728 xmlSecBnCompare(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSize) {
732 xmlSecAssert2(bn != NULL, -1);
734 bnData = xmlSecBnGetData(bn);
735 bnSize = xmlSecBnGetSize(bn);
737 /* skip zeros in the beggining */
738 while((dataSize > 0) && (data != 0) && (data[0] == 0)) {
742 while((bnSize > 0) && (bnData != 0) && (bnData[0] == 0)) {
747 if(((bnData == NULL) || (bnSize == 0)) && ((data == NULL) || (dataSize == 0))) {
749 } else if((bnData == NULL) || (bnSize == 0)) {
751 } else if((data == NULL) || (dataSize == 0)) {
753 } else if(bnSize < dataSize) {
755 } else if(bnSize > dataSize) {
759 xmlSecAssert2(bnData != NULL, -1);
760 xmlSecAssert2(data != NULL, -1);
761 xmlSecAssert2(bnSize == dataSize, -1);
763 return(memcmp(bnData, data, dataSize));
767 * xmlSecBnCompareReverse:
768 * @bn: the pointer to BN.
769 * @data: the data to compare BN to.
770 * @dataSize: the @data size.
772 * Compares the @bn with reverse @data.
774 * Returns: 0 if data is equal, negative value if @bn is less or positive value if @bn
775 * is greater than @data.
778 xmlSecBnCompareReverse(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSize) {
783 xmlSecAssert2(bn != NULL, -1);
785 bnData = xmlSecBnGetData(bn);
786 bnSize = xmlSecBnGetSize(bn);
788 /* skip zeros in the beggining */
789 while((dataSize > 0) && (data != 0) && (data[dataSize - 1] == 0)) {
792 while((bnSize > 0) && (bnData != 0) && (bnData[0] == 0)) {
797 if(((bnData == NULL) || (bnSize == 0)) && ((data == NULL) || (dataSize == 0))) {
799 } else if((bnData == NULL) || (bnSize == 0)) {
801 } else if((data == NULL) || (dataSize == 0)) {
803 } else if(bnSize < dataSize) {
805 } else if(bnSize > dataSize) {
809 xmlSecAssert2(bnData != NULL, -1);
810 xmlSecAssert2(data != NULL, -1);
811 xmlSecAssert2(bnSize == dataSize, -1);
812 for(i = 0, j = dataSize - 1; i < dataSize; ++i, --j) {
813 if(bnData[i] < data[j]) {
815 } else if(data[j] < bnData[i]) {
824 * xmlSecBnGetNodeValue:
825 * @bn: the pointer to BN.
826 * @cur: the poitner to an XML node.
827 * @format: the BN format.
828 * @reverse: if set then reverse read buffer after reading.
830 * Converts the node content from @format to @bn.
832 * Returns: 0 on success and a negative values if an error occurs.
835 xmlSecBnGetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int reverse) {
839 xmlSecAssert2(bn != NULL, -1);
840 xmlSecAssert2(cur != NULL, -1);
844 ret = xmlSecBufferBase64NodeContentRead(bn, cur);
846 xmlSecError(XMLSEC_ERRORS_HERE,
848 "xmlSecBufferBase64NodeContentRead",
849 XMLSEC_ERRORS_R_XMLSEC_FAILED,
850 XMLSEC_ERRORS_NO_MESSAGE);
855 content = xmlNodeGetContent(cur);
856 if(content == NULL) {
857 xmlSecError(XMLSEC_ERRORS_HERE,
860 XMLSEC_ERRORS_R_XML_FAILED,
861 XMLSEC_ERRORS_NO_MESSAGE);
864 ret = xmlSecBnFromHexString(bn, content);
866 xmlSecError(XMLSEC_ERRORS_HERE,
868 "xmlSecBnFromHexString",
869 XMLSEC_ERRORS_R_XMLSEC_FAILED,
870 XMLSEC_ERRORS_NO_MESSAGE);
877 content = xmlNodeGetContent(cur);
878 if(content == NULL) {
879 xmlSecError(XMLSEC_ERRORS_HERE,
882 XMLSEC_ERRORS_R_XML_FAILED,
883 XMLSEC_ERRORS_NO_MESSAGE);
886 ret = xmlSecBnFromDecString(bn, content);
888 xmlSecError(XMLSEC_ERRORS_HERE,
890 "xmlSecBnFromDecString",
891 XMLSEC_ERRORS_R_XMLSEC_FAILED,
892 XMLSEC_ERRORS_NO_MESSAGE);
901 ret = xmlSecBnReverse(bn);
903 xmlSecError(XMLSEC_ERRORS_HERE,
906 XMLSEC_ERRORS_R_XMLSEC_FAILED,
907 XMLSEC_ERRORS_NO_MESSAGE);
915 * xmlSecBnSetNodeValue:
916 * @bn: the pointer to BN.
917 * @cur: the poitner to an XML node.
918 * @format: the BN format.
919 * @reverse: the flag that indicates whether to reverse the buffer before writing.
920 * @addLineBreaks: the flag; it is equal to 1 then linebreaks will be added before and after new buffer content.
922 * Converts the @bn and sets it to node content.
924 * Returns: 0 on success and a negative values if an error occurs.
927 xmlSecBnSetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int reverse, int addLineBreaks) {
931 xmlSecAssert2(bn != NULL, -1);
932 xmlSecAssert2(cur != NULL, -1);
935 ret = xmlSecBnReverse(bn);
937 xmlSecError(XMLSEC_ERRORS_HERE,
940 XMLSEC_ERRORS_R_XMLSEC_FAILED,
941 XMLSEC_ERRORS_NO_MESSAGE);
947 xmlNodeAddContent(cur, xmlSecStringCR);
952 ret = xmlSecBufferBase64NodeContentWrite(bn, cur, xmlSecBase64GetDefaultLineSize());
954 xmlSecError(XMLSEC_ERRORS_HERE,
956 "xmlSecBufferBase64NodeContentWrite",
957 XMLSEC_ERRORS_R_XMLSEC_FAILED,
958 XMLSEC_ERRORS_NO_MESSAGE);
963 content = xmlSecBnToHexString(bn);
964 if(content == NULL) {
965 xmlSecError(XMLSEC_ERRORS_HERE,
967 "xmlSecBnToHexString",
968 XMLSEC_ERRORS_R_XMLSEC_FAILED,
969 XMLSEC_ERRORS_NO_MESSAGE);
973 xmlNodeSetContent(cur, content);
977 content = xmlSecBnToDecString(bn);
978 if(content == NULL) {
979 xmlSecError(XMLSEC_ERRORS_HERE,
981 "xmlSecBnToDecString",
982 XMLSEC_ERRORS_R_XMLSEC_FAILED,
983 XMLSEC_ERRORS_NO_MESSAGE);
987 xmlNodeSetContent(cur, content);
993 xmlNodeAddContent(cur, xmlSecStringCR);
1000 * xmlSecBnBlobSetNodeValue:
1001 * @data: the pointer to BN blob.
1002 * @dataSize: the size of BN blob.
1003 * @cur: the poitner to an XML node.
1004 * @format: the BN format.
1005 * @reverse: the flag that indicates whether to reverse the buffer before writing.
1006 * @addLineBreaks: if the flag is equal to 1 then
1007 * linebreaks will be added before and after
1008 * new buffer content.
1010 * Converts the @blob and sets it to node content.
1012 * Returns: 0 on success and a negative values if an error occurs.
1015 xmlSecBnBlobSetNodeValue(const xmlSecByte* data, xmlSecSize dataSize,
1016 xmlNodePtr cur, xmlSecBnFormat format, int reverse,
1017 int addLineBreaks) {
1021 xmlSecAssert2(data != NULL, -1);
1022 xmlSecAssert2(cur != NULL, -1);
1024 ret = xmlSecBnInitialize(&bn, dataSize);
1026 xmlSecError(XMLSEC_ERRORS_HERE,
1028 "xmlSecBnInitialize",
1029 XMLSEC_ERRORS_R_XMLSEC_FAILED,
1030 XMLSEC_ERRORS_NO_MESSAGE);
1034 ret = xmlSecBnSetData(&bn, data, dataSize);
1036 xmlSecError(XMLSEC_ERRORS_HERE,
1039 XMLSEC_ERRORS_R_XMLSEC_FAILED,
1040 XMLSEC_ERRORS_NO_MESSAGE);
1041 xmlSecBnFinalize(&bn);
1045 ret = xmlSecBnSetNodeValue(&bn, cur, format, reverse, addLineBreaks);
1047 xmlSecError(XMLSEC_ERRORS_HERE,
1049 "xmlSecBnSetNodeValue",
1050 XMLSEC_ERRORS_R_XMLSEC_FAILED,
1051 XMLSEC_ERRORS_NO_MESSAGE);
1052 xmlSecBnFinalize(&bn);
1056 xmlSecBnFinalize(&bn);