msasn1: Add partial implementation of ASN1_CreateDecoder.

Signed-off-by: Vijay Kiran Kamuju <infyquest@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Vijay Kiran Kamuju 2020-05-08 11:39:46 +02:00 committed by Alexandre Julliard
parent 85dbf7b014
commit fc2c1b5d60
3 changed files with 173 additions and 1 deletions

View File

@ -142,3 +142,46 @@ void WINAPI ASN1_CloseEncoder(ASN1encoding_t encoder)
{
FIXME("(%p): Stub!\n", encoder);
}
ASN1error_e WINAPI ASN1_CreateDecoder(ASN1module_t module, ASN1decoding_t *decoder, ASN1octet_t *buf,
ASN1uint32_t bufsize, ASN1decoding_t parent)
{
ASN1decoding_t dec;
TRACE("(%p %p %p %u %p)\n", module, decoder, buf, bufsize, parent);
if (!module || !decoder)
return ASN1_ERR_BADARGS;
dec = heap_alloc(sizeof(dec));
if (!dec)
{
return ASN1_ERR_MEMORY;
}
if (parent)
FIXME("parent not implemented.\n");
dec->magic = 0x44434544;
dec->version = 0;
dec->module = module;
dec->buf = 0;
dec->size = bufsize;
dec->len = 0;
dec->err = ASN1_SUCCESS;
dec->bit = 0;
dec->pos = 0;
dec->eRule = module->eRule;
dec->dwFlags = module->dwFlags;
if (buf)
{
dec->buf = buf;
dec->pos = buf;
dec->dwFlags |= ASN1DECODE_SETBUFFER;
}
*decoder = dec;
return ASN1_SUCCESS;
}

View File

@ -220,7 +220,7 @@
@ stub ASN1_CloseEncoder2
@ stdcall ASN1_CloseEncoder(ptr)
@ stdcall ASN1_CloseModule(ptr)
@ stub ASN1_CreateDecoder
@ stdcall ASN1_CreateDecoder(ptr ptr ptr long ptr)
@ stub ASN1_CreateDecoderEx
@ stdcall ASN1_CreateEncoder(ptr ptr ptr long ptr)
@ stdcall ASN1_CreateModule(long long long long ptr ptr ptr ptr long)

View File

