static xmlSecBase64Status xmlSecBase64CtxEncodeByteFinal(xmlSecBase64CtxPtr ctx, xmlSecByte* outByte) { xmlSecAssert2(ctx != NULL, xmlSecBase64StatusFailed); xmlSecAssert2(outByte != NULL, xmlSecBase64StatusFailed); if(ctx->inPos == 0) { return(xmlSecBase64StatusDone); } else if((ctx->columns > 0) && (ctx->linePos >= ctx->columns)) { (*outByte) = '\n'; ctx->linePos = 0; return(xmlSecBase64StatusConsumeAndRepeat); } else if(ctx->finished == 0) { ctx->finished = 1; return(xmlSecBase64CtxEncodeByte(ctx, 0, outByte)); } else if(ctx->inPos < 3) { (*outByte) = '='; ++ctx->inPos; ++ctx->linePos; return(xmlSecBase64StatusConsumeAndRepeat); } else if(ctx->inPos == 3) { (*outByte) = '='; ++ctx->linePos; ctx->inPos = 0; return(xmlSecBase64StatusConsumeAndRepeat); } xmlSecErr_a_ignorar6(XMLSEC_ERRORS_HERE, NULL, NULL, XMLSEC_ERRORS_R_INVALID_DATA, "ctx->inPos=%d", ctx->inPos); return(xmlSecBase64StatusFailed); }
static xmlSecBase64Status xmlSecBase64CtxEncodeByteFinal(xmlSecBase64CtxPtr ctx, xmlSecByte* outByte) { xmlSecAssert2(ctx != NULL, xmlSecBase64StatusFailed); xmlSecAssert2(outByte != NULL, xmlSecBase64StatusFailed); if(ctx->inPos == 0) { return(xmlSecBase64StatusDone); } else if((ctx->columns > 0) && (ctx->linePos >= ctx->columns)) { (*outByte) = '\n'; ctx->linePos = 0; return(xmlSecBase64StatusConsumeAndRepeat); } else if(ctx->finished == 0) { ctx->finished = 1; return(xmlSecBase64CtxEncodeByte(ctx, 0, outByte)); } else if(ctx->inPos < 3) { (*outByte) = '='; ++ctx->inPos; ++ctx->linePos; return(xmlSecBase64StatusConsumeAndRepeat); } else if(ctx->inPos == 3) { (*outByte) = '='; ++ctx->linePos; ctx->inPos = 0; return(xmlSecBase64StatusConsumeAndRepeat); } xmlSecInvalidIntegerDataError("ctx->inPos", ctx->inPos, "0,1,2,3", NULL); return(xmlSecBase64StatusFailed); }
static int 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); xmlSecAssert2(outBuf != NULL, -1); xmlSecAssert2(outBufResSize != NULL, -1); /* encode */ for(inPos = outPos = 0; (inPos < inBufSize) && (outPos < outBufSize); ) { status = xmlSecBase64CtxEncodeByte(ctx, inBuf[inPos], &(outBuf[outPos])); switch(status) { case xmlSecBase64StatusConsumeAndNext: ++inPos; ++outPos; break; case xmlSecBase64StatusConsumeAndRepeat: ++outPos; break; case xmlSecBase64StatusNext: case xmlSecBase64StatusDone: case xmlSecBase64StatusFailed: xmlSecErr_a_ignorar6(XMLSEC_ERRORS_HERE, NULL, "xmlSecBase64CtxEncodeByte", XMLSEC_ERRORS_R_XMLSEC_FAILED, "status=%d", status); return(-1); } } (*inBufResSize) = inPos; (*outBufResSize) = outPos; return(0); }