예제 #1
0
파일: FUBase64.cpp 프로젝트: Marlinc/0ad
	FCOLLADA_EXPORT void encode(const UInt8List& input, UInt8List& output)
	{
		output.clear();
		if (input.size() == 0) return;

		const uint8* inputBuffer = &input.at(0);
		size_t p_inputbufferLength = input.size();

		output.resize(CalculateRecquiredEncodeOutputBufferSize(input.size()), 0);
		uint8* outputBufferString = &output.at(0);

		size_t inputBufferIndex = 0;
		size_t outputBufferIndex = 0;

		while (inputBufferIndex < p_inputbufferLength)
		{
			if (p_inputbufferLength - inputBufferIndex <= 2)
			{
				EncodeByteTriple(inputBuffer + inputBufferIndex, p_inputbufferLength - inputBufferIndex, outputBufferString + outputBufferIndex);
				break;
			}
			else
			{
				EncodeByteTriple(inputBuffer + inputBufferIndex, 3, outputBufferString + outputBufferIndex);
				inputBufferIndex += 3;
				outputBufferIndex += 4;
			}
		}
	}
예제 #2
0
파일: FUBase64.cpp 프로젝트: Marlinc/0ad
	FCOLLADA_EXPORT void decode(const UInt8List& input, UInt8List& output)
	{
		size_t inputBufferIndex  = 0;
		size_t outputBufferIndex = 0;

		const uint8* inputBufferString = &input.at(0);
		size_t inputbufferLength = input.size();

		output.clear();
		output.resize(CalculateRecquiredDecodeOutputBufferSize(inputBufferString, inputbufferLength), 0);
		uint8* outputBuffer = &output.at(0);

		uint8 byteQuartet[4];

		while (inputBufferIndex < inputbufferLength)
		{
			for (int i = 0; i < 4; ++i)
			{
				byteQuartet[i] = inputBufferString[inputBufferIndex];

				// Ignore all characters except the ones in BASE64_ALPHABET
				if ((byteQuartet[i] >= 48 && byteQuartet[i] <=  57) ||
					(byteQuartet[i] >= 65 && byteQuartet[i] <=  90) ||
					(byteQuartet[i] >= 97 && byteQuartet[i] <= 122) ||
					 byteQuartet[i] == '+' || byteQuartet[i] == '/' || byteQuartet[i] == '=')
				{}
				else
				{
					// Invalid character
					--i;
				}

				++inputBufferIndex;
			}

			outputBufferIndex += DecodebyteQuartet(byteQuartet, outputBuffer + outputBufferIndex);
		}
	}