Juan Lang : crypt32: Add base implementation of CryptFormatObject.
Alexandre Julliard
julliard at winehq.org
Fri Nov 7 07:23:55 CST 2008
Module: wine
Branch: master
Commit: ba7705ea950a61402b6d76a307a1f6d12acdb9a7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=ba7705ea950a61402b6d76a307a1f6d12acdb9a7
Author: Juan Lang <juan.lang at gmail.com>
Date: Fri Oct 31 09:32:31 2008 -0700
crypt32: Add base implementation of CryptFormatObject.
---
dlls/crypt32/main.c | 10 ------
dlls/crypt32/object.c | 80 +++++++++++++++++++++++++++++++++++++++++++++
dlls/crypt32/tests/main.c | 4 --
3 files changed, 80 insertions(+), 14 deletions(-)
diff --git a/dlls/crypt32/main.c b/dlls/crypt32/main.c
index 922dd19..47ce23e 100644
--- a/dlls/crypt32/main.c
+++ b/dlls/crypt32/main.c
@@ -243,13 +243,3 @@ ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
FIXME("(%08x): stub\n", x);
return NULL;
}
-
-BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
- DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
- const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
-{
- FIXME("(%08x, %d, %d, %p, %s, %p, %d, %p, %p): stub\n",
- dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
- debugstr_a(lpszStructType), pbEncoded, cbEncoded, pbFormat, pcbFormat);
- return FALSE;
-}
diff --git a/dlls/crypt32/object.c b/dlls/crypt32/object.c
index 05a6c5f..e9590a8 100644
--- a/dlls/crypt32/object.c
+++ b/dlls/crypt32/object.c
@@ -23,6 +23,7 @@
#include "wincrypt.h"
#include "mssip.h"
#include "crypt32_private.h"
+#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
@@ -548,3 +549,82 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject,
TRACE("returning %d\n", ret);
return ret;
}
+
+static BOOL WINAPI CRYPT_FormatHexString(DWORD dwCertEncodingType,
+ DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
+ LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
+ DWORD *pcbFormat)
+{
+ BOOL ret;
+ DWORD bytesNeeded;
+
+ if (cbEncoded)
+ bytesNeeded = (cbEncoded * 3) * sizeof(WCHAR);
+ else
+ bytesNeeded = sizeof(WCHAR);
+ if (!pbFormat)
+ {
+ *pcbFormat = bytesNeeded;
+ ret = TRUE;
+ }
+ else if (*pcbFormat < bytesNeeded)
+ {
+ *pcbFormat = bytesNeeded;
+ SetLastError(ERROR_MORE_DATA);
+ ret = FALSE;
+ }
+ else
+ {
+ static const WCHAR fmt[] = { '%','0','2','x',' ',0 };
+ static const WCHAR endFmt[] = { '%','0','2','x',0 };
+ DWORD i;
+ LPWSTR ptr = pbFormat;
+
+ *pcbFormat = bytesNeeded;
+ if (cbEncoded)
+ {
+ for (i = 0; i < cbEncoded; i++)
+ {
+ if (i < cbEncoded - 1)
+ ptr += sprintfW(ptr, fmt, pbEncoded[i]);
+ else
+ ptr += sprintfW(ptr, endFmt, pbEncoded[i]);
+ }
+ }
+ else
+ *ptr = 0;
+ ret = TRUE;
+ }
+ return ret;
+}
+
+typedef BOOL (WINAPI *CryptFormatObjectFunc)(DWORD, DWORD, DWORD, void *,
+ LPCSTR, const BYTE *, DWORD, void *, DWORD *);
+
+BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
+ DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
+ const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
+{
+ static HCRYPTOIDFUNCSET set = NULL;
+ CryptFormatObjectFunc format = NULL;
+ HCRYPTOIDFUNCADDR hFunc = NULL;
+ BOOL ret = FALSE;
+
+ TRACE("(%08x, %d, %08x, %p, %s, %p, %d, %p, %p)\n", dwCertEncodingType,
+ dwFormatType, dwFormatStrType, pFormatStruct, debugstr_a(lpszStructType),
+ pbEncoded, cbEncoded, pbFormat, pcbFormat);
+
+ if (!set)
+ set = CryptInitOIDFunctionSet(CRYPT_OID_FORMAT_OBJECT_FUNC, 0);
+ CryptGetOIDFunctionAddress(set, dwCertEncodingType, lpszStructType, 0,
+ (void **)&format, &hFunc);
+ if (!format && !(dwFormatStrType & CRYPT_FORMAT_STR_NO_HEX))
+ format = CRYPT_FormatHexString;
+ if (format)
+ ret = format(dwCertEncodingType, dwFormatType, dwFormatStrType,
+ pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat,
+ pcbFormat);
+ if (hFunc)
+ CryptFreeOIDFunctionAddress(hFunc, 0);
+ return ret;
+}
diff --git a/dlls/crypt32/tests/main.c b/dlls/crypt32/tests/main.c
index 06276ba..fa50327 100644
--- a/dlls/crypt32/tests/main.c
+++ b/dlls/crypt32/tests/main.c
@@ -414,7 +414,6 @@ static void test_format_object(void)
SetLastError(0xdeadbeef);
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0,
NULL, &size);
- todo_wine
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
if (ret)
{
@@ -435,7 +434,6 @@ static void test_format_object(void)
}
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedInt,
sizeof(encodedInt), NULL, &size);
- todo_wine
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
if (ret)
{
@@ -448,7 +446,6 @@ static void test_format_object(void)
}
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL,
encodedBigInt, sizeof(encodedBigInt), NULL, &size);
- todo_wine
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
if (ret)
{
@@ -466,7 +463,6 @@ static void test_format_object(void)
SetLastError(0xdeadbeef);
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, CRYPT_FORMAT_STR_NO_HEX,
NULL, NULL, NULL, 0, NULL, &size);
- todo_wine
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
"expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
/* When called to format an AUTHORITY_KEY_ID2_INFO, it fails when no
More information about the wine-cvs
mailing list