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
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
)
44 module
= heap_alloc(sizeof(*module
));
47 module
->nModuleName
= magic
;
49 module
->dwFlags
= flags
;
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
;
66 module
->PER
.apfnEncoder
= NULL
;
67 module
->PER
.apfnDecoder
= NULL
;
74 void WINAPI
ASN1_CloseModule(ASN1module_t module
)
76 TRACE("(%p)\n", module
);
81 ASN1error_e WINAPI
ASN1_CreateEncoder(ASN1module_t module
, ASN1encoding_t
*encoder
, ASN1octet_t
*buf
,
82 ASN1uint32_t bufsize
, ASN1encoding_t parent
)
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
));
94 return ASN1_ERR_MEMORY
;
98 FIXME("parent not implemented.\n");
100 enc
->magic
= 0x44434e45;
102 enc
->module
= module
;
106 enc
->err
= ASN1_SUCCESS
;
109 enc
->cbExtraHeader
= 0;
110 enc
->eRule
= module
->eRule
;
111 enc
->dwFlags
= module
->dwFlags
;
118 enc
->dwFlags
|= ASN1ENCODE_SETBUFFER
;
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
)
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
));
144 return ASN1_ERR_MEMORY
;
148 FIXME("parent not implemented.\n");
150 dec
->magic
= 0x44434544;
152 dec
->module
= module
;
156 dec
->err
= ASN1_SUCCESS
;
159 dec
->eRule
= module
->eRule
;
160 dec
->dwFlags
= module
->dwFlags
;
166 dec
->dwFlags
|= ASN1DECODE_SETBUFFER
;
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
);
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
;