implemented append mode for xcbc, testcase
[strongswan.git] / src / charon / plugins / unit_tester / tests / test_med_db.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <library.h>
17 #include <daemon.h>
18 #include <utils/enumerator.h>
19
20 #include <unistd.h>
21
22 /*******************************************************************************
23 * fetch public key from mediation database
24 ******************************************************************************/
25
26 bool test_med_db()
27 {
28 char keyid_buf[] = {
29 0xed,0x90,0xe6,0x4f,0xec,0xa2,0x1f,0x4b,
30 0x68,0x97,0x99,0x24,0x22,0xe0,0xde,0x21,
31 0xb9,0xd6,0x26,0x29
32 };
33 chunk_t keyid = chunk_from_buf(keyid_buf);
34 identification_t *id, *found;
35 enumerator_t *enumerator;
36 auth_info_t *auth;
37 public_key_t *public;
38 bool good = FALSE;
39
40 id = identification_create_from_encoding(ID_KEY_ID, keyid);
41 enumerator = charon->credentials->create_public_enumerator(
42 charon->credentials, KEY_ANY, id, NULL);
43 while (enumerator->enumerate(enumerator, &public, &auth))
44 {
45 found = public->get_id(public, ID_PUBKEY_SHA1);
46 good = chunk_equals(id->get_encoding(id), found->get_encoding(found));
47 }
48 enumerator->destroy(enumerator);
49 id->destroy(id);
50 return good;
51 }
52