crypt32: Add a function to serialize a store to an arbitrary stream.

This commit is contained in:
Juan Lang 2007-09-27 12:30:52 -07:00 committed by Alexandre Julliard
parent bc81929519
commit 779dd45e6b
2 changed files with 75 additions and 0 deletions

View File

@ -268,6 +268,15 @@ HCERTCHAINENGINE CRYPT_CreateChainEngine(HCERTSTORE root,
const void *CRYPT_ReadSerializedElement(const BYTE *pbElement,
DWORD cbElement, DWORD dwContextTypeFlags, DWORD *pdwContentType);
typedef BOOL (*SerializedOutputFunc)(void *handle, const void *buffer,
DWORD size);
/* Writes contexts from the memory store to the output function, passing handle
* as the handle parameter to the output function.
*/
BOOL CRYPT_WriteSerializedStoreToStream(HCERTSTORE store,
SerializedOutputFunc output, void *handle);
/* Writes contexts from the memory store to the file. */
BOOL CRYPT_WriteSerializedStoreToFile(HANDLE file, HCERTSTORE store);

View File

@ -533,6 +533,72 @@ static BOOL WINAPI CRYPT_SerializeCTLNoHash(PCCTL_CONTEXT pCtlContext,
CERT_CTL_PROP_ID, pCTLInterface, dwFlags, TRUE, pbElement, pcbElement);
}
static BOOL CRYPT_SerializeContextsToStream(SerializedOutputFunc output,
void *handle, const WINE_CONTEXT_INTERFACE *contextInterface, HCERTSTORE store)
{
const void *context = NULL;
BOOL ret;
do {
context = contextInterface->enumContextsInStore(store, context);
if (context)
{
DWORD size = 0;
LPBYTE buf = NULL;
ret = contextInterface->serialize(context, 0, NULL, &size);
if (size)
buf = CryptMemAlloc(size);
if (buf)
{
ret = contextInterface->serialize(context, 0, buf, &size);
if (ret)
ret = output(handle, buf, size);
}
CryptMemFree(buf);
}
else
ret = TRUE;
} while (ret && context != NULL);
if (context)
contextInterface->free(context);
return ret;
}
BOOL CRYPT_WriteSerializedStoreToStream(HCERTSTORE store,
SerializedOutputFunc output, void *handle)
{
static const BYTE fileTrailer[12] = { 0 };
WINE_CONTEXT_INTERFACE interface;
BOOL ret;
ret = output(handle, fileHeader, sizeof(fileHeader));
if (ret)
{
memcpy(&interface, pCertInterface, sizeof(interface));
interface.serialize = (SerializeElementFunc)CRYPT_SerializeCertNoHash;
ret = CRYPT_SerializeContextsToStream(output, handle, &interface,
store);
}
if (ret)
{
memcpy(&interface, pCRLInterface, sizeof(interface));
interface.serialize = (SerializeElementFunc)CRYPT_SerializeCRLNoHash;
ret = CRYPT_SerializeContextsToStream(output, handle, &interface,
store);
}
if (ret)
{
memcpy(&interface, pCTLInterface, sizeof(interface));
interface.serialize = (SerializeElementFunc)CRYPT_SerializeCTLNoHash;
ret = CRYPT_SerializeContextsToStream(output, handle, &interface,
store);
}
if (ret)
ret = output(handle, fileTrailer, sizeof(fileTrailer));
return ret;
}
static BOOL CRYPT_SerializeContextsToFile(HANDLE file,
const WINE_CONTEXT_INTERFACE *contextInterface, HCERTSTORE store)
{