crypt32(3/13): Move cert functions to cert.c

Juan Lang juan.lang at gmail.com
Wed Aug 15 18:46:50 CDT 2007


--Juan
-------------- next part --------------
From 65da7ceffc09a07dae5d12508db0b309afef580c Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Wed, 15 Aug 2007 16:31:25 -0700
Subject: [PATCH] Move cert functions to cert.c
---
 dlls/crypt32/cert.c  |  132 ++++++++++++++++++++++++++++++++++++++++++++++++++
 dlls/crypt32/store.c |  132 --------------------------------------------------
 2 files changed, 132 insertions(+), 132 deletions(-)

diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c
index 4e5fcfd..76588c1 100644
--- a/dlls/crypt32/cert.c
+++ b/dlls/crypt32/cert.c
@@ -48,6 +48,95 @@ static BOOL WINAPI CertContext_GetProper
 static BOOL WINAPI CertContext_SetProperty(void *context, DWORD dwPropId,
  DWORD dwFlags, const void *pvData);
 
+#define CertContext_CopyProperties(to, from) \
+ Context_CopyProperties((to), (from), sizeof(CERT_CONTEXT))
+
+BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore,
+ PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
+ PCCERT_CONTEXT *ppStoreContext)
+{
+    PWINECRYPT_CERTSTORE store = (PWINECRYPT_CERTSTORE)hCertStore;
+    BOOL ret = TRUE;
+    PCCERT_CONTEXT toAdd = NULL, existing = NULL;
+
+    TRACE("(%p, %p, %08x, %p)\n", hCertStore, pCertContext,
+     dwAddDisposition, ppStoreContext);
+
+    /* Weird case to pass a test */
+    if (dwAddDisposition == 0)
+    {
+        SetLastError(STATUS_ACCESS_VIOLATION);
+        return FALSE;
+    }
+    if (dwAddDisposition != CERT_STORE_ADD_ALWAYS)
+    {
+        BYTE hashToAdd[20];
+        DWORD size = sizeof(hashToAdd);
+
+        ret = CertGetCertificateContextProperty(pCertContext, CERT_HASH_PROP_ID,
+         hashToAdd, &size);
+        if (ret)
+        {
+            CRYPT_HASH_BLOB blob = { sizeof(hashToAdd), hashToAdd };
+
+            existing = CertFindCertificateInStore(hCertStore,
+             pCertContext->dwCertEncodingType, 0, CERT_FIND_SHA1_HASH, &blob,
+             NULL);
+        }
+    }
+
+    switch (dwAddDisposition)
+    {
+    case CERT_STORE_ADD_ALWAYS:
+        toAdd = CertDuplicateCertificateContext(pCertContext);
+        break;
+    case CERT_STORE_ADD_NEW:
+        if (existing)
+        {
+            TRACE("found matching certificate, not adding\n");
+            SetLastError(CRYPT_E_EXISTS);
+            ret = FALSE;
+        }
+        else
+            toAdd = CertDuplicateCertificateContext(pCertContext);
+        break;
+    case CERT_STORE_ADD_REPLACE_EXISTING:
+        toAdd = CertDuplicateCertificateContext(pCertContext);
+        break;
+    case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES:
+        toAdd = CertDuplicateCertificateContext(pCertContext);
+        if (existing)
+            CertContext_CopyProperties(toAdd, existing);
+        break;
+    case CERT_STORE_ADD_USE_EXISTING:
+        if (existing)
+        {
+            CertContext_CopyProperties(existing, pCertContext);
+            *ppStoreContext = CertDuplicateCertificateContext(existing);
+        }
+        else
+            toAdd = CertDuplicateCertificateContext(pCertContext);
+        break;
+    default:
+        FIXME("Unimplemented add disposition %d\n", dwAddDisposition);
+        ret = FALSE;
+    }
+
+    if (toAdd)
+    {
+        if (store)
+            ret = store->certs.addContext(store, (void *)toAdd,
+             (void *)existing, (const void **)ppStoreContext);
+        else if (ppStoreContext)
+            *ppStoreContext = CertDuplicateCertificateContext(toAdd);
+        CertFreeCertificateContext(toAdd);
+    }
+    CertFreeCertificateContext(existing);
+
+    TRACE("returning %d\n", ret);
+    return ret;
+}
+
 BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore,
  DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded,
  DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
@@ -70,6 +159,33 @@ BOOL WINAPI CertAddEncodedCertificateToS
     return ret;
 }
 
+BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
+{
+    BOOL ret;
+
+    TRACE("(%p)\n", pCertContext);
+
+    if (!pCertContext)
+        ret = TRUE;
+    else if (!pCertContext->hCertStore)
+    {
+        ret = TRUE;
+        CertFreeCertificateContext(pCertContext);
+    }
+    else
+    {
+        PWINECRYPT_CERTSTORE hcs =
+         (PWINECRYPT_CERTSTORE)pCertContext->hCertStore;
+
+        if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
+            ret = FALSE;
+        else
+            ret = hcs->certs.deleteContext(hcs, (void *)pCertContext);
+        CertFreeCertificateContext(pCertContext);
+    }
+    return ret;
+}
+
 PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType,
  const BYTE *pbCertEncoded, DWORD cbCertEncoded)
 {
@@ -1084,6 +1200,22 @@ static BOOL compare_cert_by_issuer(PCCER
     return ret;
 }
 
+PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore,
+ PCCERT_CONTEXT pPrev)
+{
+    WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *)hCertStore;
+    PCCERT_CONTEXT ret;
+
+    TRACE("(%p, %p)\n", hCertStore, pPrev);
+    if (!hCertStore)
+        ret = NULL;
+    else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
+        ret = NULL;
+    else
+        ret = (PCCERT_CONTEXT)hcs->certs.enumContext(hcs, (void *)pPrev);
+    return ret;
+}
+
 PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore,
  DWORD dwCertEncodingType, DWORD dwFlags, DWORD dwType, const void *pvPara,
  PCCERT_CONTEXT pPrevCertContext)
diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c
index 42695b8..595d13c 100644
--- a/dlls/crypt32/store.c
+++ b/dlls/crypt32/store.c
@@ -2150,138 +2150,6 @@ BOOL WINAPI CertSaveStore(HCERTSTORE hCe
     return TRUE;
 }
 
-#define CertContext_CopyProperties(to, from) \
- Context_CopyProperties((to), (from), sizeof(CERT_CONTEXT))
-
-BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore,
- PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
- PCCERT_CONTEXT *ppStoreContext)
-{
-    PWINECRYPT_CERTSTORE store = (PWINECRYPT_CERTSTORE)hCertStore;
-    BOOL ret = TRUE;
-    PCCERT_CONTEXT toAdd = NULL, existing = NULL;
-
-    TRACE("(%p, %p, %08x, %p)\n", hCertStore, pCertContext,
-     dwAddDisposition, ppStoreContext);
-
-    /* Weird case to pass a test */
-    if (dwAddDisposition == 0)
-    {
-        SetLastError(STATUS_ACCESS_VIOLATION);
-        return FALSE;
-    }
-    if (dwAddDisposition != CERT_STORE_ADD_ALWAYS)
-    {
-        BYTE hashToAdd[20];
-        DWORD size = sizeof(hashToAdd);
-
-        ret = CertGetCertificateContextProperty(pCertContext, CERT_HASH_PROP_ID,
-         hashToAdd, &size);
-        if (ret)
-        {
-            CRYPT_HASH_BLOB blob = { sizeof(hashToAdd), hashToAdd };
-
-            existing = CertFindCertificateInStore(hCertStore,
-             pCertContext->dwCertEncodingType, 0, CERT_FIND_SHA1_HASH, &blob,
-             NULL);
-        }
-    }
-
-    switch (dwAddDisposition)
-    {
-    case CERT_STORE_ADD_ALWAYS:
-        toAdd = CertDuplicateCertificateContext(pCertContext);
-        break;
-    case CERT_STORE_ADD_NEW:
-        if (existing)
-        {
-            TRACE("found matching certificate, not adding\n");
-            SetLastError(CRYPT_E_EXISTS);
-            ret = FALSE;
-        }
-        else
-            toAdd = CertDuplicateCertificateContext(pCertContext);
-        break;
-    case CERT_STORE_ADD_REPLACE_EXISTING:
-        toAdd = CertDuplicateCertificateContext(pCertContext);
-        break;
-    case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES:
-        toAdd = CertDuplicateCertificateContext(pCertContext);
-        if (existing)
-            CertContext_CopyProperties(toAdd, existing);
-        break;
-    case CERT_STORE_ADD_USE_EXISTING:
-        if (existing)
-        {
-            CertContext_CopyProperties(existing, pCertContext);
-            *ppStoreContext = CertDuplicateCertificateContext(existing);
-        }
-        else
-            toAdd = CertDuplicateCertificateContext(pCertContext);
-        break;
-    default:
-        FIXME("Unimplemented add disposition %d\n", dwAddDisposition);
-        ret = FALSE;
-    }
-
-    if (toAdd)
-    {
-        if (store)
-            ret = store->certs.addContext(store, (void *)toAdd,
-             (void *)existing, (const void **)ppStoreContext);
-        else if (ppStoreContext)
-            *ppStoreContext = CertDuplicateCertificateContext(toAdd);
-        CertFreeCertificateContext(toAdd);
-    }
-    CertFreeCertificateContext(existing);
-
-    TRACE("returning %d\n", ret);
-    return ret;
-}
-
-PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore,
- PCCERT_CONTEXT pPrev)
-{
-    WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *)hCertStore;
-    PCCERT_CONTEXT ret;
-
-    TRACE("(%p, %p)\n", hCertStore, pPrev);
-    if (!hCertStore)
-        ret = NULL;
-    else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
-        ret = NULL;
-    else
-        ret = (PCCERT_CONTEXT)hcs->certs.enumContext(hcs, (void *)pPrev);
-    return ret;
-}
-
-BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
-{
-    BOOL ret;
-
-    TRACE("(%p)\n", pCertContext);
-
-    if (!pCertContext)
-        ret = TRUE;
-    else if (!pCertContext->hCertStore)
-    {
-        ret = TRUE;
-        CertFreeCertificateContext(pCertContext);
-    }
-    else
-    {
-        PWINECRYPT_CERTSTORE hcs =
-         (PWINECRYPT_CERTSTORE)pCertContext->hCertStore;
-
-        if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
-            ret = FALSE;
-        else
-            ret = hcs->certs.deleteContext(hcs, (void *)pCertContext);
-        CertFreeCertificateContext(pCertContext);
-    }
-    return ret;
-}
-
 #define CrlContext_CopyProperties(to, from) \
  Context_CopyProperties((to), (from), sizeof(CRL_CONTEXT))
 
-- 
1.4.1


More information about the wine-patches mailing list