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/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msasn1
);
31 ASN1module_t WINAPI
ASN1_CreateModule(ASN1uint32_t ver
, ASN1encodingrule_e rule
, ASN1uint32_t flags
,
32 ASN1uint32_t pdu
, const ASN1GenericFun_t encoder
[],
33 const ASN1GenericFun_t decoder
[], const ASN1FreeFun_t freemem
[],
34 const ASN1uint32_t size
[], ASN1magic_t magic
)
36 ASN1module_t module
= NULL
;
38 TRACE("(%08lx %08x %08lx %lu %p %p %p %p %lu)\n", ver
, rule
, flags
, pdu
, encoder
, decoder
, freemem
, size
, magic
);
40 if (!encoder
|| !decoder
|| !freemem
|| !size
)
43 module
= malloc(sizeof(*module
));
46 module
->nModuleName
= magic
;
48 module
->dwFlags
= flags
;
50 module
->apfnFreeMemory
= freemem
;
51 module
->acbStructSize
= size
;
53 if (rule
& ASN1_PER_RULE
)
55 module
->PER
.apfnEncoder
= (ASN1PerEncFun_t
*)encoder
;
56 module
->PER
.apfnDecoder
= (ASN1PerDecFun_t
*)decoder
;
58 else if (rule
& ASN1_BER_RULE
)
60 module
->BER
.apfnEncoder
= (ASN1BerEncFun_t
*)encoder
;
61 module
->BER
.apfnDecoder
= (ASN1BerDecFun_t
*)decoder
;
65 module
->PER
.apfnEncoder
= NULL
;
66 module
->PER
.apfnDecoder
= NULL
;
73 void WINAPI
ASN1_CloseModule(ASN1module_t module
)
75 TRACE("(%p)\n", module
);
80 ASN1error_e WINAPI
ASN1_CreateEncoder(ASN1module_t module
, ASN1encoding_t
*encoder
, ASN1octet_t
*buf
,
81 ASN1uint32_t bufsize
, ASN1encoding_t parent
)
85 TRACE("(%p %p %p %lu %p)\n", module
, encoder
, buf
, bufsize
, parent
);
87 if (!module
|| !encoder
)
88 return ASN1_ERR_BADARGS
;
90 enc
= malloc(sizeof(*enc
));
93 return ASN1_ERR_MEMORY
;
97 FIXME("parent not implemented.\n");
99 enc
->magic
= 0x44434e45;
101 enc
->module
= module
;
105 enc
->err
= ASN1_SUCCESS
;
108 enc
->cbExtraHeader
= 0;
109 enc
->eRule
= module
->eRule
;
110 enc
->dwFlags
= module
->dwFlags
;
117 enc
->dwFlags
|= ASN1ENCODE_SETBUFFER
;
125 void WINAPI
ASN1_CloseEncoder(ASN1encoding_t encoder
)
127 FIXME("(%p): Stub!\n", encoder
);
130 ASN1error_e WINAPI
ASN1_CreateDecoder(ASN1module_t module
, ASN1decoding_t
*decoder
, ASN1octet_t
*buf
,
131 ASN1uint32_t bufsize
, ASN1decoding_t parent
)
135 TRACE("(%p %p %p %lu %p)\n", module
, decoder
, buf
, bufsize
, parent
);
137 if (!module
|| !decoder
)
138 return ASN1_ERR_BADARGS
;
140 dec
= malloc(sizeof(*dec
));
143 return ASN1_ERR_MEMORY
;
147 FIXME("parent not implemented.\n");
149 dec
->magic
= 0x44434544;
151 dec
->module
= module
;
155 dec
->err
= ASN1_SUCCESS
;
158 dec
->eRule
= module
->eRule
;
159 dec
->dwFlags
= module
->dwFlags
;
165 dec
->dwFlags
|= ASN1DECODE_SETBUFFER
;
173 void WINAPI
ASN1_CloseDecoder(ASN1decoding_t decoder
)
175 FIXME("(%p): Stub!\n", decoder
);
178 ASN1error_e WINAPI
ASN1_Decode(ASN1decoding_t decoder
, void **outdata
, ASN1uint32_t pdunum
,
179 ASN1uint32_t flags
, ASN1octet_t
*buf
, ASN1uint32_t bufsize
)
181 FIXME("(%p %p %lu %08lx %p %lu): Stub!\n", decoder
, outdata
, pdunum
, flags
, buf
, bufsize
);
184 return ASN1_ERR_BADARGS
;
186 if (!buf
|| !bufsize
)
188 decoder
->err
= ASN1_ERR_BADARGS
;
189 return ASN1_ERR_BADARGS
;
192 decoder
->err
= ASN1_ERR_BADPDU
;
193 return ASN1_ERR_BADPDU
;