crypt32: Add support for the CRYPT_STRING_NOCRLF flag to CryptBinaryToStringA/W.

This commit is contained in:
Juan Lang 2009-10-29 15:43:37 -07:00 committed by Alexandre Julliard
parent 2d5ac92d9a
commit fc0aff0d2e
2 changed files with 47 additions and 24 deletions

View File

@ -99,6 +99,7 @@ static LONG encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep,
TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
needed = bytes + pad_bytes + 1;
if (sep)
needed += (needed / 64 + 1) * strlen(sep);
if (needed > *out_len)
@ -116,7 +117,7 @@ static LONG encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep,
i = 0;
while (div > 0)
{
if (i && i % 64 == 0)
if (sep && i && i % 64 == 0)
{
strcpy(ptr, sep);
ptr += strlen(sep);
@ -162,6 +163,7 @@ static LONG encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep,
*ptr++ = '=';
break;
}
if (sep)
strcpy(ptr, sep);
return ERROR_SUCCESS;
@ -172,14 +174,16 @@ static BOOL BinaryToBase64A(const BYTE *pbBinary,
{
static const char crlf[] = "\r\n", lf[] = "\n";
BOOL ret = TRUE;
LPCSTR header = NULL, trailer = NULL, sep = NULL;
LPCSTR header = NULL, trailer = NULL, sep;
DWORD charsNeeded;
if (dwFlags & CRYPT_STRING_NOCR)
sep = lf;
else if (dwFlags & CRYPT_STRING_NOCRLF)
sep = NULL;
else
sep = crlf;
switch (dwFlags & 0x7fffffff)
switch (dwFlags & 0x0fffffff)
{
case CRYPT_STRING_BASE64:
/* no header or footer */
@ -200,6 +204,7 @@ static BOOL BinaryToBase64A(const BYTE *pbBinary,
charsNeeded = 0;
encodeBase64A(pbBinary, cbBinary, sep, NULL, &charsNeeded);
if (sep)
charsNeeded += strlen(sep);
if (header)
charsNeeded += strlen(header) + strlen(sep);
@ -214,18 +219,24 @@ static BOOL BinaryToBase64A(const BYTE *pbBinary,
{
strcpy(ptr, header);
ptr += strlen(ptr);
if (sep)
{
strcpy(ptr, sep);
ptr += strlen(sep);
}
}
encodeBase64A(pbBinary, cbBinary, sep, ptr, &size);
ptr += size - 1;
if (trailer)
{
strcpy(ptr, trailer);
ptr += strlen(ptr);
if (sep)
{
strcpy(ptr, sep);
ptr += strlen(sep);
}
}
*pcchString = charsNeeded - 1;
}
else if (pszString)
@ -258,7 +269,7 @@ BOOL WINAPI CryptBinaryToStringA(const BYTE *pbBinary,
return FALSE;
}
switch (dwFlags & 0x7fffffff)
switch (dwFlags & 0x0fffffff)
{
case CRYPT_STRING_BINARY:
encoder = EncodeBinaryToBinaryA;
@ -273,7 +284,7 @@ BOOL WINAPI CryptBinaryToStringA(const BYTE *pbBinary,
case CRYPT_STRING_HEXASCII:
case CRYPT_STRING_HEXADDR:
case CRYPT_STRING_HEXASCIIADDR:
FIXME("Unimplemented type %d\n", dwFlags & 0x7fffffff);
FIXME("Unimplemented type %d\n", dwFlags & 0x0fffffff);
/* fall through */
default:
SetLastError(ERROR_INVALID_PARAMETER);
@ -293,6 +304,7 @@ static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
needed = bytes + pad_bytes + 1;
if (sep)
needed += (needed / 64 + 1) * strlenW(sep);
if (needed > *out_len)
@ -310,7 +322,7 @@ static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
i = 0;
while (div > 0)
{
if (i && i % 64 == 0)
if (sep && i && i % 64 == 0)
{
strcpyW(ptr, sep);
ptr += strlenW(sep);
@ -356,6 +368,7 @@ static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
*ptr++ = '=';
break;
}
if (sep)
strcpyW(ptr, sep);
return ERROR_SUCCESS;
@ -366,14 +379,16 @@ static BOOL BinaryToBase64W(const BYTE *pbBinary,
{
static const WCHAR crlf[] = { '\r','\n',0 }, lf[] = { '\n',0 };
BOOL ret = TRUE;
LPCWSTR header = NULL, trailer = NULL, sep = NULL;
LPCWSTR header = NULL, trailer = NULL, sep;
DWORD charsNeeded;
if (dwFlags & CRYPT_STRING_NOCR)
sep = lf;
else if (dwFlags & CRYPT_STRING_NOCRLF)
sep = NULL;
else
sep = crlf;
switch (dwFlags & 0x7fffffff)
switch (dwFlags & 0x0fffffff)
{
case CRYPT_STRING_BASE64:
/* no header or footer */
@ -394,6 +409,7 @@ static BOOL BinaryToBase64W(const BYTE *pbBinary,
charsNeeded = 0;
encodeBase64W(pbBinary, cbBinary, sep, NULL, &charsNeeded);
if (sep)
charsNeeded += strlenW(sep);
if (header)
charsNeeded += strlenW(header) + strlenW(sep);
@ -408,18 +424,24 @@ static BOOL BinaryToBase64W(const BYTE *pbBinary,
{
strcpyW(ptr, header);
ptr += strlenW(ptr);
if (sep)
{
strcpyW(ptr, sep);
ptr += strlenW(sep);
}
}
encodeBase64W(pbBinary, cbBinary, sep, ptr, &size);
ptr += size - 1;
if (trailer)
{
strcpyW(ptr, trailer);
ptr += strlenW(ptr);
if (sep)
{
strcpyW(ptr, sep);
ptr += strlenW(sep);
}
}
*pcchString = charsNeeded - 1;
}
else if (pszString)
@ -452,7 +474,7 @@ BOOL WINAPI CryptBinaryToStringW(const BYTE *pbBinary,
return FALSE;
}
switch (dwFlags & 0x7fffffff)
switch (dwFlags & 0x0fffffff)
{
case CRYPT_STRING_BASE64:
case CRYPT_STRING_BASE64HEADER:
@ -465,7 +487,7 @@ BOOL WINAPI CryptBinaryToStringW(const BYTE *pbBinary,
case CRYPT_STRING_HEXASCII:
case CRYPT_STRING_HEXADDR:
case CRYPT_STRING_HEXASCIIADDR:
FIXME("Unimplemented type %d\n", dwFlags & 0x7fffffff);
FIXME("Unimplemented type %d\n", dwFlags & 0x0fffffff);
/* fall through */
default:
SetLastError(ERROR_INVALID_PARAMETER);

View File

@ -2750,6 +2750,7 @@ typedef struct _CTL_FIND_SUBJECT_PARA
#define CRYPT_STRING_BASE64X509CRLHEADER 0x00000009
#define CRYPT_STRING_HEXADDR 0x0000000a
#define CRYPT_STRING_HEXASCIIADDR 0x0000000b
#define CRYPT_STRING_NOCRLF 0x40000000
#define CRYPT_STRING_NOCR 0x80000000
/* OIDs */