Implement CryptMem and undocumented I_Crypt*Tls functions, with tests.

oldstable
Juan Lang 2005-10-27 10:24:20 +00:00 committed by Alexandre Julliard
parent 473cac840b
commit c534fa1e82
4 changed files with 155 additions and 7 deletions

View File

@ -120,9 +120,9 @@
@ stdcall CryptInitOIDFunctionSet(str long)
@ stub CryptInstallOIDFunctionAddress
@ stub CryptLoadSip
@ stub CryptMemAlloc
@ stub CryptMemFree
@ stub CryptMemRealloc
@ stdcall CryptMemAlloc(long)
@ stdcall CryptMemFree(ptr)
@ stdcall CryptMemRealloc(ptr long)
@ stub CryptMsgCalculateEncodedLength
@ stub CryptMsgClose
@ stub CryptMsgControl
@ -164,21 +164,22 @@
@ stub CryptVerifyMessageSignature
@ stub CryptVerifyMessageSignatureWithKey
@ stub CryptVerifySignatureU
@ stub I_CryptAllocTls
@ stdcall I_CryptAllocTls()
@ stdcall I_CryptCreateLruCache(long long)
@ stub I_CryptCreateLruEntry
@ stub I_CryptDetachTls
@ stdcall I_CryptDetachTls(long)
@ stdcall I_CryptFindLruEntryData(long)
@ stdcall I_CryptFlushLruCache(long)
@ stdcall I_CryptFreeLruCache(long)
@ stdcall I_CryptFreeTls(long long)
@ stub I_CryptGetDefaultCryptProv
@ stub I_CryptGetDefaultCryptProvForEncrypt
@ stub I_CryptGetOssGlobal
@ stub I_CryptGetTls
@ stdcall I_CryptGetTls(long)
@ stub I_CryptInsertLruEntry
@ stub I_CryptInstallOssGlobal
@ stub I_CryptReleaseLruEntry
@ stub I_CryptSetTls
@ stdcall I_CryptSetTls(long ptr)
@ stub I_CryptUninstallOssGlobal
@ stub PFXExportCertStore
@ stub PFXImportCertStore

View File

@ -304,3 +304,48 @@ DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
}
return 0;
}
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
{
return HeapAlloc(GetProcessHeap(), 0, cbSize);
}
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
{
return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
}
VOID WINAPI CryptMemFree(LPVOID pv)
{
HeapFree(GetProcessHeap(), 0, pv);
}
DWORD WINAPI I_CryptAllocTls(void)
{
return TlsAlloc();
}
LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
{
LPVOID ret;
ret = TlsGetValue(dwTlsIndex);
TlsSetValue(dwTlsIndex, NULL);
return ret;
}
LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
{
return TlsGetValue(dwTlsIndex);
}
BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
{
return TlsSetValue(dwTlsIndex, lpTlsValue);
}
BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
{
TRACE("(%ld, %ld)\n", dwTlsIndex, unknown);
return TlsFree(dwTlsIndex);
}

View File

