File: t_asn1.c

package info (click to toggle)
samba 2%3A3.2.5-4lenny15
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 124,704 kB
  • ctags: 69,181
  • sloc: ansic: 564,153; xml: 219,271; sh: 11,039; perl: 4,458; makefile: 4,301; python: 1,975; cpp: 1,224; exp: 1,147; yacc: 881; awk: 557; csh: 58; sed: 45
file content (61 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (C) 2004 by Volker Lendecke
 *
 * Test harness for asn1_write_*, inspired by Love Hornquist Astrand
 */

#include "includes.h"

static DATA_BLOB tests[] = {
        {"\x02\x01\x00", 3, NULL},
        {"\x02\x01\x7f", 3, NULL},
        {"\x02\x02\x00\x80", 4, NULL},
        {"\x02\x02\x01\x00", 4, NULL},
        {"\x02\x01\x80", 3, NULL},
        {"\x02\x02\xff\x7f", 4, NULL},
        {"\x02\x01\xff", 3, NULL},
        {"\x02\x02\xff\x01", 4, NULL},
        {"\x02\x02\x00\xff", 4, NULL},
        {"\x02\x04\x80\x00\x00\x00", 6, NULL},
        {"\x02\x04\x7f\xff\xff\xff", 6, NULL},
	{NULL, 0, NULL}
};

static int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
		       0x80000000, 0x7fffffff};

int main(void)
{
	int i = 0;
	int val;
	bool ok = True;

	for (i=0; tests[i].data != NULL; i++) {
		ASN1_DATA data;
		DATA_BLOB blob;

		ZERO_STRUCT(data);
		asn1_write_Integer(&data, values[i]);

		if ((data.length != tests[i].length) ||
		    (memcmp(data.data, tests[i].data, data.length) != 0)) {
			printf("Test for %d failed\n", values[i]);
			ok = False;
		}

		blob.data = data.data;
		blob.length = data.length;
		asn1_load(&data, blob);
		if (!asn1_read_Integer(&data, &val)) {
			printf("Could not read our own Integer for %d\n",
			       values[i]);
			ok = False;
		}
		if (val != values[i]) {
			printf("%d -> ASN -> Int %d\n", values[i], val);
			ok = False;
		}
	}

	return ok ? 0 : 1;
}