rpcrt4: Implement full-pointer support for interpreted stubs.
[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_T61STRING       (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x14)
30 #define ASN_IA5STRING       (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x16)
31 #define ASN_UTCTIME         (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x17)
32 #define ASN_GENERALTIME     (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x18)
33
34 /* The following aren't defined in wincrypt.h, as they're "reserved" */
35 #define CERT_CERT_PROP_ID 32
36 #define CERT_CRL_PROP_ID  33
37 #define CERT_CTL_PROP_ID  34
38
39 /* Returns a handle to the default crypto provider; loads it if necessary.
40  * Returns NULL on failure.
41  */
42 HCRYPTPROV CRYPT_GetDefaultProvider(void);
43
44 void crypt_oid_init(HINSTANCE hinst);
45 void crypt_oid_free(void);
46
47 /* Some typedefs that make it easier to abstract which type of context we're
48  * working with.
49  */
50 typedef const void *(WINAPI *CreateContextFunc)(DWORD dwCertEncodingType,
51  const BYTE *pbCertEncoded, DWORD cbCertEncoded);
52 typedef BOOL (WINAPI *AddContextToStoreFunc)(HCERTSTORE hCertStore,
53  const void *context, DWORD dwAddDisposition, const void **ppStoreContext);
54 typedef BOOL (WINAPI *AddEncodedContextToStoreFunc)(HCERTSTORE hCertStore,
55  DWORD dwCertEncodingType, const BYTE *pbEncoded, DWORD cbEncoded,
56  DWORD dwAddDisposition, const void **ppContext);
57 typedef const void *(WINAPI *DuplicateContextFunc)(const void *context);
58 typedef const void *(WINAPI *EnumContextsInStoreFunc)(HCERTSTORE hCertStore,
59  const void *pPrevContext);
60 typedef DWORD (WINAPI *EnumPropertiesFunc)(const void *context, DWORD dwPropId);
61 typedef BOOL (WINAPI *GetContextPropertyFunc)(const void *context,
62  DWORD dwPropID, void *pvData, DWORD *pcbData);
63 typedef BOOL (WINAPI *SetContextPropertyFunc)(const void *context,
64  DWORD dwPropID, DWORD dwFlags, const void *pvData);
65 typedef BOOL (WINAPI *SerializeElementFunc)(const void *context, DWORD dwFlags,
66  BYTE *pbElement, DWORD *pcbElement);
67 typedef BOOL (WINAPI *FreeContextFunc)(const void *context);
68 typedef BOOL (WINAPI *DeleteContextFunc)(const void *context);
69
70 /* An abstract context (certificate, CRL, or CTL) interface */
71 typedef struct _WINE_CONTEXT_INTERFACE
72 {
73     CreateContextFunc            create;
74     AddContextToStoreFunc        addContextToStore;
75     AddEncodedContextToStoreFunc addEncodedToStore;
76     DuplicateContextFunc         duplicate;
77     EnumContextsInStoreFunc      enumContextsInStore;
78     EnumPropertiesFunc           enumProps;
79     GetContextPropertyFunc       getProp;
80     SetContextPropertyFunc       setProp;
81     SerializeElementFunc         serialize;
82     FreeContextFunc              free;
83     DeleteContextFunc            deleteFromStore;
84 } WINE_CONTEXT_INTERFACE, *PWINE_CONTEXT_INTERFACE;
85 typedef const WINE_CONTEXT_INTERFACE *PCWINE_CONTEXT_INTERFACE;
86
87 extern PCWINE_CONTEXT_INTERFACE pCertInterface;
88 extern PCWINE_CONTEXT_INTERFACE pCRLInterface;
89 extern PCWINE_CONTEXT_INTERFACE pCTLInterface;
90
91 /* Helper function for store reading functions and
92  * CertAddSerializedElementToStore.  Returns a context of the appropriate type
93  * if it can, or NULL otherwise.  Doesn't validate any of the properties in
94  * the serialized context (for example, bad hashes are retained.)
95  * *pdwContentType is set to the type of the returned context.
96  */
97 const void *CRYPT_ReadSerializedElement(const BYTE *pbElement,
98  DWORD cbElement, DWORD dwContextTypeFlags, DWORD *pdwContentType);
99
100 DWORD CertStore_GetAccessState(HCERTSTORE hCertStore);
101
102 /**
103  *  Context functions
104  */
105
106 /* Allocates a new data context, a context which owns properties directly.
107  * contextSize is the size of the public data type associated with context,
108  * which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT.
109  * Free with Context_Release.
110  */
111 void *Context_CreateDataContext(size_t contextSize);
112
113 /* Creates a new link context with extra bytes.  The context refers to linked
114  * rather than owning its own properties.  If addRef is TRUE (which ordinarily
115  * it should be) linked is addref'd.
116  * Free with Context_Release.
117  */
118 void *Context_CreateLinkContext(size_t contextSize, void *linked, size_t extra,
119  BOOL addRef);
120
121 /* Returns a pointer to the extra bytes allocated with context, which must be
122  * a link context.
123  */
124 void *Context_GetExtra(const void *context, size_t contextSize);
125
126 /* Gets the context linked to by context, which must be a link context. */
127 void *Context_GetLinkedContext(void *context, size_t contextSize);
128
129 /* Copies properties from fromContext to toContext. */
130 void Context_CopyProperties(const void *to, const void *from,
131  size_t contextSize);
132
133 struct _CONTEXT_PROPERTY_LIST;
134 typedef struct _CONTEXT_PROPERTY_LIST *PCONTEXT_PROPERTY_LIST;
135
136 /* Returns context's properties, or the linked context's properties if context
137  * is a link context.
138  */
139 PCONTEXT_PROPERTY_LIST Context_GetProperties(void *context, size_t contextSize);
140
141 void Context_AddRef(void *context, size_t contextSize);
142
143 typedef void (*ContextFreeFunc)(void *context);
144
145 /* Decrements context's ref count.  If context is a link context, releases its
146  * linked context as well.
147  * If a data context has its ref count reach 0, calls dataContextFree on it.
148  */
149 void Context_Release(void *context, size_t contextSize,
150  ContextFreeFunc dataContextFree);
151
152 /**
153  *  Context property list functions
154  */
155
156 PCONTEXT_PROPERTY_LIST ContextPropertyList_Create(void);
157
158 /* Searches for the property with ID id in the context.  Returns TRUE if found,
159  * and copies the property's length and a pointer to its data to blob.
160  * Otherwise returns FALSE.
161  */
162 BOOL ContextPropertyList_FindProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
163  PCRYPT_DATA_BLOB blob);
164
165 BOOL ContextPropertyList_SetProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
166  const BYTE *pbData, size_t cbData);
167
168 void ContextPropertyList_RemoveProperty(PCONTEXT_PROPERTY_LIST list, DWORD id);
169
170 DWORD ContextPropertyList_EnumPropIDs(PCONTEXT_PROPERTY_LIST list, DWORD id);
171
172 void ContextPropertyList_Copy(PCONTEXT_PROPERTY_LIST to,
173  PCONTEXT_PROPERTY_LIST from);
174
175 void ContextPropertyList_Free(PCONTEXT_PROPERTY_LIST list);
176
177 /**
178  *  Context list functions.  A context list is a simple list of link contexts.
179  */
180 struct ContextList;
181
182 struct ContextList *ContextList_Create(
183  PCWINE_CONTEXT_INTERFACE contextInterface, size_t contextSize);
184
185 void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace);
186
187 void *ContextList_Enum(struct ContextList *list, void *pPrev);
188
189 void ContextList_Delete(struct ContextList *list, void *context);
190
191 void ContextList_Empty(struct ContextList *list);
192
193 void ContextList_Free(struct ContextList *list);
194
195 #endif