ntdll: Rename local variables in heap_reallocate.
[wine.git] / dlls / msasn1 / main.c
blob4614a5b292ea4ba39dead52f7ccbab4104a5aaf5
1 /*
2 * Copyright 2014 Austin English
3 * Copyright 2020 Vijay Kiran Kamuju
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "msasn1.h"
27 #include "wine/heap.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msasn1);
32 ASN1module_t WINAPI ASN1_CreateModule(ASN1uint32_t ver, ASN1encodingrule_e rule, ASN1uint32_t flags,
33 ASN1uint32_t pdu, const ASN1GenericFun_t encoder[],
34 const ASN1GenericFun_t decoder[], const ASN1FreeFun_t freemem[],
35 const ASN1uint32_t size[], ASN1magic_t magic)
37 ASN1module_t module = NULL;
39 TRACE("(%08lx %08x %08lx %lu %p %p %p %p %lu)\n", ver, rule, flags, pdu, encoder, decoder, freemem, size, magic);
41 if (!encoder || !decoder || !freemem || !size)
42 return module;
44 module = heap_alloc(sizeof(*module));
45 if (module)
47 module->nModuleName = magic;
48 module->eRule = rule;
49 module->dwFlags = flags;
50 module->cPDUs = pdu;
51 module->apfnFreeMemory = freemem;
52 module->acbStructSize = size;
54 if (rule & ASN1_PER_RULE)
56 module->PER.apfnEncoder = (ASN1PerEncFun_t *)encoder;
57 module->PER.apfnDecoder = (ASN1PerDecFun_t *)decoder;
59 else if (rule & ASN1_BER_RULE)
61 module->BER.apfnEncoder = (ASN1BerEncFun_t *)encoder;
62 module->BER.apfnDecoder = (ASN1BerDecFun_t *)decoder;
64 else
66 module->PER.apfnEncoder = NULL;
67 module->PER.apfnDecoder = NULL;
71 return module;
74 void WINAPI ASN1_CloseModule(ASN1module_t module)
76 TRACE("(%p)\n", module);
78 heap_free(module);
81 ASN1error_e WINAPI ASN1_CreateEncoder(ASN1module_t module, ASN1encoding_t *encoder, ASN1octet_t *buf,
82 ASN1uint32_t bufsize, ASN1encoding_t parent)
84 ASN1encoding_t enc;
86 TRACE("(%p %p %p %lu %p)\n", module, encoder, buf, bufsize, parent);
88 if (!module || !encoder)
89 return ASN1_ERR_BADARGS;
91 enc = heap_alloc(sizeof(*enc));
92 if (!enc)
94 return ASN1_ERR_MEMORY;
97 if (parent)
98 FIXME("parent not implemented.\n");
100 enc->magic = 0x44434e45;
101 enc->version = 0;
102 enc->module = module;
103 enc->buf = 0;
104 enc->size = 0;
105 enc->len = 0;
106 enc->err = ASN1_SUCCESS;
107 enc->bit = 0;
108 enc->pos = 0;
109 enc->cbExtraHeader = 0;
110 enc->eRule = module->eRule;
111 enc->dwFlags = module->dwFlags;
113 if (buf && bufsize)
115 enc->buf = buf;
116 enc->pos = buf;
117 enc->size = bufsize;
118 enc->dwFlags |= ASN1ENCODE_SETBUFFER;
121 *encoder = enc;
123 return ASN1_SUCCESS;
126 void WINAPI ASN1_CloseEncoder(ASN1encoding_t encoder)
128 FIXME("(%p): Stub!\n", encoder);
131 ASN1error_e WINAPI ASN1_CreateDecoder(ASN1module_t module, ASN1decoding_t *decoder, ASN1octet_t *buf,
132 ASN1uint32_t bufsize, ASN1decoding_t parent)
134 ASN1decoding_t dec;
136 TRACE("(%p %p %p %lu %p)\n", module, decoder, buf, bufsize, parent);
138 if (!module || !decoder)
139 return ASN1_ERR_BADARGS;
141 dec = heap_alloc(sizeof(*dec));
142 if (!dec)
144 return ASN1_ERR_MEMORY;
147 if (parent)
148 FIXME("parent not implemented.\n");
150 dec->magic = 0x44434544;
151 dec->version = 0;
152 dec->module = module;
153 dec->buf = 0;
154 dec->size = bufsize;
155 dec->len = 0;
156 dec->err = ASN1_SUCCESS;
157 dec->bit = 0;
158 dec->pos = 0;
159 dec->eRule = module->eRule;
160 dec->dwFlags = module->dwFlags;
162 if (buf)
164 dec->buf = buf;
165 dec->pos = buf;
166 dec->dwFlags |= ASN1DECODE_SETBUFFER;
169 *decoder = dec;
171 return ASN1_SUCCESS;
174 void WINAPI ASN1_CloseDecoder(ASN1decoding_t decoder)
176 FIXME("(%p): Stub!\n", decoder);
179 ASN1error_e WINAPI ASN1_Decode(ASN1decoding_t decoder, void **outdata, ASN1uint32_t pdunum,
180 ASN1uint32_t flags, ASN1octet_t *buf, ASN1uint32_t bufsize)
182 FIXME("(%p %p %lu %08lx %p %lu): Stub!\n", decoder, outdata, pdunum, flags, buf, bufsize);
184 if (!decoder)
185 return ASN1_ERR_BADARGS;
187 if (!buf || !bufsize)
189 decoder->err = ASN1_ERR_BADARGS;
190 return ASN1_ERR_BADARGS;
193 decoder->err = ASN1_ERR_BADPDU;
194 return ASN1_ERR_BADPDU;