Juan Lang : crypt32: Add a function to serialize a store to an arbitrary stream.
Alexandre Julliard
julliard at winehq.org
Fri Sep 28 06:46:00 CDT 2007
Module: wine
Branch: master
Commit: 779dd45e6bc5e869c8e79c21dcb115838eca977f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=779dd45e6bc5e869c8e79c21dcb115838eca977f
Author: Juan Lang <juan.lang at gmail.com>
Date: Thu Sep 27 12:30:52 2007 -0700
crypt32: Add a function to serialize a store to an arbitrary stream.
---
dlls/crypt32/crypt32_private.h | 9 +++++
dlls/crypt32/serialize.c | 66 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h
index 533d483..4970d56 100644
--- a/dlls/crypt32/crypt32_private.h
+++ b/dlls/crypt32/crypt32_private.h
@@ -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);
diff --git a/dlls/crypt32/serialize.c b/dlls/crypt32/serialize.c
index 9ef6b54..44ee510 100644
--- a/dlls/crypt32/serialize.c
+++ b/dlls/crypt32/serialize.c
@@ -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)
{
More information about the wine-cvs
mailing list