1 /* priv.c Shishi PRIV self tests.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 main (int argc
, char *argv
[])
32 Shishi_asn1 asn1encprivpart
;
39 if (strcmp (argv
[argc
- 1], "-v") == 0 ||
40 strcmp (argv
[argc
- 1], "--verbose") == 0)
42 else if (strcmp (argv
[argc
- 1], "-d") == 0 ||
43 strcmp (argv
[argc
- 1], "--debug") == 0)
45 else if (strcmp (argv
[argc
- 1], "-b") == 0 ||
46 strcmp (argv
[argc
- 1], "--break-on-error") == 0)
48 else if (strcmp (argv
[argc
- 1], "-h") == 0 ||
49 strcmp (argv
[argc
- 1], "-?") == 0 ||
50 strcmp (argv
[argc
- 1], "--help") == 0)
52 printf ("Usage: %s [-vdbh?] [--verbose] [--debug] "
53 "[--break-on-error] [--help]\n", argv
[0]);
61 fail ("Could not initialize shishi\n");
67 shishi_cfg (handle
, strdup ("verbose"));
68 shishi_cfg (handle
, strdup ("verbose-crypto"));
71 escapeprint (NULL
, 0);
76 res
= shishi_priv (handle
, &priv
);
78 printf ("shishi_priv () => `%p'.\n", priv
);
80 success ("shishi_priv() OK\n");
82 fail ("shishi_priv() failed\n");
85 key
= shishi_priv_key (priv
);
87 success ("shishi_priv_key() OK\n");
89 fail ("shishi_priv_key() failed\n");
91 /* shishi_priv_priv */
92 asn1priv
= shishi_priv_priv (priv
);
94 success ("shishi_priv_priv() OK\n");
96 fail ("shishi_priv_priv() failed\n");
98 /* shishi_priv_encprivpart */
99 asn1encprivpart
= shishi_priv_encprivpart (priv
);
101 success ("shishi_priv_encprivpart() OK\n");
103 fail ("shishi_priv_encprivpart() failed\n");
105 /* shishi_encprivpart_set_user_data */
106 res
= shishi_encprivpart_set_user_data (handle
, asn1encprivpart
, "foo", 3);
107 if (res
== SHISHI_OK
)
108 success ("shishi_encprivpart_set_user_data() OK\n");
110 fail ("shishi_encprivpart_set_user_data() failed (%d)\n", res
);
112 /* shishi_encprivpart_user_data */
113 res
= shishi_encprivpart_user_data (handle
, asn1encprivpart
, &p
, &l
);
116 if (res
== SHISHI_OK
&& l
== 3 && memcmp (p
, "foo", 3) == 0)
117 success ("shishi_encprivpart_user_data() OK\n");
119 fail ("shishi_encprivpart_user_data() failed (%d)\n", res
);
121 /* shishi_priv_set_cksum */
122 res
= shishi_priv_set_enc_part (handle
, asn1priv
, 42, "bar", 3);
123 if (res
== SHISHI_OK
)
124 success ("shishi_priv_set_enc_part() OK\n");
126 fail ("shishi_priv_set_enc_part() failed (%d)\n", res
);
128 /* shishi_priv_enc_part_etype */
129 res
= shishi_priv_enc_part_etype (handle
, asn1priv
, &t
);
131 printf ("type=%d\n", t
);
132 if (res
== SHISHI_OK
&& t
== 42)
133 success ("shishi_priv_enc_part_etype() OK\n");
135 fail ("shishi_priv_enc_part_etype() failed (%d)\n", res
);
137 /* shishi_priv_process */
138 res
= shishi_priv_process (priv
, key
);
139 if (res
== SHISHI_PRIV_BAD_KEYTYPE
) /* t==42 unsupported etype */
140 success ("shishi_priv_proces() OK\n");
142 fail ("shishi_priv_process() failed (%d)\n", res
);
144 /* shishi_priv_priv_der() */
145 res
= shishi_priv_priv_der (priv
, &p
, &l
);
146 if (res
== SHISHI_OK
)
147 success ("shishi_priv_priv_der() OK\n");
149 fail ("shishi_priv_priv_der() failed\n");
151 /* shishi_priv_to_file() */
152 res
= shishi_priv_to_file (handle
, asn1priv
, SHISHI_FILETYPE_TEXT
,
154 if (res
== SHISHI_OK
)
155 success ("shishi_priv_to_file() OK\n");
157 fail ("shishi_priv_to_file() failed\n");
159 /* shishi_priv_done() */
160 shishi_priv_done (priv
);
161 success ("shishi_priv_done() OK\n");
163 /* shishi_authenticator_from_file() */
164 res
= shishi_priv_from_file (handle
, &asn1priv
, SHISHI_FILETYPE_TEXT
,
166 if (res
== SHISHI_OK
)
167 success ("shishi_priv_from_file() OK\n");
169 fail ("shishi_priv_from_file() failed\n");
173 /* shishi_priv_print() */
174 res
= shishi_priv_print (handle
, stdout
, asn1priv
);
175 if (res
== SHISHI_OK
)
176 success ("shishi_priv_print() OK\n");
178 fail ("shishi_priv_print() failed\n");
182 res
= shishi_new_a2d (handle
, asn1priv
, &q
, &m
);
183 if (res
== SHISHI_OK
)
184 success ("shishi_a2d() OK\n");
186 fail ("shishi_a2d() failed\n");
188 /* Compare DER encodings of authenticators */
189 if (l
> 0 && m
> 0 && l
== m
&& memcmp (p
, q
, l
) == 0)
190 success ("DER comparison OK\n");
192 fail ("DER comparison failed\n");
198 res
= unlink ("priv.tmp");
200 success ("unlink() OK\n");
202 fail ("unlink() failed\n");
204 shishi_done (handle
);
207 printf ("PRIV self tests done with %d errors\n", error_count
);
209 return error_count
? 1 : 0;