diff options
Diffstat (limited to 'src/base64.c')
-rw-r--r-- | src/base64.c | 874 |
1 files changed, 437 insertions, 437 deletions
diff --git a/src/base64.c b/src/base64.c index 53e66945..73b9e504 100644 --- a/src/base64.c +++ b/src/base64.c @@ -5,7 +5,7 @@ * * 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" @@ -22,11 +22,11 @@ #include <xmlsec/base64.h> #include <xmlsec/errors.h> -/* - * the table to map numbers to base64 +/* + * the table to map numbers to base64 */ static const xmlSecByte base64[] = -{ +{ /* 0 1 2 3 4 5 6 7 */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', /* 0 */ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', /* 1 */ @@ -40,21 +40,21 @@ static const xmlSecByte base64[] = /* few macros to simplify the code */ -#define xmlSecBase64Encode1(a) (((a) >> 2) & 0x3F) -#define xmlSecBase64Encode2(a, b) ((((a) << 4) & 0x30) + (((b) >> 4) & 0x0F)) -#define xmlSecBase64Encode3(b, c) ((((b) << 2) & 0x3c) + (((c) >> 6) & 0x03)) -#define xmlSecBase64Encode4(c) ((c) & 0x3F) - -#define xmlSecBase64Decode1(a, b) (((a) << 2) | (((b) & 0x3F) >> 4)) -#define xmlSecBase64Decode2(b, c) (((b) << 4) | (((c) & 0x3F) >> 2)) -#define xmlSecBase64Decode3(c, d) (((c) << 6) | ((d) & 0x3F)) +#define xmlSecBase64Encode1(a) (((a) >> 2) & 0x3F) +#define xmlSecBase64Encode2(a, b) ((((a) << 4) & 0x30) + (((b) >> 4) & 0x0F)) +#define xmlSecBase64Encode3(b, c) ((((b) << 2) & 0x3c) + (((c) >> 6) & 0x03)) +#define xmlSecBase64Encode4(c) ((c) & 0x3F) -#define xmlSecIsBase64Char(ch) ((((ch) >= 'A') && ((ch) <= 'Z')) || \ - (((ch) >= 'a') && ((ch) <= 'z')) || \ - (((ch) >= '0') && ((ch) <= '9')) || \ - ((ch) == '+') || ((ch) == '/')) -#define xmlSecIsBase64Space(ch) (((ch) == ' ') || ((ch) == '\t') || \ - ((ch) == '\x0d') || ((ch) == '\x0a')) +#define xmlSecBase64Decode1(a, b) (((a) << 2) | (((b) & 0x3F) >> 4)) +#define xmlSecBase64Decode2(b, c) (((b) << 4) | (((c) & 0x3F) >> 2)) +#define xmlSecBase64Decode3(c, d) (((c) << 6) | ((d) & 0x3F)) + +#define xmlSecIsBase64Char(ch) ((((ch) >= 'A') && ((ch) <= 'Z')) || \ + (((ch) >= 'a') && ((ch) <= 'z')) || \ + (((ch) >= '0') && ((ch) <= '9')) || \ + ((ch) == '+') || ((ch) == '/')) +#define xmlSecIsBase64Space(ch) (((ch) == ' ') || ((ch) == '\t') || \ + ((ch) == '\x0d') || ((ch) == '\x0a')) @@ -72,48 +72,48 @@ typedef enum { } xmlSecBase64Status; struct _xmlSecBase64Ctx { - int encode; + int encode; int inByte; int inPos; - xmlSecSize linePos; - xmlSecSize columns; + xmlSecSize linePos; + xmlSecSize columns; int finished; }; -static xmlSecBase64Status xmlSecBase64CtxEncodeByte (xmlSecBase64CtxPtr ctx, - xmlSecByte inByte, - xmlSecByte* outByte); -static xmlSecBase64Status xmlSecBase64CtxEncodeByteFinal (xmlSecBase64CtxPtr ctx, - xmlSecByte* outByte); -static xmlSecBase64Status xmlSecBase64CtxDecodeByte (xmlSecBase64CtxPtr ctx, - xmlSecByte inByte, - xmlSecByte* outByte); -static int xmlSecBase64CtxEncode (xmlSecBase64CtxPtr ctx, - const xmlSecByte* inBuf, - xmlSecSize inBufSize, - xmlSecSize* inBufResSize, - xmlSecByte* outBuf, - xmlSecSize outBufSize, - xmlSecSize* outBufResSize); -static int xmlSecBase64CtxEncodeFinal (xmlSecBase64CtxPtr ctx, - xmlSecByte* outBuf, - xmlSecSize outBufSize, - xmlSecSize* outBufResSize); -static int xmlSecBase64CtxDecode (xmlSecBase64CtxPtr ctx, - const xmlSecByte* inBuf, - xmlSecSize inBufSize, - xmlSecSize* inBufResSize, - xmlSecByte* outBuf, - xmlSecSize outBufSize, - xmlSecSize* outBufResSize); -static int xmlSecBase64CtxDecodeIsFinished (xmlSecBase64CtxPtr ctx); +static xmlSecBase64Status xmlSecBase64CtxEncodeByte (xmlSecBase64CtxPtr ctx, + xmlSecByte inByte, + xmlSecByte* outByte); +static xmlSecBase64Status xmlSecBase64CtxEncodeByteFinal (xmlSecBase64CtxPtr ctx, + xmlSecByte* outByte); +static xmlSecBase64Status xmlSecBase64CtxDecodeByte (xmlSecBase64CtxPtr ctx, + xmlSecByte inByte, + xmlSecByte* outByte); +static int xmlSecBase64CtxEncode (xmlSecBase64CtxPtr ctx, + const xmlSecByte* inBuf, + xmlSecSize inBufSize, + xmlSecSize* inBufResSize, + xmlSecByte* outBuf, + xmlSecSize outBufSize, + xmlSecSize* outBufResSize); +static int xmlSecBase64CtxEncodeFinal (xmlSecBase64CtxPtr ctx, + xmlSecByte* outBuf, + xmlSecSize outBufSize, + xmlSecSize* outBufResSize); +static int xmlSecBase64CtxDecode (xmlSecBase64CtxPtr ctx, + const xmlSecByte* inBuf, + xmlSecSize inBufSize, + xmlSecSize* inBufResSize, + xmlSecByte* outBuf, + xmlSecSize outBufSize, + xmlSecSize* outBufResSize); +static int xmlSecBase64CtxDecodeIsFinished (xmlSecBase64CtxPtr ctx); static int g_xmlsec_base64_default_line_size = XMLSEC_BASE64_LINESIZE; /** * xmlSecBase64GetDefaultLineSize: - * + * * Gets the current default line size. * * Returns: the current default line size. @@ -138,72 +138,72 @@ xmlSecBase64SetDefaultLineSize(int columns) /** * xmlSecBase64CtxCreate: - * @encode: the encode/decode flag (1 - encode, 0 - decode) - * @columns: the max line length. + * @encode: the encode/decode flag (1 - encode, 0 - decode) + * @columns: the max line length. * * Allocates and initializes new base64 context. * * Returns: a pointer to newly created #xmlSecBase64Ctx structure * or NULL if an error occurs. */ -xmlSecBase64CtxPtr +xmlSecBase64CtxPtr xmlSecBase64CtxCreate(int encode, int columns) { xmlSecBase64CtxPtr ctx; int ret; - + /* * Allocate a new xmlSecBase64CtxPtr and fill the fields. */ ctx = (xmlSecBase64CtxPtr) xmlMalloc(sizeof(xmlSecBase64Ctx)); if (ctx == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_MALLOC_FAILED, - "sizeof(xmlSecBase64Ctx)=%d", - sizeof(xmlSecBase64Ctx)); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_MALLOC_FAILED, + "sizeof(xmlSecBase64Ctx)=%d", + sizeof(xmlSecBase64Ctx)); + return(NULL); } - + ret = xmlSecBase64CtxInitialize(ctx, encode, columns); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecBase64CtxDestroy(ctx); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxInitialize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecBase64CtxDestroy(ctx); + return(NULL); } return(ctx); } /** * xmlSecBase64CtxDestroy: - * @ctx: the pointer to #xmlSecBase64Ctx structure. - * + * @ctx: the pointer to #xmlSecBase64Ctx structure. + * * Destroys base64 context. */ void xmlSecBase64CtxDestroy(xmlSecBase64CtxPtr ctx) { xmlSecAssert(ctx != NULL); - + xmlSecBase64CtxFinalize(ctx); xmlFree(ctx); } /** * xmlSecBase64CtxInitialize: - * @ctx: the pointer to #xmlSecBase64Ctx structure, - * @encode: the encode/decode flag (1 - encode, 0 - decode) - * @columns: the max line length. + * @ctx: the pointer to #xmlSecBase64Ctx structure, + * @encode: the encode/decode flag (1 - encode, 0 - decode) + * @columns: the max line length. * * Initializes new base64 context. * * Returns: 0 on success and a negative value otherwise. */ -int -xmlSecBase64CtxInitialize(xmlSecBase64CtxPtr ctx, int encode, int columns) { +int +xmlSecBase64CtxInitialize(xmlSecBase64CtxPtr ctx, int encode, int columns) { xmlSecAssert2(ctx != NULL, -1); memset(ctx, 0, sizeof(xmlSecBase64Ctx)); @@ -215,63 +215,63 @@ xmlSecBase64CtxInitialize(xmlSecBase64CtxPtr ctx, int encode, int columns) { /** * xmlSecBase64CtxFinalize: - * @ctx: the pointer to #xmlSecBase64Ctx structure, + * @ctx: the pointer to #xmlSecBase64Ctx structure, * * Frees all the resources allocated by @ctx. */ -void -xmlSecBase64CtxFinalize(xmlSecBase64CtxPtr ctx) { +void +xmlSecBase64CtxFinalize(xmlSecBase64CtxPtr ctx) { xmlSecAssert(ctx != NULL); - memset(ctx, 0, sizeof(xmlSecBase64Ctx)); -} + memset(ctx, 0, sizeof(xmlSecBase64Ctx)); +} /** * xmlSecBase64CtxUpdate: - * @ctx: the pointer to #xmlSecBase64Ctx structure - * @in: the input buffer - * @inSize: the input buffer size - * @out: the output buffer - * @outSize: the output buffer size + * @ctx: the pointer to #xmlSecBase64Ctx structure + * @in: the input buffer + * @inSize: the input buffer size + * @out: the output buffer + * @outSize: the output buffer size * * Encodes or decodes the next piece of data from input buffer. - * - * Returns: the number of bytes written to output buffer or + * + * Returns: the number of bytes written to output buffer or * -1 if an error occurs. */ int xmlSecBase64CtxUpdate(xmlSecBase64CtxPtr ctx, - const xmlSecByte *in, xmlSecSize inSize, - xmlSecByte *out, xmlSecSize outSize) { + const xmlSecByte *in, xmlSecSize inSize, + xmlSecByte *out, xmlSecSize outSize) { xmlSecSize inResSize = 0, outResSize = 0; int ret; - + xmlSecAssert2(ctx != NULL, -1); xmlSecAssert2(in != NULL, -1); xmlSecAssert2(out != NULL, -1); if(ctx->encode != 0) { - ret = xmlSecBase64CtxEncode(ctx, in, inSize, &inResSize, - out, outSize, &outResSize); - if((ret < 0) || (inResSize != inSize)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxEncode", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } + ret = xmlSecBase64CtxEncode(ctx, in, inSize, &inResSize, + out, outSize, &outResSize); + if((ret < 0) || (inResSize != inSize)) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxEncode", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } } else { - ret = xmlSecBase64CtxDecode(ctx, in, inSize, &inResSize, - out, outSize, &outResSize); - if((ret < 0) || (inResSize != inSize)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxDecode", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } + ret = xmlSecBase64CtxDecode(ctx, in, inSize, &inResSize, + out, outSize, &outResSize); + if((ret < 0) || (inResSize != inSize)) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxDecode", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } } return(outResSize); @@ -279,50 +279,50 @@ xmlSecBase64CtxUpdate(xmlSecBase64CtxPtr ctx, /** * xmlSecBase64CtxFinal: - * @ctx: the pointer to #xmlSecBase64Ctx structure - * @out: the output buffer - * @outSize: the output buffer size + * @ctx: the pointer to #xmlSecBase64Ctx structure + * @out: the output buffer + * @outSize: the output buffer size * * Encodes or decodes the last piece of data stored in the context * and finalizes the result. * - * Returns: the number of bytes written to output buffer or + * Returns: the number of bytes written to output buffer or * -1 if an error occurs. */ int -xmlSecBase64CtxFinal(xmlSecBase64CtxPtr ctx, - xmlSecByte *out, xmlSecSize outSize) { +xmlSecBase64CtxFinal(xmlSecBase64CtxPtr ctx, + xmlSecByte *out, xmlSecSize outSize) { xmlSecSize outResSize = 0; int ret; - + xmlSecAssert2(ctx != NULL, -1); - xmlSecAssert2(out != NULL, -1); - xmlSecAssert2(outSize > 0, -1); + xmlSecAssert2(out != NULL, -1); + xmlSecAssert2(outSize > 0, -1); - if(ctx->encode != 0) { - ret = xmlSecBase64CtxEncodeFinal(ctx, out, outSize, &outResSize); + if(ctx->encode != 0) { + ret = xmlSecBase64CtxEncodeFinal(ctx, out, outSize, &outResSize); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxEncodeFinal", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "outSize=%d", outSize); - return(-1); - } + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxEncodeFinal", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "outSize=%d", outSize); + return(-1); + } } else { - if(!xmlSecBase64CtxDecodeIsFinished(ctx)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxIsFinished", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } + if(!xmlSecBase64CtxDecodeIsFinished(ctx)) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxIsFinished", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } } - + /* add \0 */ if((outResSize + 1) < outSize) { - out[outResSize] = '\0'; + out[outResSize] = '\0'; } return(outResSize); } @@ -338,36 +338,36 @@ xmlSecBase64CtxEncodeByte(xmlSecBase64CtxPtr ctx, xmlSecByte inByte, xmlSecByte* return(xmlSecBase64StatusConsumeAndRepeat); } else if(ctx->inPos == 0) { /* we just started new block */ - (*outByte) = base64[xmlSecBase64Encode1(inByte)]; + (*outByte) = base64[xmlSecBase64Encode1(inByte)]; ctx->inByte = inByte; ++ctx->linePos; ++ctx->inPos; return(xmlSecBase64StatusConsumeAndNext); } else if(ctx->inPos == 1) { - (*outByte) = base64[xmlSecBase64Encode2(ctx->inByte, inByte)]; + (*outByte) = base64[xmlSecBase64Encode2(ctx->inByte, inByte)]; ctx->inByte = inByte; ++ctx->linePos; ++ctx->inPos; return(xmlSecBase64StatusConsumeAndNext); } else if(ctx->inPos == 2) { - (*outByte) = base64[xmlSecBase64Encode3(ctx->inByte, inByte)]; + (*outByte) = base64[xmlSecBase64Encode3(ctx->inByte, inByte)]; ctx->inByte = inByte; ++ctx->linePos; ++ctx->inPos; return(xmlSecBase64StatusConsumeAndRepeat); } else if(ctx->inPos == 3) { - (*outByte) = base64[xmlSecBase64Encode4(ctx->inByte)]; + (*outByte) = base64[xmlSecBase64Encode4(ctx->inByte)]; ++ctx->linePos; ctx->inByte = 0; ctx->inPos = 0; return(xmlSecBase64StatusConsumeAndNext); } - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "ctx->inPos=%d", ctx->inPos); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "ctx->inPos=%d", ctx->inPos); return(xmlSecBase64StatusFailed); } @@ -397,68 +397,68 @@ xmlSecBase64CtxEncodeByteFinal(xmlSecBase64CtxPtr ctx, xmlSecByte* outByte) { return(xmlSecBase64StatusConsumeAndRepeat); } - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "ctx->inPos=%d", ctx->inPos); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "ctx->inPos=%d", ctx->inPos); return(xmlSecBase64StatusFailed); } static xmlSecBase64Status xmlSecBase64CtxDecodeByte(xmlSecBase64CtxPtr ctx, xmlSecByte inByte, xmlSecByte* outByte) { xmlSecAssert2(ctx != NULL, xmlSecBase64StatusFailed); - xmlSecAssert2(outByte != NULL, xmlSecBase64StatusFailed); + xmlSecAssert2(outByte != NULL, xmlSecBase64StatusFailed); if((ctx->finished != 0) && (ctx->inPos == 0)) { return(xmlSecBase64StatusDone); } if(inByte == '=') { ctx->finished = 1; if(ctx->inPos < 2) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "ctx->inPos=%d", ctx->inPos); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "ctx->inPos=%d", ctx->inPos); return(xmlSecBase64StatusFailed); } else if(ctx->inPos == 2) { ++ctx->inPos; - return(xmlSecBase64StatusNext); + return(xmlSecBase64StatusNext); } else if(ctx->inPos == 3) { ctx->inPos = 0; return(xmlSecBase64StatusNext); } else { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "ctx->inPos=%d", ctx->inPos); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "ctx->inPos=%d", ctx->inPos); return(xmlSecBase64StatusFailed); } } else if(xmlSecIsBase64Space(inByte)) { return(xmlSecBase64StatusNext); } else if(!xmlSecIsBase64Char(inByte) || (ctx->finished != 0)) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "inByte=0x%02x", inByte); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "inByte=0x%02x", inByte); return(xmlSecBase64StatusFailed); } /* convert from character to position in base64 array */ if((inByte >= 'A') && (inByte <= 'Z')) { - inByte = (inByte - 'A'); + inByte = (inByte - 'A'); } else if((inByte >= 'a') && (inByte <= 'z')) { - inByte = 26 + (inByte - 'a'); + inByte = 26 + (inByte - 'a'); } else if((inByte >= '0') && (inByte <= '9')) { - inByte = 52 + (inByte - '0'); + inByte = 52 + (inByte - '0'); } else if(inByte == '+') { - inByte = 62; + inByte = 62; } else if(inByte == '/') { - inByte = 63; + inByte = 63; } - + if(ctx->inPos == 0) { ctx->inByte = inByte; ++ctx->inPos; @@ -480,22 +480,22 @@ xmlSecBase64CtxDecodeByte(xmlSecBase64CtxPtr ctx, xmlSecByte inByte, xmlSecByte* return(xmlSecBase64StatusConsumeAndNext); } - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "ctx->inPos=%d", ctx->inPos); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "ctx->inPos=%d", ctx->inPos); return(xmlSecBase64StatusFailed); } static int -xmlSecBase64CtxEncode(xmlSecBase64CtxPtr ctx, +xmlSecBase64CtxEncode(xmlSecBase64CtxPtr ctx, const xmlSecByte* inBuf, xmlSecSize inBufSize, xmlSecSize* inBufResSize, xmlSecByte* outBuf, xmlSecSize outBufSize, xmlSecSize* outBufResSize) { xmlSecBase64Status status = xmlSecBase64StatusNext; xmlSecSize inPos, outPos; - + xmlSecAssert2(ctx != NULL, -1); xmlSecAssert2(inBuf != NULL, -1); xmlSecAssert2(inBufResSize != NULL, -1); @@ -516,11 +516,11 @@ xmlSecBase64CtxEncode(xmlSecBase64CtxPtr ctx, case xmlSecBase64StatusNext: case xmlSecBase64StatusDone: case xmlSecBase64StatusFailed: - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxEncodeByte", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "status=%d", status); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxEncodeByte", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "status=%d", status); return(-1); } } @@ -532,11 +532,11 @@ xmlSecBase64CtxEncode(xmlSecBase64CtxPtr ctx, } static int -xmlSecBase64CtxEncodeFinal(xmlSecBase64CtxPtr ctx, +xmlSecBase64CtxEncodeFinal(xmlSecBase64CtxPtr ctx, xmlSecByte* outBuf, xmlSecSize outBufSize, xmlSecSize* outBufResSize) { xmlSecBase64Status status = xmlSecBase64StatusNext; xmlSecSize outPos; - + xmlSecAssert2(ctx != NULL, -1); xmlSecAssert2(outBuf != NULL, -1); xmlSecAssert2(outBufResSize != NULL, -1); @@ -553,21 +553,21 @@ xmlSecBase64CtxEncodeFinal(xmlSecBase64CtxPtr ctx, break; case xmlSecBase64StatusNext: case xmlSecBase64StatusFailed: - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxEncodeByteFinal", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "status=%d", status); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxEncodeByteFinal", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "status=%d", status); return(-1); } } if(status != xmlSecBase64StatusDone) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_SIZE, - "outBufSize=%d", outBufSize); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_SIZE, + "outBufSize=%d", outBufSize); return(-1); } if(outPos < outBufSize) { @@ -580,12 +580,12 @@ xmlSecBase64CtxEncodeFinal(xmlSecBase64CtxPtr ctx, static int -xmlSecBase64CtxDecode(xmlSecBase64CtxPtr ctx, +xmlSecBase64CtxDecode(xmlSecBase64CtxPtr ctx, const xmlSecByte* inBuf, xmlSecSize inBufSize, xmlSecSize* inBufResSize, xmlSecByte* outBuf, xmlSecSize outBufSize, xmlSecSize* outBufResSize) { xmlSecBase64Status status = xmlSecBase64StatusNext; xmlSecSize inPos, outPos; - + xmlSecAssert2(ctx != NULL, -1); xmlSecAssert2(inBuf != NULL, -1); xmlSecAssert2(inBufResSize != NULL, -1); @@ -609,11 +609,11 @@ xmlSecBase64CtxDecode(xmlSecBase64CtxPtr ctx, case xmlSecBase64StatusDone: break; case xmlSecBase64StatusFailed: - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxDecodeByte", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "status=%d", status); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxDecodeByte", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "status=%d", status); return(-1); } } @@ -638,23 +638,23 @@ xmlSecBase64CtxDecodeIsFinished(xmlSecBase64CtxPtr ctx) { /** * xmlSecBase64Encode: - * @buf: the input buffer. - * @len: the input buffer size. - * @columns: the output max line length (if 0 then no line breaks - * would be inserted) + * @buf: the input buffer. + * @len: the input buffer size. + * @columns: the output max line length (if 0 then no line breaks + * would be inserted) * * Encodes the data from input buffer and allocates the string for the result. * The caller is responsible for freeing returned buffer using * xmlFree() function. * - * Returns: newly allocated string with base64 encoded data + * Returns: newly allocated string with base64 encoded data * or NULL if an error occurs. */ xmlChar* xmlSecBase64Encode(const xmlSecByte *buf, xmlSecSize len, int columns) { xmlSecBase64Ctx ctx; xmlChar *ptr; - xmlSecSize size; + xmlSecSize size; int size_update, size_final; int ret; @@ -662,72 +662,72 @@ xmlSecBase64Encode(const xmlSecByte *buf, xmlSecSize len, int columns) { ret = xmlSecBase64CtxInitialize(&ctx, 1, columns); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxInitialize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(NULL); } - + /* create result buffer */ size = (4 * len) / 3 + 4; if(columns > 0) { - size += (size / columns) + 4; + size += (size / columns) + 4; } ptr = (xmlChar*) xmlMalloc(size); if(ptr == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_MALLOC_FAILED, - "size=%d", size); - xmlSecBase64CtxFinalize(&ctx); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_MALLOC_FAILED, + "size=%d", size); + xmlSecBase64CtxFinalize(&ctx); + return(NULL); } ret = xmlSecBase64CtxUpdate(&ctx, buf, len, (xmlSecByte*)ptr, size); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxUpdate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "len=%d", len); - xmlFree(ptr); - xmlSecBase64CtxFinalize(&ctx); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxUpdate", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "len=%d", len); + xmlFree(ptr); + xmlSecBase64CtxFinalize(&ctx); + return(NULL); } size_update = ret; ret = xmlSecBase64CtxFinal(&ctx, ((xmlSecByte*)ptr) + size_update, size - size_update); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxFinal", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlFree(ptr); - xmlSecBase64CtxFinalize(&ctx); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxFinal", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlFree(ptr); + xmlSecBase64CtxFinalize(&ctx); + return(NULL); } size_final = ret; ptr[size_update + size_final] = '\0'; - + xmlSecBase64CtxFinalize(&ctx); return(ptr); } /** * xmlSecBase64Decode: - * @str: the input buffer with base64 encoded string - * @buf: the output buffer - * @len: the output buffer size + * @str: the input buffer with base64 encoded string + * @buf: the output buffer + * @len: the output buffer size * * Decodes input base64 encoded string and puts result into * the output buffer. * - * Returns: the number of bytes written to the output buffer or - * a negative value if an error occurs + * Returns: the number of bytes written to the output buffer or + * a negative value if an error occurs */ int xmlSecBase64Decode(const xmlChar* str, xmlSecByte *buf, xmlSecSize len) { @@ -741,37 +741,37 @@ xmlSecBase64Decode(const xmlChar* str, xmlSecByte *buf, xmlSecSize len) { ret = xmlSecBase64CtxInitialize(&ctx, 0, 0); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxInitialize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } - + ret = xmlSecBase64CtxUpdate(&ctx, (const xmlSecByte*)str, xmlStrlen(str), buf, len); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxUpdate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecBase64CtxFinalize(&ctx); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxUpdate", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecBase64CtxFinalize(&ctx); + return(-1); } size_update = ret; ret = xmlSecBase64CtxFinal(&ctx, buf + size_update, len - size_update); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecBase64CtxFinal", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecBase64CtxFinalize(&ctx); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecBase64CtxFinal", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecBase64CtxFinalize(&ctx); + return(-1); } - size_final = ret; + size_final = ret; xmlSecBase64CtxFinalize(&ctx); return(size_update + size_final); @@ -782,46 +782,46 @@ xmlSecBase64Decode(const xmlChar* str, xmlSecByte *buf, xmlSecSize len) { * Base64 Transform * * xmlSecBase64Ctx is located after xmlSecTransform - * + * **************************************************************/ #define xmlSecBase64Size \ - (sizeof(xmlSecTransform) + sizeof(xmlSecBase64Ctx)) + (sizeof(xmlSecTransform) + sizeof(xmlSecBase64Ctx)) #define xmlSecBase64GetCtx(transform) \ ((xmlSecTransformCheckSize((transform), xmlSecBase64Size)) ? \ - (xmlSecBase64CtxPtr)(((xmlSecByte*)(transform)) + sizeof(xmlSecTransform)) : \ - (xmlSecBase64CtxPtr)NULL) + (xmlSecBase64CtxPtr)(((xmlSecByte*)(transform)) + sizeof(xmlSecTransform)) : \ + (xmlSecBase64CtxPtr)NULL) -static int xmlSecBase64Initialize (xmlSecTransformPtr transform); -static void xmlSecBase64Finalize (xmlSecTransformPtr transform); -static int xmlSecBase64Execute (xmlSecTransformPtr transform, - int last, - xmlSecTransformCtxPtr transformCtx); +static int xmlSecBase64Initialize (xmlSecTransformPtr transform); +static void xmlSecBase64Finalize (xmlSecTransformPtr transform); +static int xmlSecBase64Execute (xmlSecTransformPtr transform, + int last, + xmlSecTransformCtxPtr transformCtx); static xmlSecTransformKlass xmlSecBase64Klass = { /* klass/object sizes */ - sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ - xmlSecBase64Size, /* xmlSecSize objSize */ - - xmlSecNameBase64, /* const xmlChar* name; */ - xmlSecHrefBase64, /* const xmlChar* href; */ - xmlSecTransformUsageDSigTransform, /* xmlSecAlgorithmUsage usage; */ - - xmlSecBase64Initialize, /* xmlSecTransformInitializeMethod initialize; */ - xmlSecBase64Finalize, /* xmlSecTransformFinalizeMethod finalize; */ - NULL, /* xmlSecTransformNodeReadMethod readNode; */ - NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ - NULL, /* xmlSecTransformSetKeyReqMethod setKeyReq; */ - NULL, /* xmlSecTransformSetKeyMethod setKey; */ - NULL, /* xmlSecTransformValidateMethod validate; */ - xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ - xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */ - xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */ - NULL, /* xmlSecTransformPushXmlMethod pushXml; */ - NULL, /* xmlSecTransformPopXmlMethod popXml; */ - xmlSecBase64Execute, /* xmlSecTransformExecuteMethod execute; */ - - NULL, /* void* reserved0; */ - NULL, /* void* reserved1; */ + sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ + xmlSecBase64Size, /* xmlSecSize objSize */ + + xmlSecNameBase64, /* const xmlChar* name; */ + xmlSecHrefBase64, /* const xmlChar* href; */ + xmlSecTransformUsageDSigTransform, /* xmlSecAlgorithmUsage usage; */ + + xmlSecBase64Initialize, /* xmlSecTransformInitializeMethod initialize; */ + xmlSecBase64Finalize, /* xmlSecTransformFinalizeMethod finalize; */ + NULL, /* xmlSecTransformNodeReadMethod readNode; */ + NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ + NULL, /* xmlSecTransformSetKeyReqMethod setKeyReq; */ + NULL, /* xmlSecTransformSetKeyMethod setKey; */ + NULL, /* xmlSecTransformValidateMethod validate; */ + xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ + xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */ + xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */ + NULL, /* xmlSecTransformPushXmlMethod pushXml; */ + NULL, /* xmlSecTransformPopXmlMethod popXml; */ + xmlSecBase64Execute, /* xmlSecTransformExecuteMethod execute; */ + + NULL, /* void* reserved0; */ + NULL, /* void* reserved1; */ }; /** @@ -829,42 +829,42 @@ static xmlSecTransformKlass xmlSecBase64Klass = { * * The Base64 transform klass (http://www.w3.org/TR/xmldsig-core/#sec-Base-64). * The normative specification for base64 decoding transforms is RFC 2045 - * (http://www.ietf.org/rfc/rfc2045.txt). The base64 Transform element has - * no content. The input is decoded by the algorithms. This transform is - * useful if an application needs to sign the raw data associated with + * (http://www.ietf.org/rfc/rfc2045.txt). The base64 Transform element has + * no content. The input is decoded by the algorithms. This transform is + * useful if an application needs to sign the raw data associated with * the encoded content of an element. * * Returns: base64 transform id. */ -xmlSecTransformId +xmlSecTransformId xmlSecTransformBase64GetKlass(void) { return(&xmlSecBase64Klass); } /** * xmlSecTransformBase64SetLineSize: - * @transform: the pointer to BASE64 encode transform. - * @lineSize: the new max line size. + * @transform: the pointer to BASE64 encode transform. + * @lineSize: the new max line size. * * Sets the max line size to @lineSize. */ void xmlSecTransformBase64SetLineSize(xmlSecTransformPtr transform, xmlSecSize lineSize) { xmlSecBase64CtxPtr ctx; - + xmlSecAssert(xmlSecTransformCheckId(transform, xmlSecTransformBase64Id)); - + ctx = xmlSecBase64GetCtx(transform); xmlSecAssert(ctx != NULL); - - ctx->columns = lineSize; + + ctx->columns = lineSize; } static int xmlSecBase64Initialize(xmlSecTransformPtr transform) { xmlSecBase64CtxPtr ctx; int ret; - + xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecTransformBase64Id), -1); ctx = xmlSecBase64GetCtx(transform); @@ -873,30 +873,30 @@ xmlSecBase64Initialize(xmlSecTransformPtr transform) { transform->operation = xmlSecTransformOperationDecode; ret = xmlSecBase64CtxInitialize(ctx, 0, xmlSecBase64GetDefaultLineSize()); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBase64CtxInitialize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBase64CtxInitialize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } - + return(0); } static void xmlSecBase64Finalize(xmlSecTransformPtr transform) { xmlSecBase64CtxPtr ctx; - + xmlSecAssert(xmlSecTransformCheckId(transform, xmlSecTransformBase64Id)); ctx = xmlSecBase64GetCtx(transform); xmlSecAssert(ctx != NULL); - + xmlSecBase64CtxFinalize(ctx); } -static int +static int xmlSecBase64Execute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxPtr transformCtx) { xmlSecBase64CtxPtr ctx; xmlSecBufferPtr in, out; @@ -906,127 +906,127 @@ xmlSecBase64Execute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxPt xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecTransformBase64Id), -1); xmlSecAssert2((transform->operation == xmlSecTransformOperationEncode) || (transform->operation == xmlSecTransformOperationDecode), -1); xmlSecAssert2(transformCtx != NULL, -1); - + ctx = xmlSecBase64GetCtx(transform); xmlSecAssert2(ctx != NULL, -1); - + in = &(transform->inBuf); out = &(transform->outBuf); if(transform->status == xmlSecTransformStatusNone) { - ctx->encode = (transform->operation == xmlSecTransformOperationEncode) ? 1 : 0; - transform->status = xmlSecTransformStatusWorking; + ctx->encode = (transform->operation == xmlSecTransformOperationEncode) ? 1 : 0; + transform->status = xmlSecTransformStatusWorking; } switch(transform->status) { - case xmlSecTransformStatusWorking: - inSize = xmlSecBufferGetSize(in); - outSize = xmlSecBufferGetSize(out); - if(inSize > 0) { - if(ctx->encode != 0) { - outLen = 4 * inSize / 3 + 8; - if(ctx->columns > 0) { - outLen += inSize / ctx->columns + 4; - } - } else { - outLen = 3 * inSize / 4 + 8; - } - ret = xmlSecBufferSetMaxSize(out, outSize + outLen); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBufferSetMaxSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", outSize + outLen); - return(-1); - } - - /* encode/decode the next chunk */ - ret = xmlSecBase64CtxUpdate(ctx, xmlSecBufferGetData(in), inSize, - xmlSecBufferGetData(out) + outSize, - outLen); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBase64CtxUpdate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } - outLen = ret; - - /* set correct size */ - ret = xmlSecBufferSetSize(out, outSize + outLen); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBufferSetSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", outSize + outLen); - return(-1); - } - - /* remove chunk from input */ - ret = xmlSecBufferRemoveHead(in, inSize); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBufferRemoveHead", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", inSize); - return(-1); - } - } - - if(last) { - outSize = xmlSecBufferGetSize(out); - - ret = xmlSecBufferSetMaxSize(out, outSize + 16); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBufferSetMaxSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", outSize + 16); - return(-1); - } - - /* add from ctx buffer */ - ret = xmlSecBase64CtxFinal(ctx, xmlSecBufferGetData(out) + outSize, 16); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBase64CtxFinal", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); - } - outLen = ret; - - /* set correct size */ - ret = xmlSecBufferSetSize(out, outSize + outLen); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - "xmlSecBufferSetSize", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "size=%d", outSize + outLen); - return(-1); - } - transform->status = xmlSecTransformStatusFinished; - } - break; - case xmlSecTransformStatusFinished: - /* the only way we can get here is if there is no input */ - xmlSecAssert2(xmlSecBufferGetSize(in) == 0, -1); - break; - default: - xmlSecError(XMLSEC_ERRORS_HERE, - xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), - NULL, - XMLSEC_ERRORS_R_INVALID_STATUS, - "status=%d", transform->status); - return(-1); + case xmlSecTransformStatusWorking: + inSize = xmlSecBufferGetSize(in); + outSize = xmlSecBufferGetSize(out); + if(inSize > 0) { + if(ctx->encode != 0) { + outLen = 4 * inSize / 3 + 8; + if(ctx->columns > 0) { + outLen += inSize / ctx->columns + 4; + } + } else { + outLen = 3 * inSize / 4 + 8; + } + ret = xmlSecBufferSetMaxSize(out, outSize + outLen); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBufferSetMaxSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", outSize + outLen); + return(-1); + } + + /* encode/decode the next chunk */ + ret = xmlSecBase64CtxUpdate(ctx, xmlSecBufferGetData(in), inSize, + xmlSecBufferGetData(out) + outSize, + outLen); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBase64CtxUpdate", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } + outLen = ret; + + /* set correct size */ + ret = xmlSecBufferSetSize(out, outSize + outLen); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBufferSetSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", outSize + outLen); + return(-1); + } + + /* remove chunk from input */ + ret = xmlSecBufferRemoveHead(in, inSize); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBufferRemoveHead", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", inSize); + return(-1); + } + } + + if(last) { + outSize = xmlSecBufferGetSize(out); + + ret = xmlSecBufferSetMaxSize(out, outSize + 16); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBufferSetMaxSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", outSize + 16); + return(-1); + } + + /* add from ctx buffer */ + ret = xmlSecBase64CtxFinal(ctx, xmlSecBufferGetData(out) + outSize, 16); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBase64CtxFinal", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); + } + outLen = ret; + + /* set correct size */ + ret = xmlSecBufferSetSize(out, outSize + outLen); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + "xmlSecBufferSetSize", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "size=%d", outSize + outLen); + return(-1); + } + transform->status = xmlSecTransformStatusFinished; + } + break; + case xmlSecTransformStatusFinished: + /* the only way we can get here is if there is no input */ + xmlSecAssert2(xmlSecBufferGetSize(in) == 0, -1); + break; + default: + xmlSecError(XMLSEC_ERRORS_HERE, + xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), + NULL, + XMLSEC_ERRORS_R_INVALID_STATUS, + "status=%d", transform->status); + return(-1); } return(0); } |