Removed strayed code fragment
[strongswan.git] / src / charon / credentials / sets / ocsp_response_wrapper.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 "ocsp_response_wrapper.h"
17
18 typedef struct private_ocsp_response_wrapper_t private_ocsp_response_wrapper_t;
19
20 /**
21 * private data of ocsp_response_wrapper
22 */
23 struct private_ocsp_response_wrapper_t {
24
25 /**
26 * public functions
27 */
28 ocsp_response_wrapper_t public;
29
30 /**
31 * wrapped OCSP response
32 */
33 ocsp_response_t *response;
34 };
35
36 /**
37 * enumerator for ocsp_response_wrapper_t.create_cert_enumerator()
38 */
39 typedef struct {
40 /** implements enumerator_t */
41 enumerator_t public;
42 /** enumerator over ocsp response */
43 enumerator_t *inner;
44 /** type of cert */
45 certificate_type_t cert;
46 /** type of key */
47 key_type_t key;
48 /** filtering identity */
49 identification_t *id;
50 } wrapper_enumerator_t;
51
52 /**
53 * enumerate function wrapper_enumerator_t
54 */
55 static bool enumerate(wrapper_enumerator_t *this, certificate_t **cert)
56 {
57 certificate_t *current;
58 public_key_t *public;
59
60 while (this->inner->enumerate(this->inner, &current))
61 {
62 if (this->cert != CERT_ANY && this->cert != current->get_type(current))
63 { /* CERT type requested, but does not match */
64 continue;
65 }
66 public = current->get_public_key(current);
67 if (this->key != KEY_ANY && !public)
68 { /* key type requested, but no public key */
69 DESTROY_IF(public);
70 continue;
71 }
72 if (this->key != KEY_ANY && public && this->key != public->get_type(public))
73 { /* key type requested, but public key has another type */
74 DESTROY_IF(public);
75 continue;
76 }
77 DESTROY_IF(public);
78 if (this->id && !current->has_subject(current, this->id))
79 { /* subject requested, but does not match */
80 continue;
81 }
82 *cert = current;
83 return TRUE;
84 }
85 return FALSE;
86 }
87
88 /**
89 * destroy function for wrapper_enumerator_t
90 */
91 static void enumerator_destroy(wrapper_enumerator_t *this)
92 {
93 this->inner->destroy(this->inner);
94 free(this);
95 }
96
97 /**
98 * implementation of ocsp_response_wrapper_t.set.create_cert_enumerator
99 */
100 static enumerator_t *create_enumerator(private_ocsp_response_wrapper_t *this,
101 certificate_type_t cert, key_type_t key,
102 identification_t *id, bool trusted)
103 {
104 wrapper_enumerator_t *enumerator;
105
106 if (trusted)
107 {
108 return NULL;
109 }
110
111 enumerator = malloc_thing(wrapper_enumerator_t);
112 enumerator->cert = cert;
113 enumerator->key = key;
114 enumerator->id = id;
115 enumerator->inner = this->response->create_cert_enumerator(this->response);
116 enumerator->public.enumerate = (void*)enumerate;
117 enumerator->public.destroy = (void*)enumerator_destroy;
118 return &enumerator->public;
119 }
120
121 /**
122 * Implementation of ocsp_response_wrapper_t.destroy
123 */
124 static void destroy(private_ocsp_response_wrapper_t *this)
125 {
126 free(this);
127 }
128
129 /*
130 * see header file
131 */
132 ocsp_response_wrapper_t *ocsp_response_wrapper_create(ocsp_response_t *response)
133 {
134 private_ocsp_response_wrapper_t *this = malloc_thing(private_ocsp_response_wrapper_t);
135
136 this->public.set.create_private_enumerator = (void*)return_null;
137 this->public.set.create_cert_enumerator = (void*)create_enumerator;
138 this->public.set.create_shared_enumerator = (void*)return_null;
139 this->public.set.create_cdp_enumerator = (void*)return_null;
140 this->public.set.cache_cert = (void*)nop;
141 this->public.destroy = (void(*)(ocsp_response_wrapper_t*))destroy;
142
143 this->response = response;
144
145 return &this->public;
146 }
147