fixed typo
[strongswan.git] / src / libstrongswan / crypto / certinfo.c
1 /**
2 * @file certinfo.c
3 *
4 * @brief Implementation of certinfo_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Andreas Steffen
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <time.h>
24
25 #include <library.h>
26
27 #include "certinfo.h"
28
29 typedef struct private_certinfo_t private_certinfo_t;
30
31 /**
32 * Private data of a certinfo_t object.
33 */
34 struct private_certinfo_t {
35 /**
36 * Public interface for this certificate status information object.
37 */
38 certinfo_t public;
39
40 /**
41 * Serial number of the certificate
42 */
43 chunk_t serialNumber;
44
45 /**
46 * Certificate status
47 */
48 cert_status_t status;
49
50 /**
51 * Certificate status is for one-time use only
52 */
53 bool once;
54
55 /**
56 * Time when the certificate status info was generated
57 */
58 time_t thisUpdate;
59
60 /**
61 * Time when an updated certifcate status info will be available
62 */
63 time_t nextUpdate;
64
65 /**
66 * Time of certificate revocation
67 */
68 time_t revocationTime;
69
70 /**
71 * Reason of certificate revocation
72 */
73 crl_reason_t revocationReason;
74 };
75
76 ENUM(cert_status_names, CERT_GOOD, CERT_UNTRUSTED,
77 "good",
78 "revoked",
79 "unknown",
80 "unknown",
81 "untrusted",
82 );
83
84 ENUM(crl_reason_names, REASON_UNSPECIFIED, REASON_REMOVE_FROM_CRL,
85 "unspecified",
86 "key compromise",
87 "ca compromise",
88 "affiliation changed",
89 "superseded",
90 "cessation of operation",
91 "certificate hold",
92 "reason #7",
93 "remove from crl",
94 );
95
96 /**
97 * Implements certinfo_t.equals_serialNumber
98 */
99 static bool equals_serialNumber(const private_certinfo_t *this, const private_certinfo_t *that)
100 {
101 return chunk_equals(this->serialNumber, that->serialNumber);
102 }
103
104 /**
105 * Implements certinfo_t.get_serialNumber
106 */
107 static chunk_t get_serialNumber(const private_certinfo_t *this)
108 {
109 return this->serialNumber;
110 }
111
112 /**
113 * Implements certinfo_t.set_status
114 */
115 static void set_status(private_certinfo_t *this, cert_status_t status)
116 {
117 this->status = status;
118 }
119
120 /**
121 * Implements certinfo_t.get_status
122 */
123 static cert_status_t get_status(const private_certinfo_t *this)
124 {
125 return this->status;
126 }
127
128 /**
129 * Implements certinfo_t.set_nextUpdate
130 */
131 static void set_nextUpdate(private_certinfo_t *this, time_t nextUpdate)
132 {
133 this->nextUpdate = nextUpdate;
134 }
135
136 /**
137 * Implements certinfo_t.get_nextUpdate
138 */
139 static time_t get_nextUpdate(const private_certinfo_t *this)
140 {
141 return this->nextUpdate;
142 }
143
144 /**
145 * Implements certinfo_t.set_revocationTime
146 */
147 static void set_revocationTime(private_certinfo_t *this, time_t revocationTime)
148 {
149 this->revocationTime = revocationTime;
150 }
151
152 /**
153 * Implements certinfo_t.get_revocationTime
154 */
155 static time_t get_revocationTime(const private_certinfo_t *this)
156 {
157 return this->revocationTime;
158 }
159
160 /**
161 * Implements certinfo_t.set_revocationReason
162 */
163 static void set_revocationReason(private_certinfo_t *this, crl_reason_t reason)
164 {
165 this->revocationReason = reason;
166 }
167
168 /**
169 * Implements certinfo_t.get_revocationReason
170 */
171 static crl_reason_t get_revocationReason(const private_certinfo_t *this)
172 {
173 return this->revocationReason;
174 }
175
176 /**
177 * Implements certinfo_t.destroy
178 */
179 static void destroy(private_certinfo_t *this)
180 {
181 free(this->serialNumber.ptr);
182 free(this);
183 }
184
185 /*
186 * Described in header.
187 */
188 certinfo_t *certinfo_create(chunk_t serial)
189 {
190 private_certinfo_t *this = malloc_thing(private_certinfo_t);
191
192 /* initialize */
193 this->serialNumber = chunk_clone(serial);
194 this->status = CERT_UNDEFINED;
195 this->nextUpdate = UNDEFINED_TIME;
196 this->revocationTime = UNDEFINED_TIME;
197 this->revocationReason = REASON_UNSPECIFIED;
198
199 /* public functions */
200 this->public.equals_serialNumber = (bool (*) (const certinfo_t*,const certinfo_t*))equals_serialNumber;
201 this->public.get_serialNumber = (chunk_t (*) (const certinfo_t*))get_serialNumber;
202 this->public.set_status = (void (*) (certinfo_t*,cert_status_t))set_status;
203 this->public.get_status = (cert_status_t (*) (const certinfo_t*))get_status;
204 this->public.set_nextUpdate = (void (*) (certinfo_t*,time_t))set_nextUpdate;
205 this->public.get_nextUpdate = (time_t (*) (const certinfo_t*))get_nextUpdate;
206 this->public.set_revocationTime = (void (*) (certinfo_t*,time_t))set_revocationTime;
207 this->public.get_revocationTime = (time_t (*) (const certinfo_t*))get_revocationTime;
208 this->public.set_revocationReason = (void (*) (certinfo_t*, crl_reason_t))set_revocationReason;
209 this->public.get_revocationReason = (crl_reason_t(*) (const certinfo_t*))get_revocationReason;
210 this->public.destroy = (void (*) (certinfo_t*))destroy;
211
212 return &this->public;
213 }