| 3445 | } |
| 3446 | |
| 3447 | static void fxUint8ArrayFromBase64(txMachine* the, txU1* srcStart, txU1* dstStart, txSize* read, txSize* written, txU1* alphabet, txInteger lastChunkHandling) |
| 3448 | { |
| 3449 | txU1* src = srcStart; |
| 3450 | txU1* dst = dstStart; |
| 3451 | txSize remaining = *written; |
| 3452 | txBoolean url = (alphabet == (txU1*)gxBase64URLAlphabet) ? 1 : 0, done = 0; |
| 3453 | txU1 byte, buffer[4]; |
| 3454 | txSize bufferIndex, bufferLength = 0; |
| 3455 | |
| 3456 | if (remaining == 0) { |
| 3457 | *read = 0; |
| 3458 | return; |
| 3459 | } |
| 3460 | for (;;) { |
| 3461 | byte = fxSkipAsciiWhitespace(&src); |
| 3462 | if (byte == 0) { |
| 3463 | if (bufferLength == 0) |
| 3464 | break; |
| 3465 | if (lastChunkHandling == mxBase64StopBeforePartial) |
| 3466 | break; |
| 3467 | if ((lastChunkHandling == mxBase64Strict) || (bufferLength == 1)) |
| 3468 | mxSyntaxError("invalid string"); |
| 3469 | if (bufferLength == 2) |
| 3470 | buffer[2] = 0; |
| 3471 | buffer[3] = 0; |
| 3472 | done = 1; |
| 3473 | } |
| 3474 | else if (byte == '=') { |
| 3475 | if (bufferLength < 2) |
| 3476 | mxSyntaxError("invalid string"); |
| 3477 | src++; |
| 3478 | byte = fxSkipAsciiWhitespace(&src); |
| 3479 | if (bufferLength == 2) { |
| 3480 | if (byte == 0) { |
| 3481 | if (lastChunkHandling == mxBase64StopBeforePartial) |
| 3482 | break; |
| 3483 | mxSyntaxError("invalid string"); |
| 3484 | } |
| 3485 | if (byte == '=') { |
| 3486 | src++; |
| 3487 | byte = fxSkipAsciiWhitespace(&src); |
| 3488 | } |
| 3489 | buffer[2] = 0; |
| 3490 | } |
| 3491 | if (byte != 0) |
| 3492 | mxSyntaxError("invalid string"); |
| 3493 | buffer[3] = 0; |
| 3494 | done = 1; |
| 3495 | } |
| 3496 | else { |
| 3497 | if (('A' <= byte) && (byte <= 'Z')) |
| 3498 | byte = byte - 'A'; |
| 3499 | else if (('a' <= byte) && (byte <= 'z')) |
| 3500 | byte = byte - 'a' + 26; |
| 3501 | else if (('0' <= byte) && (byte <= '9')) |
| 3502 | byte = byte - '0' + 52; |
| 3503 | else if ((byte == '+') && !url) |
| 3504 | byte = 62; |
no test coverage detected