diff options
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_testvectors.c')
-rw-r--r-- | src/gnsrecord/test_gnsrecord_testvectors.c | 131 |
1 files changed, 0 insertions, 131 deletions
diff --git a/src/gnsrecord/test_gnsrecord_testvectors.c b/src/gnsrecord/test_gnsrecord_testvectors.c deleted file mode 100644 index bb4922417..000000000 --- a/src/gnsrecord/test_gnsrecord_testvectors.c +++ /dev/null | |||
@@ -1,131 +0,0 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_util_lib.h" | ||
3 | #include "gnunet_signatures.h" | ||
4 | #include "gnunet_gns_service.h" | ||
5 | #include "gnunet_gnsrecord_lib.h" | ||
6 | #include "gnunet_dnsparser_lib.h" | ||
7 | #include "gnunet_testing_lib.h" | ||
8 | #include <inttypes.h> | ||
9 | |||
10 | |||
11 | |||
12 | static char *d = | ||
13 | "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98"; | ||
14 | |||
15 | |||
16 | static char *zid = | ||
17 | "00010000677c477d2d93097c85b195c6f96d84ff61f5982c2c4fe02d5a11fedfb0c2901f"; | ||
18 | |||
19 | #define RRCOUNT 2 | ||
20 | #define LABEL "namesystem" | ||
21 | |||
22 | #define R0_EXPIRATION | ||
23 | #define R0_DATA_SIZE 4 | ||
24 | #define R0_TYPE 1 | ||
25 | #define R0_FLAGS 0 | ||
26 | #define R0_DATA "01020304" | ||
27 | |||
28 | /* Record #1*/ | ||
29 | #define R1_EXPIRATION 26147096139323793 | ||
30 | #define R1_DATA_SIZE 36 | ||
31 | #define R1_TYPE 65536 | ||
32 | #define R1_FLAGS 2 | ||
33 | #define R1_DATA \ | ||
34 | "000100000e601be42eb57fb4697610cf3a3b18347b65a33f025b5b174abefb30807bfecf" | ||
35 | |||
36 | #define R1_RRBLOCK \ | ||
37 | "000100008e16da87203b5159c5538e9b765742e968c54af9afbc0890dc80205ad14c84e107b0c115fc0089aa38b9c7ab9cbe1d77040d282a51a2ad493f61f3495f02d8170fe473a55ec6bdf9a509ab1701ffc37ea3bb4cac4a672520986df96e67cc1a73000000940000000f0034e53be193799100e4837eb5d04f92903de4b5234e8ccac5736c9793379a59c33375fc8951aca2eb7aad067bf9af60bf26758646a17f5e5c3b6215f94079545b1c4d4f1b2ebb22c2b4dad44126817b6f001530d476401dd67ac0148554e806353da9e4298079f3e1b16942c48d90c4360c61238c40d9d52911aea52cc0037ac7160bb3cf5b2f4a722fd96b" | ||
38 | |||
39 | int parsehex (char *src, char *dst, size_t dstlen, int invert) | ||
40 | { | ||
41 | char *line = src; | ||
42 | char *data = line; | ||
43 | int off; | ||
44 | int read_byte; | ||
45 | int data_len = 0; | ||
46 | |||
47 | while (sscanf (data, " %02x%n", &read_byte, &off) == 1) | ||
48 | { | ||
49 | if (invert) | ||
50 | dst[dstlen - 1 - data_len++] = read_byte; | ||
51 | else | ||
52 | dst[data_len++] = read_byte; | ||
53 | data += off; | ||
54 | } | ||
55 | return data_len; | ||
56 | } | ||
57 | |||
58 | void | ||
59 | res_checker (void *cls, | ||
60 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) | ||
61 | { | ||
62 | int r0_found = 0; | ||
63 | int r1_found = 0; | ||
64 | char r0_data[R0_DATA_SIZE]; | ||
65 | char r1_data[R1_DATA_SIZE]; | ||
66 | parsehex (R0_DATA, (char*) r0_data, 0, 0); | ||
67 | parsehex (R1_DATA, (char*) r1_data, 0, 0); | ||
68 | GNUNET_assert (rd_count == RRCOUNT); | ||
69 | for (int i = 0; i < RRCOUNT; i++) | ||
70 | { | ||
71 | if (rd[i].record_type == R0_TYPE) | ||
72 | { | ||
73 | if (0 != memcmp (rd[i].data, r0_data, R0_DATA_SIZE)) | ||
74 | { | ||
75 | printf ("R0 Data mismatch\n"); | ||
76 | continue; | ||
77 | } | ||
78 | if (rd[i].expiration_time != R0_EXPIRATION) | ||
79 | { | ||
80 | printf ("R0 expiration mismatch\n"); | ||
81 | continue; | ||
82 | } | ||
83 | r0_found = 1; | ||
84 | } | ||
85 | if (rd[i].record_type == R1_TYPE) | ||
86 | { | ||
87 | if (0 != memcmp (rd[i].data, r1_data, R1_DATA_SIZE)) | ||
88 | { | ||
89 | printf ("R1 Data mismatch\n"); | ||
90 | continue; | ||
91 | } | ||
92 | if (rd[i].expiration_time != R1_EXPIRATION) | ||
93 | { | ||
94 | printf ("R1 expiration mismatch\n"); | ||
95 | continue; | ||
96 | } | ||
97 | |||
98 | r1_found = 1; | ||
99 | } | ||
100 | |||
101 | } | ||
102 | GNUNET_assert (r0_found); | ||
103 | GNUNET_assert (r1_found); | ||
104 | } | ||
105 | |||
106 | |||
107 | int | ||
108 | main () | ||
109 | { | ||
110 | struct GNUNET_IDENTITY_PrivateKey priv; | ||
111 | struct GNUNET_IDENTITY_PublicKey pub; | ||
112 | struct GNUNET_IDENTITY_PublicKey pub_parsed; | ||
113 | struct GNUNET_GNSRECORD_Block *rrblock; | ||
114 | char *bdata; | ||
115 | |||
116 | parsehex (d,(char*) &priv.ecdsa_key, sizeof (priv.ecdsa_key), 1); | ||
117 | priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
118 | parsehex (zid,(char*) &pub_parsed, 0, 0); | ||
119 | GNUNET_IDENTITY_key_get_public (&priv, &pub); | ||
120 | GNUNET_assert (0 == memcmp (&pub, &pub_parsed, sizeof (pub))); | ||
121 | rrblock = GNUNET_malloc (strlen (R1_RRBLOCK) / 2); | ||
122 | parsehex (R1_RRBLOCK, (char*) rrblock, 0, 0); | ||
123 | GNUNET_assert (GNUNET_YES | ||
124 | == GNUNET_GNSRECORD_is_critical (GNUNET_GNSRECORD_TYPE_PKEY)); | ||
125 | GNUNET_GNSRECORD_block_decrypt (rrblock, | ||
126 | &pub_parsed, | ||
127 | LABEL, | ||
128 | &res_checker, | ||
129 | NULL); | ||
130 | return 0; | ||
131 | } | ||