summaryrefslogtreecommitdiff
path: root/comphelper/source/misc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-06-27 00:39:34 +0200
committerTomaž Vajngerl <quikee@gmail.com>2018-07-06 18:25:49 +0200
commit0d0bf4132d7cf81306a3de6592fce40ab69ef040 (patch)
tree124be65dcdc8652d640729959d299b2e2858bac8 /comphelper/source/misc
parentfc434c8fd62ccb6d083af075f1ab83da6bd76b8d (diff)
base64: change impl. of encodig to also work with OStringBuffer
+ make test simpler and add a test case for the new behaviour Change-Id: Ifc743835f0cd634c79929ce22dc36b5a822a7e88 Reviewed-on: https://gerrit.libreoffice.org/56969 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'comphelper/source/misc')
-rw-r--r--comphelper/source/misc/base64.cxx32
1 files changed, 23 insertions, 9 deletions
diff --git a/comphelper/source/misc/base64.cxx b/comphelper/source/misc/base64.cxx
index e7f20cdfa693..4e3a6bc6ef00 100644
--- a/comphelper/source/misc/base64.cxx
+++ b/comphelper/source/misc/base64.cxx
@@ -21,7 +21,6 @@
#include <com/sun/star/uno/Sequence.hxx>
-#include <rtl/ustrbuf.hxx>
#include <rtl/math.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
@@ -61,7 +60,7 @@ const
// p q r s t u v w x y z
-void ThreeByteToFourByte(const sal_Int8* pBuffer, const sal_Int32 nStart, const sal_Int32 nFullLen, OUStringBuffer& sBuffer)
+void ThreeByteToFourByte(const sal_Int8* pBuffer, const sal_Int32 nStart, const sal_Int32 nFullLen, sal_Char* aCharBuffer)
{
sal_Int32 nLen(nFullLen - nStart);
if (nLen > 3)
@@ -94,24 +93,37 @@ void ThreeByteToFourByte(const sal_Int8* pBuffer, const sal_Int32 nStart, const
break;
}
- sal_Unicode buf[] = { '=', '=', '=', '=' };
+ aCharBuffer[0] = aCharBuffer[1] = aCharBuffer[2] = aCharBuffer[3] = '=';
sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinaer & 0xFC0000) >> 18));
- buf[0] = aBase64EncodeTable [nIndex];
+ aCharBuffer[0] = aBase64EncodeTable [nIndex];
nIndex = static_cast<sal_uInt8>((nBinaer & 0x3F000) >> 12);
- buf[1] = aBase64EncodeTable [nIndex];
+ aCharBuffer[1] = aBase64EncodeTable [nIndex];
if (nLen > 1)
{
nIndex = static_cast<sal_uInt8>((nBinaer & 0xFC0) >> 6);
- buf[2] = aBase64EncodeTable [nIndex];
+ aCharBuffer[2] = aBase64EncodeTable [nIndex];
if (nLen > 2)
{
nIndex = static_cast<sal_uInt8>((nBinaer & 0x3F));
- buf[3] = aBase64EncodeTable [nIndex];
+ aCharBuffer[3] = aBase64EncodeTable [nIndex];
}
}
- sBuffer.append(buf, SAL_N_ELEMENTS(buf));
+}
+
+void Base64::encode(OStringBuffer& aStrBuffer, const uno::Sequence<sal_Int8>& aPass)
+{
+ sal_Int32 i(0);
+ sal_Int32 nBufferLength(aPass.getLength());
+ const sal_Int8* pBuffer = aPass.getConstArray();
+ while (i < nBufferLength)
+ {
+ sal_Char aCharBuffer[4];
+ ThreeByteToFourByte(pBuffer, i, nBufferLength, aCharBuffer);
+ aStrBuffer.append(aCharBuffer, SAL_N_ELEMENTS(aCharBuffer));
+ i += 3;
+ }
}
void Base64::encode(OUStringBuffer& aStrBuffer, const uno::Sequence<sal_Int8>& aPass)
@@ -121,7 +133,9 @@ void Base64::encode(OUStringBuffer& aStrBuffer, const uno::Sequence<sal_Int8>& a
const sal_Int8* pBuffer = aPass.getConstArray();
while (i < nBufferLength)
{
- ThreeByteToFourByte(pBuffer, i, nBufferLength, aStrBuffer);
+ sal_Char aCharBuffer[4];
+ ThreeByteToFourByte(pBuffer, i, nBufferLength, aCharBuffer);
+ aStrBuffer.appendAscii(aCharBuffer, SAL_N_ELEMENTS(aCharBuffer));
i += 3;
}
}