@ -228,8 +228,137 @@ static void test_CreateEncoder(void)
ASN1_CloseModule(mod);
}
static void test_CreateDecoder(void)
{
const ASN1GenericFun_t encfn[] = { NULL };
const ASN1GenericFun_t decfn[] = { NULL };
const ASN1FreeFun_t freefn[] = { NULL };
const ASN1uint32_t size[] = { 0 };
ASN1magic_t name = 0x61736e31;
ASN1decoding_t decoder = NULL;
ASN1octet_t buf[] = {0x54,0x65,0x73,0x74,0};
ASN1module_t mod;
ASN1error_e ret;
ret = ASN1_CreateDecoder(NULL, NULL, NULL, 0, NULL);
ok(ret == ASN1_ERR_BADARGS,"Got error code %d.\n",ret);
mod = ASN1_CreateModule(ASN1_THIS_VERSION, ASN1_BER_RULE_DER, ASN1FLAGS_NOASSERT, 1, encfn, decfn, freefn, size, name);
ret = ASN1_CreateDecoder(mod, NULL, NULL, 0, NULL);
ok(ret == ASN1_ERR_BADARGS,"Got error code %d.\n",ret);
ret = ASN1_CreateDecoder(mod, &decoder, NULL, 0, NULL);
ok(ASN1_SUCCEEDED(ret),"Got error code %d.\n",ret);
ok(!!decoder,"Decoder creation failed.\n");
ok(decoder->magic==0x44434544,"Got invalid magic = %08x.\n",decoder->magic);
ok(!decoder->version,"Got incorrect version = %08x.\n",decoder->version);
ok(decoder->module==mod,"Got incorrect module = %p.\n",decoder->module);
ok(!decoder->buf,"Got incorrect buf = %p.\n",decoder->buf);
ok(!decoder->size,"Got incorrect size = %u.\n",decoder->size);
ok(!decoder->len,"Got incorrect length = %u.\n",decoder->len);
ok(decoder->err==ASN1_SUCCESS,"Got incorrect err = %d.\n",decoder->err);
ok(!decoder->bit,"Got incorrect bit = %u.\n",decoder->bit);
ok(!decoder->pos,"Got incorrect pos = %p.\n",decoder->pos);
ok(decoder->eRule == ASN1_BER_RULE_DER,"Got incorrect eRule = %08x.\n",decoder->eRule);
ok(decoder->dwFlags == ASN1DECODE_NOASSERT,"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 0, NULL);
ok(ASN1_SUCCEEDED(ret),"Got error code %d.\n",ret);
ok(!!decoder,"Decoder creation failed.\n");
ok(decoder->magic==0x44434544,"Got invalid magic = %08x.\n",decoder->magic);
ok(!decoder->version,"Got incorrect version = %08x.\n",decoder->version);
ok(decoder->module==mod,"Got incorrect module = %p.\n",decoder->module);
ok(decoder->buf==buf,"Got incorrect buf = %s.\n",decoder->buf);
ok(!decoder->size,"Got incorrect size = %u.\n",decoder->size);
ok(!decoder->len,"Got incorrect length = %u.\n",decoder->len);
ok(decoder->err==ASN1_SUCCESS,"Got incorrect err = %d.\n",decoder->err);
ok(!decoder->bit,"Got incorrect bit = %u.\n",decoder->bit);
ok(decoder->pos==buf,"Got incorrect pos = %s.\n",decoder->pos);
ok(decoder->eRule == ASN1_BER_RULE_DER,"Got incorrect eRule = %08x.\n",decoder->eRule);
ok(decoder->dwFlags == (ASN1DECODE_NOASSERT|ASN1DECODE_SETBUFFER), "Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 2, NULL);
ok(ASN1_SUCCEEDED(ret),"Got error code %d.\n",ret);
ok(!!decoder,"Decoder creation failed.\n");
ok(decoder->magic==0x44434544,"Got invalid magic = %08x.\n",decoder->magic);
ok(!decoder->version,"Got incorrect version = %08x.\n",decoder->version);
ok(decoder->module==mod,"Got incorrect module = %p.\n",decoder->module);
ok(decoder->buf==buf,"Got incorrect buf = %p.\n",decoder->buf);
ok(decoder->size==2,"Got incorrect size = %u.\n",decoder->size);
ok(!decoder->len,"Got incorrect length = %u.\n",decoder->len);
ok(decoder->err==ASN1_SUCCESS,"Got incorrect err = %d.\n",decoder->err);
ok(!decoder->bit,"Got incorrect bit = %u.\n",decoder->bit);
ok(decoder->pos==buf,"Got incorrect pos = %p.\n",decoder->pos);
ok(decoder->eRule == ASN1_BER_RULE_DER,"Got incorrect eRule = %08x.\n",decoder->eRule);
ok(decoder->dwFlags == (ASN1DECODE_NOASSERT|ASN1DECODE_SETBUFFER),"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 4, NULL);
ok(ASN1_SUCCEEDED(ret),"Got error code %d.\n",ret);
ok(!!decoder,"Decoder creation failed.\n");
ok(decoder->magic==0x44434544,"Got invalid magic = %08x.\n",decoder->magic);
ok(!decoder->version,"Got incorrect version = %08x.\n",decoder->version);
ok(decoder->module==mod,"Got incorrect module = %p.\n",decoder->module);
ok(decoder->buf==buf,"Got incorrect buf = %p.\n",decoder->buf);
ok(decoder->size==4,"Got incorrect size = %u.\n",decoder->size);
ok(!decoder->len,"Got incorrect length = %u.\n",decoder->len);
ok(decoder->err==ASN1_SUCCESS,"Got incorrect err = %d.\n",decoder->err);
ok(!decoder->bit,"Got incorrect bit = %u.\n",decoder->bit);
ok(decoder->pos==buf,"Got incorrect pos = %p.\n",decoder->pos);
ok(decoder->eRule == ASN1_BER_RULE_DER,"Got incorrect rule = %08x.\n",decoder->eRule);
ok(decoder->dwFlags == (ASN1DECODE_NOASSERT|ASN1DECODE_SETBUFFER),"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ASN1_CloseModule(mod);
mod = ASN1_CreateModule(ASN1_THIS_VERSION, ASN1_BER_RULE_DER, ASN1FLAGS_NONE, 1, encfn, decfn, freefn, size, name);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 0, NULL);
ok(decoder->dwFlags == ASN1DECODE_SETBUFFER,"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 4, NULL);
ok(decoder->dwFlags == ASN1DECODE_SETBUFFER,"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ASN1_CloseModule(mod);
mod = ASN1_CreateModule(ASN1_THIS_VERSION, ASN1_PER_RULE_ALIGNED, ASN1FLAGS_NOASSERT, 1, encfn, decfn, freefn, size, name);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 0, NULL);
ok(ASN1_SUCCEEDED(ret),"Got error code %d.\n",ret);
ok(!!decoder,"Decoder creation failed.\n");
ok(decoder->magic==0x44434544,"Got invalid magic = %08x.\n",decoder->magic);
ok(!decoder->version,"Got incorrect version = %08x.\n",decoder->version);
ok(decoder->module==mod,"Got incorrect module = %p.\n",decoder->module);
ok(decoder->buf==buf,"Got incorrect buf = %s.\n",decoder->buf);
ok(!decoder->size,"Got incorrect size = %u.\n",decoder->size);
ok(!decoder->len,"Got incorrect length = %u.\n",decoder->len);
ok(decoder->err==ASN1_SUCCESS,"Got incorrect err = %d.\n",decoder->err);
ok(!decoder->bit,"Got incorrect bit = %u.\n",decoder->bit);
ok(decoder->pos==buf,"Got incorrect pos = %s.\n",decoder->pos);
ok(decoder->eRule == ASN1_PER_RULE_ALIGNED,"Got incorrect eRule = %08x.\n",decoder->eRule);
ok(decoder->dwFlags == (ASN1DECODE_NOASSERT|ASN1DECODE_SETBUFFER),"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 4, NULL);
ok(!!decoder,"Decoder creation failed.\n");
ok(decoder->magic==0x44434544,"Got invalid magic = %08x.\n",decoder->magic);
ok(!decoder->version,"Got incorrect version = %08x.\n",decoder->version);
ok(decoder->module==mod,"Got incorrect module = %p.\n",decoder->module);
ok(decoder->buf==buf,"Got incorrect buf = %p.\n",decoder->buf);
ok(decoder->size==4,"Got incorrect size = %u.\n",decoder->size);
ok(!decoder->len,"Got incorrect length = %u.\n",decoder->len);
ok(decoder->err==ASN1_SUCCESS,"Got incorrect err = %d.\n",decoder->err);
ok(!decoder->bit,"Got incorrect bit = %u.\n",decoder->bit);
ok(decoder->pos==buf,"Got incorrect pos = %p.\n",decoder->pos);
ok(decoder->eRule == ASN1_PER_RULE_ALIGNED,"Got incorrect rule = %08x.\n",decoder->eRule);
ok(decoder->dwFlags == (ASN1FLAGS_NOASSERT|ASN1DECODE_SETBUFFER),"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ASN1_CloseModule(mod);
mod = ASN1_CreateModule(ASN1_THIS_VERSION, ASN1_PER_RULE_ALIGNED, ASN1FLAGS_NONE, 1, encfn, decfn, freefn, size, name);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 0, NULL);
ok(decoder->dwFlags == ASN1DECODE_SETBUFFER,"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ret = ASN1_CreateDecoder(mod, &decoder, buf, 4, NULL);
ok(decoder->dwFlags == ASN1DECODE_SETBUFFER,"Got incorrect dwFlags = %08x.\n",decoder->dwFlags);
ASN1_CloseModule(mod);
}
START_TEST(asn1)
{
test_CreateModule();
test_CreateEncoder();
test_CreateDecoder();
}