diff options
Diffstat (limited to 'src/bn.c')
-rw-r--r-- | src/bn.c | 710 |
1 files changed, 355 insertions, 355 deletions
@@ -1,20 +1,20 @@ -/** +/** * XML Security Library (http://www.aleksey.com/xmlsec). * * Big Numbers. * * This is free software; see Copyright file in the source * distribution for preciese wording. - * + * * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> - * Copyright (C) 2003 Cordys R&D BV, All rights reserved. + * Copyrigth (C) 2003 Cordys R&D BV, All rights reserved. */ #include "globals.h" #include <stdlib.h> #include <string.h> #include <ctype.h> - + #include <libxml/tree.h> #include <xmlsec/xmlsec.h> @@ -44,10 +44,10 @@ static const int xmlSecBnLookupTable[] = -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; -static const char xmlSecBnRevLookupTable[] = -{ - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' +static const char xmlSecBnRevLookupTable[] = +{ + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /***************************************************************************** @@ -57,118 +57,118 @@ static const char xmlSecBnRevLookupTable[] = ****************************************************************************/ /** * xmlSecBnCreate: - * @size: the initial allocated BN size. + * @size: the initial allocated BN size. * * Creates a new BN object. Caller is responsible for destroying it * by calling @xmlSecBnDestroy function. * * Returns: the newly BN or a NULL if an error occurs. */ -xmlSecBnPtr +xmlSecBnPtr xmlSecBnCreate(xmlSecSize size) { return(xmlSecBufferCreate(size)); } /** * xmlSecBnDestroy: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * * Destroys @bn object created with @xmlSecBnCreate function. */ -void +void xmlSecBnDestroy(xmlSecBnPtr bn) { xmlSecBufferDestroy(bn); } /** * xmlSecBnInitialize: - * @bn: the pointer to BN. - * @size: the initial allocated BN size. + * @bn: the pointer to BN. + * @size: the initial allocated BN size. * * Initializes a BN object. Caller is responsible for destroying it * by calling @xmlSecBnFinalize function. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnInitialize(xmlSecBnPtr bn, xmlSecSize size) { return(xmlSecBufferInitialize(bn, size)); } /** * xmlSecBnFinalize: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * * Destroys @bn object created with @xmlSecBnInitialize function. */ -void +void xmlSecBnFinalize(xmlSecBnPtr bn) { xmlSecBufferFinalize(bn); } /** * xmlSecBnGetData: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * * Gets pointer to the binary @bn representation. - * + * * Returns: pointer to binary BN data or NULL if an error occurs. */ -xmlSecByte* +xmlSecByte* xmlSecBnGetData(xmlSecBnPtr bn) { return(xmlSecBufferGetData(bn)); } /** * xmlSecBnSetData: - * @bn: the pointer to BN. - * @data: the pointer to new BN binary data. - * @size: the size of new BN data. + * @bn: the pointer to BN. + * @data: the pointer to new BN binary data. + * @size: the size of new BN data. * * Sets the value of @bn to @data. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnSetData(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize size) { return(xmlSecBufferSetData(bn, data, size)); } /** * xmlSecBnGetSize: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * * Gets the size of binary data in @bn. * * Returns: the size of binary data. */ -xmlSecSize +xmlSecSize xmlSecBnGetSize(xmlSecBnPtr bn) { return(xmlSecBufferGetSize(bn)); } /** * xmlSecBnZero: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * * Sets the value of @bn to zero. */ -void +void xmlSecBnZero(xmlSecBnPtr bn) { xmlSecBufferEmpty(bn); } /** * xmlSecBnFromString: - * @bn: the pointer to BN. - * @str: the string with BN. - * @base: the base for @str. + * @bn: the pointer to BN. + * @str: the string with BN. + * @base: the base for @str. * * Reads @bn from string @str assuming it has base @base. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) { xmlSecSize i, len, size; xmlSecByte ch; @@ -187,21 +187,21 @@ xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) { if(len == 0) { return(0); } - + /* The result size could not exceed the input string length * because each char fits inside a byte in all cases :) * In truth, it would be likely less than 1/2 input string length - * because each byte is represented by 2 chars. If needed, + * because each byte is represented by 2 chars. If needed, * buffer size would be increased by Mul/Add functions. * Finally, we can add one byte for 00 or 10 prefix. */ ret = xmlSecBufferSetMaxSize(bn, xmlSecBufferGetSize(bn) + len / 2 + 1 + 1); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnRevLookupTable", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", len / 2 + 1); + NULL, + "xmlSecBnRevLookupTable", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", len / 2 + 1); return (-1); } @@ -213,9 +213,9 @@ xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) { /* skip spaces */ if(isspace(ch)) { - continue; - } - + continue; + } + /* check if it is + or - */ if(ch == '+') { positive = 1; @@ -235,13 +235,13 @@ xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) { --i; /* make sure that we will look at this character in next loop */ break; } else { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "char=%c;base=%d", - ch, base); - return (-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "char=%c;base=%d", + ch, base); + return (-1); } } @@ -249,40 +249,40 @@ xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) { while(i < len) { ch = str[i++]; if(isspace(ch)) { - continue; + continue; } xmlSecAssert2(ch <= sizeof(xmlSecBnLookupTable), -1); nn = xmlSecBnLookupTable[ch]; if((nn < 0) || ((xmlSecSize)nn > base)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "char=%c;base=%d", - ch, base); - return (-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "char=%c;base=%d", + ch, base); + return (-1); } ret = xmlSecBnMul(bn, base); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnMul", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "base=%d", base); - return (-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnMul", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "base=%d", base); + return (-1); } ret = xmlSecBnAdd(bn, nn); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnAdd", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "base=%d", base); - return (-1); -} + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnAdd", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "base=%d", base); + return (-1); +} } /* check if we need to add 00 prefix, do this for empty bn too */ @@ -308,7 +308,7 @@ xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) { for(i = 0; i < size; ++i) { data[i] ^= 0xFF; } - + ret = xmlSecBnAdd(bn, 1); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, @@ -325,15 +325,15 @@ xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar* str, xmlSecSize base) { /** * xmlSecBnToString: - * @bn: the pointer to BN. - * @base: the base for returned string. + * @bn: the pointer to BN. + * @base: the base for returned string. * - * Writes @bn to string with base @base. Caller is responsible for + * Writes @bn to string with base @base. Caller is responsible for * freeing returned string with @xmlFree. * * Returns: the string represenataion if BN or a NULL if an error occurs. */ -xmlChar* +xmlChar* xmlSecBnToString(xmlSecBnPtr bn, xmlSecSize base) { xmlSecBn bn2; int positive = 1; @@ -361,7 +361,7 @@ xmlSecBnToString(xmlSecBnPtr bn, xmlSecSize base) { "size=%d", size); return (NULL); } - + ret = xmlSecBnSetData(&bn2, data, size); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, @@ -398,18 +398,18 @@ xmlSecBnToString(xmlSecBnPtr bn, xmlSecSize base) { } /* Result string len is - * len = log base (256) * <bn size> - * Since the smallest base == 2 then we can get away with - * len = 8 * <bn size> + * len = log base (256) * <bn size> + * Since the smallest base == 2 then we can get away with + * len = 8 * <bn size> */ len = 8 * size + 1 + 1; res = (xmlChar*)xmlMalloc(len + 1); if(res == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_MALLOC_FAILED, - "len=%d", len); + NULL, + NULL, + XMLSEC_ERRORS_R_MALLOC_FAILED, + "len=%d", len); xmlSecBnFinalize(&bn2); return (NULL); } @@ -454,70 +454,70 @@ xmlSecBnToString(xmlSecBnPtr bn, xmlSecSize base) { /** * xmlSecBnFromHexString: - * @bn: the pointer to BN. - * @str: the string with BN. + * @bn: the pointer to BN. + * @str: the string with BN. * * Reads @bn from hex string @str. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnFromHexString(xmlSecBnPtr bn, const xmlChar* str) { return(xmlSecBnFromString(bn, str, 16)); } /** * xmlSecBnToHexString: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * - * Writes @bn to hex string. Caller is responsible for + * Writes @bn to hex string. Caller is responsible for * freeing returned string with @xmlFree. * * Returns: the string represenataion if BN or a NULL if an error occurs. */ -xmlChar* +xmlChar* xmlSecBnToHexString(xmlSecBnPtr bn) { return(xmlSecBnToString(bn, 16)); } /** * xmlSecBnFromDecString: - * @bn: the pointer to BN. - * @str: the string with BN. + * @bn: the pointer to BN. + * @str: the string with BN. * * Reads @bn from decimal string @str. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnFromDecString(xmlSecBnPtr bn, const xmlChar* str) { return(xmlSecBnFromString(bn, str, 10)); } /** * xmlSecBnToDecString: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * - * Writes @bn to decimal string. Caller is responsible for + * Writes @bn to decimal string. Caller is responsible for * freeing returned string with @xmlFree. * * Returns: the string represenataion if BN or a NULL if an error occurs. */ -xmlChar* +xmlChar* xmlSecBnToDecString(xmlSecBnPtr bn) { return(xmlSecBnToString(bn, 10)); } /** * xmlSecBnMul: - * @bn: the pointer to BN. - * @multiplier: the multiplier. + * @bn: the pointer to BN. + * @multiplier: the multiplier. * * Multiplies @bn with @multiplier. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnMul(xmlSecBnPtr bn, int multiplier) { xmlSecByte* data; int over; @@ -529,49 +529,49 @@ xmlSecBnMul(xmlSecBnPtr bn, int multiplier) { xmlSecAssert2(multiplier > 0, -1); if(multiplier == 1) { - return(0); + return(0); } data = xmlSecBufferGetData(bn); i = xmlSecBufferGetSize(bn); - over = 0; + over = 0; while(i > 0) { - xmlSecAssert2(data != NULL, -1); + xmlSecAssert2(data != NULL, -1); - over = over + multiplier * data[--i]; - data[i] = over % 256; - over = over / 256; + over = over + multiplier * data[--i]; + data[i] = over % 256; + over = over / 256; } - + while(over > 0) { - ch = over % 256; - over = over / 256; - - ret = xmlSecBufferPrepend(bn, &ch, 1); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferPrepend", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=1"); - return (-1); - } + ch = over % 256; + over = over / 256; + + ret = xmlSecBufferPrepend(bn, &ch, 1); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferPrepend", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=1"); + return (-1); + } } - + return(0); } /** * xmlSecBnDiv: - * @bn: the pointer to BN. - * @divider: the divider - * @mod: the pointer for modulus result. + * @bn: the pointer to BN. + * @divider: the divider + * @mod: the pointer for modulus result. * * Divides @bn by @divider and places modulus into @mod. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnDiv(xmlSecBnPtr bn, int divider, int* mod) { int over; xmlSecSize i, size; @@ -583,52 +583,52 @@ xmlSecBnDiv(xmlSecBnPtr bn, int divider, int* mod) { xmlSecAssert2(mod != NULL, -1); if(divider == 1) { - return(0); + return(0); } data = xmlSecBufferGetData(bn); size = xmlSecBufferGetSize(bn); for(over = 0, i = 0; i < size; i++) { - xmlSecAssert2(data != NULL, -1); + xmlSecAssert2(data != NULL, -1); - over = over * 256 + data[i]; - data[i] = over / divider; - over = over % divider; + over = over * 256 + data[i]; + data[i] = over / divider; + over = over % divider; } (*mod) = over; - + /* remove leading zeros */ for(i = 0; i < size; i++) { - xmlSecAssert2(data != NULL, -1); + xmlSecAssert2(data != NULL, -1); - if(data[i] != 0) { - break; - } + if(data[i] != 0) { + break; + } } if(i > 0) { - ret = xmlSecBufferRemoveHead(bn, i); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferRemoveHead", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", i); - return (-1); - } + ret = xmlSecBufferRemoveHead(bn, i); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferRemoveHead", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", i); + return (-1); + } } return(0); } /** * xmlSecBnAdd: - * @bn: the pointer to BN. - * @delta: the delta. + * @bn: the pointer to BN. + * @delta: the delta. * * Adds @delta to @bn. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnAdd(xmlSecBnPtr bn, int delta) { int over, tmp; xmlSecByte* data; @@ -639,41 +639,41 @@ xmlSecBnAdd(xmlSecBnPtr bn, int delta) { xmlSecAssert2(bn != NULL, -1); if(delta == 0) { - return(0); + return(0); } data = xmlSecBufferGetData(bn); if(delta > 0) { for(over = delta, i = xmlSecBufferGetSize(bn); (i > 0) && (over > 0) ;) { - xmlSecAssert2(data != NULL, -1); - + xmlSecAssert2(data != NULL, -1); + tmp = data[--i]; - over += tmp; - data[i] = over % 256; - over = over / 256; + over += tmp; + data[i] = over % 256; + over = over / 256; } - + while(over > 0) { - ch = over % 256; - over = over / 256; - - ret = xmlSecBufferPrepend(bn, &ch, 1); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferPrepend", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=1"); - return (-1); - } + ch = over % 256; + over = over / 256; + + ret = xmlSecBufferPrepend(bn, &ch, 1); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferPrepend", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=1"); + return (-1); + } } } else { for(over = -delta, i = xmlSecBufferGetSize(bn); (i > 0) && (over > 0);) { - xmlSecAssert2(data != NULL, -1); - + xmlSecAssert2(data != NULL, -1); + tmp = data[--i]; if(tmp < over) { - data[i] = 0; + data[i] = 0; over = (over - tmp) / 256; } else { data[i] = tmp - over; @@ -686,13 +686,13 @@ xmlSecBnAdd(xmlSecBnPtr bn, int delta) { /** * xmlSecBnReverse: - * @bn: the pointer to BN. + * @bn: the pointer to BN. * * Reverses bytes order in @bn. * * Returns: 0 on success or a negative value if an error occurs. */ -int +int xmlSecBnReverse(xmlSecBnPtr bn) { xmlSecByte* data; xmlSecSize i, j, size; @@ -703,28 +703,28 @@ xmlSecBnReverse(xmlSecBnPtr bn) { data = xmlSecBufferGetData(bn); size = xmlSecBufferGetSize(bn); for(i = 0, j = size - 1; i < size / 2; ++i, --j) { - xmlSecAssert2(data != NULL, -1); + xmlSecAssert2(data != NULL, -1); - ch = data[i]; - data[i] = data[j]; - data[j] = ch; - } + ch = data[i]; + data[i] = data[j]; + data[j] = ch; + } return(0); } /** * xmlSecBnCompare: - * @bn: the pointer to BN. - * @data: the data to compare BN to. - * @dataSize: the @data size. + * @bn: the pointer to BN. + * @data: the data to compare BN to. + * @dataSize: the @data size. * * Compares the @bn with @data. * * Returns: 0 if data is equal, negative value if @bn is less or positive value if @bn * is greater than @data. */ -int +int xmlSecBnCompare(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSize) { xmlSecByte* bnData; xmlSecSize bnSize; @@ -736,25 +736,25 @@ xmlSecBnCompare(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSize) { /* skip zeros in the beggining */ while((dataSize > 0) && (data != 0) && (data[0] == 0)) { - ++data; - --dataSize; + ++data; + --dataSize; } while((bnSize > 0) && (bnData != 0) && (bnData[0] == 0)) { - ++bnData; - --bnSize; + ++bnData; + --bnSize; } if(((bnData == NULL) || (bnSize == 0)) && ((data == NULL) || (dataSize == 0))) { - return(0); + return(0); } else if((bnData == NULL) || (bnSize == 0)) { - return(-1); + return(-1); } else if((data == NULL) || (dataSize == 0)) { - return(1); + return(1); } else if(bnSize < dataSize) { - return(-1); + return(-1); } else if(bnSize > dataSize) { - return(-1); - } + return(-1); + } xmlSecAssert2(bnData != NULL, -1); xmlSecAssert2(data != NULL, -1); @@ -765,16 +765,16 @@ xmlSecBnCompare(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSize) { /** * xmlSecBnCompareReverse: - * @bn: the pointer to BN. - * @data: the data to compare BN to. - * @dataSize: the @data size. + * @bn: the pointer to BN. + * @data: the data to compare BN to. + * @dataSize: the @data size. * * Compares the @bn with reverse @data. * * Returns: 0 if data is equal, negative value if @bn is less or positive value if @bn * is greater than @data. */ -int +int xmlSecBnCompareReverse(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSize) { xmlSecByte* bnData; xmlSecSize bnSize; @@ -787,34 +787,34 @@ xmlSecBnCompareReverse(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSi /* skip zeros in the beggining */ while((dataSize > 0) && (data != 0) && (data[dataSize - 1] == 0)) { - --dataSize; + --dataSize; } while((bnSize > 0) && (bnData != 0) && (bnData[0] == 0)) { - ++bnData; - --bnSize; + ++bnData; + --bnSize; } if(((bnData == NULL) || (bnSize == 0)) && ((data == NULL) || (dataSize == 0))) { - return(0); + return(0); } else if((bnData == NULL) || (bnSize == 0)) { - return(-1); + return(-1); } else if((data == NULL) || (dataSize == 0)) { - return(1); + return(1); } else if(bnSize < dataSize) { - return(-1); + return(-1); } else if(bnSize > dataSize) { - return(-1); - } + return(-1); + } xmlSecAssert2(bnData != NULL, -1); xmlSecAssert2(data != NULL, -1); xmlSecAssert2(bnSize == dataSize, -1); for(i = 0, j = dataSize - 1; i < dataSize; ++i, --j) { - if(bnData[i] < data[j]) { - return(-1); - } else if(data[j] < bnData[i]) { - return(1); - } + if(bnData[i] < data[j]) { + return(-1); + } else if(data[j] < bnData[i]) { + return(1); + } } return(0); @@ -822,16 +822,16 @@ xmlSecBnCompareReverse(xmlSecBnPtr bn, const xmlSecByte* data, xmlSecSize dataSi /** * xmlSecBnGetNodeValue: - * @bn: the pointer to BN. - * @cur: the poitner to an XML node. - * @format: the BN format. - * @reverse: if set then reverse read buffer after reading. + * @bn: the pointer to BN. + * @cur: the poitner to an XML node. + * @format: the BN format. + * @reverse: if set then reverse read buffer after reading. * * Converts the node content from @format to @bn. * * Returns: 0 on success and a negative values if an error occurs. */ -int +int xmlSecBnGetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int reverse) { xmlChar* content; int ret; @@ -841,89 +841,89 @@ xmlSecBnGetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int switch(format) { case xmlSecBnBase64: - ret = xmlSecBufferBase64NodeContentRead(bn, cur); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferBase64NodeContentRead", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } - break; + ret = xmlSecBufferBase64NodeContentRead(bn, cur); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferBase64NodeContentRead", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } + break; case xmlSecBnHex: - content = xmlNodeGetContent(cur); - if(content == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlNodeGetContent", - XMLSEC_ERRORS_R_XML_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } - ret = xmlSecBnFromHexString(bn, content); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnFromHexString", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlFree(content); - return(-1); - } - xmlFree(content); - break; + content = xmlNodeGetContent(cur); + if(content == NULL) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlNodeGetContent", + XMLSEC_ERRORS_R_XML_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } + ret = xmlSecBnFromHexString(bn, content); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnFromHexString", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlFree(content); + return(-1); + } + xmlFree(content); + break; case xmlSecBnDec: - content = xmlNodeGetContent(cur); - if(content == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlNodeGetContent", - XMLSEC_ERRORS_R_XML_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } - ret = xmlSecBnFromDecString(bn, content); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnFromDecString", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlFree(content); - return(-1); - } - xmlFree(content); - break; + content = xmlNodeGetContent(cur); + if(content == NULL) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlNodeGetContent", + XMLSEC_ERRORS_R_XML_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } + ret = xmlSecBnFromDecString(bn, content); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnFromDecString", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlFree(content); + return(-1); + } + xmlFree(content); + break; } if(reverse != 0) { - ret = xmlSecBnReverse(bn); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnReverse", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } + ret = xmlSecBnReverse(bn); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnReverse", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } } return(0); } /** * xmlSecBnSetNodeValue: - * @bn: the pointer to BN. - * @cur: the poitner to an XML node. - * @format: the BN format. - * @reverse: the flag that indicates whether to reverse the buffer before writing. - * @addLineBreaks: the flag; it is equal to 1 then linebreaks will be added before and after new buffer content. + * @bn: the pointer to BN. + * @cur: the poitner to an XML node. + * @format: the BN format. + * @reverse: the flag that indicates whether to reverse the buffer before writing. + * @addLineBreaks: the flag; it is equal to 1 then linebreaks will be added before and after new buffer content. * * Converts the @bn and sets it to node content. * * Returns: 0 on success and a negative values if an error occurs. */ -int +int xmlSecBnSetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int reverse, int addLineBreaks) { xmlChar* content; int ret; @@ -932,65 +932,65 @@ xmlSecBnSetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int xmlSecAssert2(cur != NULL, -1); if(reverse != 0) { - ret = xmlSecBnReverse(bn); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnReverse", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } + ret = xmlSecBnReverse(bn); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnReverse", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } } if(addLineBreaks) { - xmlNodeAddContent(cur, xmlSecStringCR); + xmlNodeAddContent(cur, xmlSecStringCR); } switch(format) { case xmlSecBnBase64: - ret = xmlSecBufferBase64NodeContentWrite(bn, cur, xmlSecBase64GetDefaultLineSize()); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBufferBase64NodeContentWrite", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } - break; + ret = xmlSecBufferBase64NodeContentWrite(bn, cur, xmlSecBase64GetDefaultLineSize()); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBufferBase64NodeContentWrite", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } + break; case xmlSecBnHex: - content = xmlSecBnToHexString(bn); - if(content == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnToHexString", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlFree(content); - return(-1); - } - xmlNodeSetContent(cur, content); - xmlFree(content); - break; + content = xmlSecBnToHexString(bn); + if(content == NULL) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnToHexString", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlFree(content); + return(-1); + } + xmlNodeSetContent(cur, content); + xmlFree(content); + break; case xmlSecBnDec: - content = xmlSecBnToDecString(bn); - if(content == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnToDecString", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlFree(content); - return(-1); - } - xmlNodeSetContent(cur, content); - xmlFree(content); - break; + content = xmlSecBnToDecString(bn); + if(content == NULL) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnToDecString", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlFree(content); + return(-1); + } + xmlNodeSetContent(cur, content); + xmlFree(content); + break; } if(addLineBreaks) { - xmlNodeAddContent(cur, xmlSecStringCR); + xmlNodeAddContent(cur, xmlSecStringCR); } return(0); @@ -998,23 +998,23 @@ xmlSecBnSetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int /** * xmlSecBnBlobSetNodeValue: - * @data: the pointer to BN blob. - * @dataSize: the size of BN blob. - * @cur: the poitner to an XML node. - * @format: the BN format. - * @reverse: the flag that indicates whether to reverse the buffer before writing. - * @addLineBreaks: if the flag is equal to 1 then - * linebreaks will be added before and after - * new buffer content. + * @data: the pointer to BN blob. + * @dataSize: the size of BN blob. + * @cur: the poitner to an XML node. + * @format: the BN format. + * @reverse: the flag that indicates whether to reverse the buffer before writing. + * @addLineBreaks: if the flag is equal to 1 then + * linebreaks will be added before and after + * new buffer content. * * Converts the @blob and sets it to node content. * * Returns: 0 on success and a negative values if an error occurs. */ -int -xmlSecBnBlobSetNodeValue(const xmlSecByte* data, xmlSecSize dataSize, - xmlNodePtr cur, xmlSecBnFormat format, int reverse, - int addLineBreaks) { +int +xmlSecBnBlobSetNodeValue(const xmlSecByte* data, xmlSecSize dataSize, + xmlNodePtr cur, xmlSecBnFormat format, int reverse, + int addLineBreaks) { xmlSecBn bn; int ret; @@ -1023,34 +1023,34 @@ xmlSecBnBlobSetNodeValue(const xmlSecByte* data, xmlSecSize dataSize, ret = xmlSecBnInitialize(&bn, dataSize); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnInitialize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } ret = xmlSecBnSetData(&bn, data, dataSize); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnSetData", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecBnFinalize(&bn); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnSetData", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecBnFinalize(&bn); + return(-1); } ret = xmlSecBnSetNodeValue(&bn, cur, format, reverse, addLineBreaks); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBnSetNodeValue", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecBnFinalize(&bn); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBnSetNodeValue", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecBnFinalize(&bn); + return(-1); } xmlSecBnFinalize(&bn); |