s3:registry: add an extra check for dsize==0 to regdb_fetch_keys_internal()
[Samba/fernandojvsilva.git] / source3 / torture / t_asn1.c
blob0ccd97b6d5748b3eceeaa65ca80fe3b449c727a9
1 /*
2 * Copyright (C) 2004 by Volker Lendecke
4 * Test harness for asn1_write_*, inspired by Love Hornquist Astrand
5 */
7 #include "includes.h"
9 static DATA_BLOB tests[] = {
10 {"\x02\x01\x00", 3, NULL},
11 {"\x02\x01\x7f", 3, NULL},
12 {"\x02\x02\x00\x80", 4, NULL},
13 {"\x02\x02\x01\x00", 4, NULL},
14 {"\x02\x01\x80", 3, NULL},
15 {"\x02\x02\xff\x7f", 4, NULL},
16 {"\x02\x01\xff", 3, NULL},
17 {"\x02\x02\xff\x01", 4, NULL},
18 {"\x02\x02\x00\xff", 4, NULL},
19 {"\x02\x04\x80\x00\x00\x00", 6, NULL},
20 {"\x02\x04\x7f\xff\xff\xff", 6, NULL},
21 {NULL, 0, NULL}
24 static int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
25 0x80000000, 0x7fffffff};
27 int main(void)
29 int i = 0;
30 int val;
31 bool ok = True;
33 for (i=0; tests[i].data != NULL; i++) {
34 ASN1_DATA *data;
35 DATA_BLOB blob;
37 data = asn1_init(talloc_tos());
38 if (!data) {
39 return -1;
42 asn1_write_Integer(data, values[i]);
44 if ((data->length != tests[i].length) ||
45 (memcmp(data>data, tests[i].data, data->length) != 0)) {
46 printf("Test for %d failed\n", values[i]);
47 ok = False;
50 blob.data = data->data;
51 blob.length = data->length;
52 asn1_load(data, blob);
53 if (!asn1_read_Integer(data, &val)) {
54 printf("Could not read our own Integer for %d\n",
55 values[i]);
56 ok = False;
58 if (val != values[i]) {
59 printf("%d -> ASN -> Int %d\n", values[i], val);
60 ok = False;
64 return ok ? 0 : 1;