1 /* priv.c Shishi PRIV self tests.
2 * Copyright (C) 2002, 2003, 2006 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 test (Shishi
* handle
)
30 Shishi_asn1 asn1encprivpart
;
37 shishi_cfg (handle
, strdup ("verbose-crypto"));
40 res
= shishi_priv (handle
, &priv
);
42 printf ("shishi_priv () => `%p'.\n", priv
);
44 success ("shishi_priv() OK\n");
46 fail ("shishi_priv() failed\n");
49 key
= shishi_priv_key (priv
);
51 success ("shishi_priv_key() OK\n");
53 fail ("shishi_priv_key() failed\n");
55 /* shishi_priv_priv */
56 asn1priv
= shishi_priv_priv (priv
);
58 success ("shishi_priv_priv() OK\n");
60 fail ("shishi_priv_priv() failed\n");
62 /* shishi_priv_encprivpart */
63 asn1encprivpart
= shishi_priv_encprivpart (priv
);
65 success ("shishi_priv_encprivpart() OK\n");
67 fail ("shishi_priv_encprivpart() failed\n");
69 /* shishi_encprivpart_set_user_data */
70 res
= shishi_encprivpart_set_user_data (handle
, asn1encprivpart
, "foo", 3);
72 success ("shishi_encprivpart_set_user_data() OK\n");
74 fail ("shishi_encprivpart_set_user_data() failed (%d)\n", res
);
76 /* shishi_encprivpart_user_data */
77 res
= shishi_encprivpart_user_data (handle
, asn1encprivpart
, &p
, &l
);
80 if (res
== SHISHI_OK
&& l
== 3 && memcmp (p
, "foo", 3) == 0)
81 success ("shishi_encprivpart_user_data() OK\n");
83 fail ("shishi_encprivpart_user_data() failed (%d)\n", res
);
86 /* shishi_priv_set_cksum */
87 res
= shishi_priv_set_enc_part (handle
, asn1priv
, 42, "bar", 3);
89 success ("shishi_priv_set_enc_part() OK\n");
91 fail ("shishi_priv_set_enc_part() failed (%d)\n", res
);
93 /* shishi_priv_enc_part_etype */
94 res
= shishi_priv_enc_part_etype (handle
, asn1priv
, &t
);
96 printf ("type=%d\n", t
);
97 if (res
== SHISHI_OK
&& t
== 42)
98 success ("shishi_priv_enc_part_etype() OK\n");
100 fail ("shishi_priv_enc_part_etype() failed (%d)\n", res
);
102 /* shishi_priv_process */
103 res
= shishi_priv_process (priv
, key
);
104 if (res
== SHISHI_PRIV_BAD_KEYTYPE
) /* t==42 unsupported etype */
105 success ("shishi_priv_proces() OK\n");
107 fail ("shishi_priv_process() failed (%d)\n", res
);
109 /* shishi_priv_priv_der() */
110 res
= shishi_priv_priv_der (priv
, &p
, &l
);
111 if (res
== SHISHI_OK
)
112 success ("shishi_priv_priv_der() OK\n");
114 fail ("shishi_priv_priv_der() failed\n");
116 /* shishi_priv_to_file() */
117 res
= shishi_priv_to_file (handle
, asn1priv
, SHISHI_FILETYPE_TEXT
,
119 if (res
== SHISHI_OK
)
120 success ("shishi_priv_to_file() OK\n");
122 fail ("shishi_priv_to_file() failed\n");
124 /* shishi_priv_done() */
125 shishi_priv_done (priv
);
126 success ("shishi_priv_done() OK\n");
128 /* shishi_authenticator_from_file() */
129 res
= shishi_priv_from_file (handle
, &asn1priv
, SHISHI_FILETYPE_TEXT
,
131 if (res
== SHISHI_OK
)
132 success ("shishi_priv_from_file() OK\n");
134 fail ("shishi_priv_from_file() failed\n");
138 /* shishi_priv_print() */
139 res
= shishi_priv_print (handle
, stdout
, asn1priv
);
140 if (res
== SHISHI_OK
)
141 success ("shishi_priv_print() OK\n");
143 fail ("shishi_priv_print() failed\n");
146 /* shishi_asn1_to_der() */
147 res
= shishi_asn1_to_der (handle
, asn1priv
, &q
, &m
);
148 if (res
== SHISHI_OK
)
149 success ("shishi_asn1_to_der() OK\n");
151 fail ("shishi_asn1_to_der() failed\n");
153 shishi_asn1_done (handle
, asn1priv
);
155 /* Compare DER encodings of authenticators */
156 if (l
> 0 && m
> 0 && l
== m
&& memcmp (p
, q
, l
) == 0)
157 success ("DER comparison OK\n");
159 fail ("DER comparison failed\n");
165 res
= unlink ("priv.tmp");
167 success ("unlink() OK\n");
169 fail ("unlink() failed\n");