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