@ -274,6 +274,102 @@ static void test_verifyTimeValidity(void)
ok(ret == -1, "Expected -1, got %ld\n", ret);
}
static void test_cryptAllocate(void)
{
LPVOID buf;
buf = CryptMemAlloc(0);
ok(buf != NULL, "CryptMemAlloc failed: %08lx\n", GetLastError());
CryptMemFree(buf);
buf = CryptMemRealloc(NULL, 0);
ok(!buf, "Expected NULL\n");
buf = CryptMemAlloc(0);
buf = CryptMemRealloc(buf, 1);
ok(buf != NULL, "CryptMemRealloc failed: %08lx\n", GetLastError());
CryptMemFree(buf);
}
typedef DWORD (WINAPI *I_CryptAllocTlsFunc)(void);
typedef LPVOID (WINAPI *I_CryptDetachTlsFunc)(DWORD dwTlsIndex);
typedef LPVOID (WINAPI *I_CryptGetTlsFunc)(DWORD dwTlsIndex);
typedef BOOL (WINAPI *I_CryptSetTlsFunc)(DWORD dwTlsIndex, LPVOID lpTlsValue);
typedef BOOL (WINAPI *I_CryptFreeTlsFunc)(DWORD dwTlsIndex, DWORD unknown);
static I_CryptAllocTlsFunc pI_CryptAllocTls;
static I_CryptDetachTlsFunc pI_CryptDetachTls;
static I_CryptGetTlsFunc pI_CryptGetTls;
static I_CryptSetTlsFunc pI_CryptSetTls;
static I_CryptFreeTlsFunc pI_CryptFreeTls;
static void test_cryptTls(void)
{
HMODULE lib = LoadLibraryA("crypt32.dll");
if (lib)
{
DWORD index;
BOOL ret;
pI_CryptAllocTls = (I_CryptAllocTlsFunc)GetProcAddress(lib,
"I_CryptAllocTls");
pI_CryptDetachTls = (I_CryptDetachTlsFunc)GetProcAddress(lib,
"I_CryptDetachTls");
pI_CryptGetTls = (I_CryptGetTlsFunc)GetProcAddress(lib,
"I_CryptGetTls");
pI_CryptSetTls = (I_CryptSetTlsFunc)GetProcAddress(lib,
"I_CryptSetTls");
pI_CryptFreeTls = (I_CryptFreeTlsFunc)GetProcAddress(lib,
"I_CryptFreeTls");
/* One normal pass */
index = pI_CryptAllocTls();
ok(index, "I_CryptAllocTls failed: %08lx\n", GetLastError());
if (index)
{
LPVOID ptr;
ptr = pI_CryptGetTls(index);
ok(!ptr, "Expected NULL\n");
ret = pI_CryptSetTls(index, (LPVOID)0xdeadbeef);
ok(ret, "I_CryptSetTls failed: %08lx\n", GetLastError());
ptr = pI_CryptGetTls(index);
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
/* This crashes
ret = pI_CryptFreeTls(index, 1);
*/
ret = pI_CryptFreeTls(index, 0);
ok(ret, "I_CryptFreeTls failed: %08lx\n", GetLastError());
ret = pI_CryptFreeTls(index, 0);
/* Not sure if this fails because TlsFree should fail, so leave as
* todo for now.
*/
todo_wine ok(!ret && GetLastError() ==
HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
"Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %08lx\n",
GetLastError());
}
/* Similar pass, check I_CryptDetachTls */
index = pI_CryptAllocTls();
ok(index, "I_CryptAllocTls failed: %08lx\n", GetLastError());
if (index)
{
LPVOID ptr;
ptr = pI_CryptGetTls(index);
ok(!ptr, "Expected NULL\n");
ret = pI_CryptSetTls(index, (LPVOID)0xdeadbeef);
ok(ret, "I_CryptSetTls failed: %08lx\n", GetLastError());
ptr = pI_CryptGetTls(index);
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
ptr = pI_CryptDetachTls(index);
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
ptr = pI_CryptGetTls(index);
ok(!ptr, "Expected NULL\n");
}
FreeLibrary(lib);
}
}
START_TEST(main)
{
testOIDToAlgID();
@ -282,4 +378,6 @@ START_TEST(main)
test_findExtension();
test_findRDNAttr();
test_verifyTimeValidity();
test_cryptAllocate();
test_cryptTls();
}

View File

@ -2273,6 +2273,10 @@ BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, BYTE *pbSignature, DWORD dw
#define CryptVerifySignature WINELIB_NAME_AW(CryptVerifySignature)
/* crypt32.dll functions */
LPVOID WINAPI CryptMemAlloc(ULONG cbSize);
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize);
VOID WINAPI CryptMemFree(LPVOID pv);
BOOL WINAPI CryptRegisterOIDFunction(DWORD,LPCSTR,LPCSTR,LPCWSTR,LPCSTR);
BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
LPCSTR pszOID, LPCWSTR szValueName, DWORD *pdwValueType,