Commit 779dd45e authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

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

parent bc819295
......@@ -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);
......
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment