crypt32: Use an empty string as a separator when no separator is desired to avoid special cases for NULL.
This commit is contained in:
parent
b8c7dec6b8
commit
7eb61a6e5c
@ -99,7 +99,6 @@ static LONG encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep,
|
|||||||
|
|
||||||
TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
|
TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
|
||||||
needed = bytes + pad_bytes + 1;
|
needed = bytes + pad_bytes + 1;
|
||||||
if (sep)
|
|
||||||
needed += (needed / 64 + 1) * strlen(sep);
|
needed += (needed / 64 + 1) * strlen(sep);
|
||||||
|
|
||||||
if (needed > *out_len)
|
if (needed > *out_len)
|
||||||
@ -117,7 +116,7 @@ static LONG encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep,
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (div > 0)
|
while (div > 0)
|
||||||
{
|
{
|
||||||
if (sep && i && i % 64 == 0)
|
if (i && i % 64 == 0)
|
||||||
{
|
{
|
||||||
strcpy(ptr, sep);
|
strcpy(ptr, sep);
|
||||||
ptr += strlen(sep);
|
ptr += strlen(sep);
|
||||||
@ -163,7 +162,6 @@ static LONG encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep,
|
|||||||
*ptr++ = '=';
|
*ptr++ = '=';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (sep)
|
|
||||||
strcpy(ptr, sep);
|
strcpy(ptr, sep);
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
@ -180,7 +178,7 @@ static BOOL BinaryToBase64A(const BYTE *pbBinary,
|
|||||||
if (dwFlags & CRYPT_STRING_NOCR)
|
if (dwFlags & CRYPT_STRING_NOCR)
|
||||||
sep = lf;
|
sep = lf;
|
||||||
else if (dwFlags & CRYPT_STRING_NOCRLF)
|
else if (dwFlags & CRYPT_STRING_NOCRLF)
|
||||||
sep = NULL;
|
sep = "";
|
||||||
else
|
else
|
||||||
sep = crlf;
|
sep = crlf;
|
||||||
switch (dwFlags & 0x0fffffff)
|
switch (dwFlags & 0x0fffffff)
|
||||||
@ -217,24 +215,18 @@ static BOOL BinaryToBase64A(const BYTE *pbBinary,
|
|||||||
{
|
{
|
||||||
strcpy(ptr, header);
|
strcpy(ptr, header);
|
||||||
ptr += strlen(ptr);
|
ptr += strlen(ptr);
|
||||||
if (sep)
|
|
||||||
{
|
|
||||||
strcpy(ptr, sep);
|
strcpy(ptr, sep);
|
||||||
ptr += strlen(sep);
|
ptr += strlen(sep);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
encodeBase64A(pbBinary, cbBinary, sep, ptr, &size);
|
encodeBase64A(pbBinary, cbBinary, sep, ptr, &size);
|
||||||
ptr += size - 1;
|
ptr += size - 1;
|
||||||
if (trailer)
|
if (trailer)
|
||||||
{
|
{
|
||||||
strcpy(ptr, trailer);
|
strcpy(ptr, trailer);
|
||||||
ptr += strlen(ptr);
|
ptr += strlen(ptr);
|
||||||
if (sep)
|
|
||||||
{
|
|
||||||
strcpy(ptr, sep);
|
strcpy(ptr, sep);
|
||||||
ptr += strlen(sep);
|
ptr += strlen(sep);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*pcchString = charsNeeded - 1;
|
*pcchString = charsNeeded - 1;
|
||||||
}
|
}
|
||||||
else if (pszString)
|
else if (pszString)
|
||||||
@ -302,7 +294,6 @@ static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
|
|||||||
|
|
||||||
TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
|
TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
|
||||||
needed = bytes + pad_bytes + 1;
|
needed = bytes + pad_bytes + 1;
|
||||||
if (sep)
|
|
||||||
needed += (needed / 64 + 1) * strlenW(sep);
|
needed += (needed / 64 + 1) * strlenW(sep);
|
||||||
|
|
||||||
if (needed > *out_len)
|
if (needed > *out_len)
|
||||||
@ -320,7 +311,7 @@ static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (div > 0)
|
while (div > 0)
|
||||||
{
|
{
|
||||||
if (sep && i && i % 64 == 0)
|
if (i && i % 64 == 0)
|
||||||
{
|
{
|
||||||
strcpyW(ptr, sep);
|
strcpyW(ptr, sep);
|
||||||
ptr += strlenW(sep);
|
ptr += strlenW(sep);
|
||||||
@ -366,7 +357,6 @@ static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
|
|||||||
*ptr++ = '=';
|
*ptr++ = '=';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (sep)
|
|
||||||
strcpyW(ptr, sep);
|
strcpyW(ptr, sep);
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
@ -375,7 +365,7 @@ static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
|
|||||||
static BOOL BinaryToBase64W(const BYTE *pbBinary,
|
static BOOL BinaryToBase64W(const BYTE *pbBinary,
|
||||||
DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
|
DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
|
||||||
{
|
{
|
||||||
static const WCHAR crlf[] = { '\r','\n',0 }, lf[] = { '\n',0 };
|
static const WCHAR crlf[] = { '\r','\n',0 }, lf[] = { '\n',0 }, empty = {0};
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
LPCWSTR header = NULL, trailer = NULL, sep;
|
LPCWSTR header = NULL, trailer = NULL, sep;
|
||||||
DWORD charsNeeded;
|
DWORD charsNeeded;
|
||||||
@ -383,7 +373,7 @@ static BOOL BinaryToBase64W(const BYTE *pbBinary,
|
|||||||
if (dwFlags & CRYPT_STRING_NOCR)
|
if (dwFlags & CRYPT_STRING_NOCR)
|
||||||
sep = lf;
|
sep = lf;
|
||||||
else if (dwFlags & CRYPT_STRING_NOCRLF)
|
else if (dwFlags & CRYPT_STRING_NOCRLF)
|
||||||
sep = NULL;
|
sep = empty;
|
||||||
else
|
else
|
||||||
sep = crlf;
|
sep = crlf;
|
||||||
switch (dwFlags & 0x0fffffff)
|
switch (dwFlags & 0x0fffffff)
|
||||||
@ -420,24 +410,18 @@ static BOOL BinaryToBase64W(const BYTE *pbBinary,
|
|||||||
{
|
{
|
||||||
strcpyW(ptr, header);
|
strcpyW(ptr, header);
|
||||||
ptr += strlenW(ptr);
|
ptr += strlenW(ptr);
|
||||||
if (sep)
|
|
||||||
{
|
|
||||||
strcpyW(ptr, sep);
|
strcpyW(ptr, sep);
|
||||||
ptr += strlenW(sep);
|
ptr += strlenW(sep);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
encodeBase64W(pbBinary, cbBinary, sep, ptr, &size);
|
encodeBase64W(pbBinary, cbBinary, sep, ptr, &size);
|
||||||
ptr += size - 1;
|
ptr += size - 1;
|
||||||
if (trailer)
|
if (trailer)
|
||||||
{
|
{
|
||||||
strcpyW(ptr, trailer);
|
strcpyW(ptr, trailer);
|
||||||
ptr += strlenW(ptr);
|
ptr += strlenW(ptr);
|
||||||
if (sep)
|
|
||||||
{
|
|
||||||
strcpyW(ptr, sep);
|
strcpyW(ptr, sep);
|
||||||
ptr += strlenW(sep);
|
ptr += strlenW(sep);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*pcchString = charsNeeded - 1;
|
*pcchString = charsNeeded - 1;
|
||||||
}
|
}
|
||||||
else if (pszString)
|
else if (pszString)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user