mshtml: Added beginning OnDataAvailable implementation.
[wine] / dlls / crypt32 / crypt32_private.h
1 /*
2  * Copyright 2005 Juan Lang
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #ifndef __CRYPT32_PRIVATE_H__
20 #define __CRYPT32_PRIVATE_H__
21
22 /* a few asn.1 tags we need */
23 #define ASN_BOOL            (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x01)
24 #define ASN_BITSTRING       (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x03)
25 #define ASN_ENUMERATED      (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x0a)
26 #define ASN_SETOF           (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x11)
27 #define ASN_NUMERICSTRING   (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x12)
28 #define ASN_PRINTABLESTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x13)
29 #define ASN_IA5STRING       (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x16)
30 #define ASN_UTCTIME         (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x17)
31 #define ASN_GENERALTIME     (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x18)
32
33 /* The following aren't defined in wincrypt.h, as they're "reserved" */
34 #define CERT_CERT_PROP_ID 32
35 #define CERT_CRL_PROP_ID  33
36 #define CERT_CTL_PROP_ID  34
37
38 /* Returns a handle to the default crypto provider; loads it if necessary.
39  * Returns NULL on failure.
40  */
41 HCRYPTPROV CRYPT_GetDefaultProvider(void);
42
43 void crypt_oid_init(HINSTANCE hinst);
44 void crypt_oid_free(void);
45
46 /* Some typedefs that make it easier to abstract which type of context we're
47  * working with.
48  */
49 typedef const void *(WINAPI *CreateContextFunc)(DWORD dwCertEncodingType,
50  const BYTE *pbCertEncoded, DWORD cbCertEncoded);
51 typedef BOOL (WINAPI *AddContextToStoreFunc)(HCERTSTORE hCertStore,
52  const void *context, DWORD dwAddDisposition, const void **ppStoreContext);
53 typedef BOOL (WINAPI *AddEncodedContextToStoreFunc)(HCERTSTORE hCertStore,
54  DWORD dwCertEncodingType, const BYTE *pbEncoded, DWORD cbEncoded,
55  DWORD dwAddDisposition, const void **ppContext);
56 typedef const void *(WINAPI *DuplicateContextFunc)(const void *context);
57 typedef const void *(WINAPI *EnumContextsInStoreFunc)(HCERTSTORE hCertStore,
58  const void *pPrevContext);
59 typedef DWORD (WINAPI *EnumPropertiesFunc)(const void *context, DWORD dwPropId);
60 typedef BOOL (WINAPI *GetContextPropertyFunc)(const void *context,
61  DWORD dwPropID, void *pvData, DWORD *pcbData);
62 typedef BOOL (WINAPI *SetContextPropertyFunc)(const void *context,
63  DWORD dwPropID, DWORD dwFlags, const void *pvData);
64 typedef BOOL (WINAPI *SerializeElementFunc)(const void *context, DWORD dwFlags,
65  BYTE *pbElement, DWORD *pcbElement);
66 typedef BOOL (WINAPI *FreeContextFunc)(const void *context);
67 typedef BOOL (WINAPI *DeleteContextFunc)(const void *context);
68
69 /* An abstract context (certificate, CRL, or CTL) interface */
70 typedef struct _WINE_CONTEXT_INTERFACE
71 {
72     CreateContextFunc            create;
73     AddContextToStoreFunc        addContextToStore;
74     AddEncodedContextToStoreFunc addEncodedToStore;
75     DuplicateContextFunc         duplicate;
76     EnumContextsInStoreFunc      enumContextsInStore;
77     EnumPropertiesFunc           enumProps;
78     GetContextPropertyFunc       getProp;
79     SetContextPropertyFunc       setProp;
80     SerializeElementFunc         serialize;
81     FreeContextFunc              free;
82     DeleteContextFunc            deleteFromStore;
83 } WINE_CONTEXT_INTERFACE, *PWINE_CONTEXT_INTERFACE;
84 typedef const WINE_CONTEXT_INTERFACE *PCWINE_CONTEXT_INTERFACE;
85
86 extern PCWINE_CONTEXT_INTERFACE pCertInterface;
87 extern PCWINE_CONTEXT_INTERFACE pCRLInterface;
88 extern PCWINE_CONTEXT_INTERFACE pCTLInterface;
89
90 /* Helper function for store reading functions and
91  * CertAddSerializedElementToStore.  Returns a context of the appropriate type
92  * if it can, or NULL otherwise.  Doesn't validate any of the properties in
93  * the serialized context (for example, bad hashes are retained.)
94  * *pdwContentType is set to the type of the returned context.
95  */
96 const void *CRYPT_ReadSerializedElement(const BYTE *pbElement,
97  DWORD cbElement, DWORD dwContextTypeFlags, DWORD *pdwContentType);
98
99 DWORD CertStore_GetAccessState(HCERTSTORE hCertStore);
100
101 /**
102  *  Context functions
103  */
104
105 /* Allocates a new data context, a context which owns properties directly.
106  * contextSize is the size of the public data type associated with context,
107  * which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT.
108  * Free with Context_Release.
109  */
110 void *Context_CreateDataContext(size_t contextSize);
111
112 /* Creates a new link context with extra bytes.  The context refers to linked
113  * rather than owning its own properties.  If addRef is TRUE (which ordinarily
114  * it should be) linked is addref'd.
115  * Free with Context_Release.
116  */
117 void *Context_CreateLinkContext(size_t contextSize, void *linked, size_t extra,
118  BOOL addRef);
119
120 /* Returns a pointer to the extra bytes allocated with context, which must be
121  * a link context.
122  */
123 void *Context_GetExtra(const void *context, size_t contextSize);
124
125 /* Gets the context linked to by context, which must be a link context. */
126 void *Context_GetLinkedContext(void *context, size_t contextSize);
127
128 /* Copies properties from fromContext to toContext. */
129 void Context_CopyProperties(const void *to, const void *from,
130  size_t contextSize);
131
132 struct _CONTEXT_PROPERTY_LIST;
133 typedef struct _CONTEXT_PROPERTY_LIST *PCONTEXT_PROPERTY_LIST;
134
135 /* Returns context's properties, or the linked context's properties if context
136  * is a link context.
137  */
138 PCONTEXT_PROPERTY_LIST Context_GetProperties(void *context, size_t contextSize);
139
140 void Context_AddRef(void *context, size_t contextSize);
141
142 typedef void (*ContextFreeFunc)(void *context);
143
144 /* Decrements context's ref count.  If context is a link context, releases its
145  * linked context as well.
146  * If a data context has its ref count reach 0, calls dataContextFree on it.
147  */
148 void Context_Release(void *context, size_t contextSize,
149  ContextFreeFunc dataContextFree);
150
151 /**
152  *  Context property list functions
153  */
154
155 PCONTEXT_PROPERTY_LIST ContextPropertyList_Create(void);
156
157 /* Searches for the property with ID id in the context.  Returns TRUE if found,
158  * and copies the property's length and a pointer to its data to blob.
159  * Otherwise returns FALSE.
160  */
161 BOOL ContextPropertyList_FindProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
162  PCRYPT_DATA_BLOB blob);
163
164 BOOL ContextPropertyList_SetProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
165  const BYTE *pbData, size_t cbData);
166
167 void ContextPropertyList_RemoveProperty(PCONTEXT_PROPERTY_LIST list, DWORD id);
168
169 DWORD ContextPropertyList_EnumPropIDs(PCONTEXT_PROPERTY_LIST list, DWORD id);
170
171 void ContextPropertyList_Copy(PCONTEXT_PROPERTY_LIST to,
172  PCONTEXT_PROPERTY_LIST from);
173
174 void ContextPropertyList_Free(PCONTEXT_PROPERTY_LIST list);
175
176 /**
177  *  Context list functions.  A context list is a simple list of link contexts.
178  */
179 struct ContextList;
180
181 struct ContextList *ContextList_Create(
182  PCWINE_CONTEXT_INTERFACE contextInterface, size_t contextSize);
183
184 void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace);
185
186 void *ContextList_Enum(struct ContextList *list, void *pPrev);
187
188 void ContextList_Delete(struct ContextList *list, void *context);
189
190 void ContextList_Empty(struct ContextList *list);
191
192 void ContextList_Free(struct ContextList *list);
193
194 #endif