summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ts/ts_req_utils.c
diff options
context:
space:
mode:
authorjsing <>2014-04-21 16:32:06 +0000
committerjsing <>2014-04-21 16:32:06 +0000
commitdbe50a7f3c84521e4543ad2e5292244bd0b81414 (patch)
treebe04a70e8733f1afb3ae549ad26c1c50ec666f15 /src/lib/libcrypto/ts/ts_req_utils.c
parent4e74c38c506a70910cb7f88175f2f718983bbdc6 (diff)
downloadopenbsd-dbe50a7f3c84521e4543ad2e5292244bd0b81414.tar.gz
openbsd-dbe50a7f3c84521e4543ad2e5292244bd0b81414.tar.bz2
openbsd-dbe50a7f3c84521e4543ad2e5292244bd0b81414.zip
KNF.
Diffstat (limited to 'src/lib/libcrypto/ts/ts_req_utils.c')
-rw-r--r--src/lib/libcrypto/ts/ts_req_utils.c204
1 files changed, 112 insertions, 92 deletions
diff --git a/src/lib/libcrypto/ts/ts_req_utils.c b/src/lib/libcrypto/ts/ts_req_utils.c
index 43280c1587..7518d7ab78 100644
--- a/src/lib/libcrypto/ts/ts_req_utils.c
+++ b/src/lib/libcrypto/ts/ts_req_utils.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -62,173 +62,193 @@
62#include <openssl/x509v3.h> 62#include <openssl/x509v3.h>
63#include <openssl/ts.h> 63#include <openssl/ts.h>
64 64
65int TS_REQ_set_version(TS_REQ *a, long version) 65int
66 { 66TS_REQ_set_version(TS_REQ *a, long version)
67{
67 return ASN1_INTEGER_set(a->version, version); 68 return ASN1_INTEGER_set(a->version, version);
68 } 69}
69 70
70long TS_REQ_get_version(const TS_REQ *a) 71long
71 { 72TS_REQ_get_version(const TS_REQ *a)
73{
72 return ASN1_INTEGER_get(a->version); 74 return ASN1_INTEGER_get(a->version);
73 } 75}
74 76
75int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint) 77int
76 { 78TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint)
79{
77 TS_MSG_IMPRINT *new_msg_imprint; 80 TS_MSG_IMPRINT *new_msg_imprint;
78 81
79 if (a->msg_imprint == msg_imprint) 82 if (a->msg_imprint == msg_imprint)
80 return 1; 83 return 1;
81 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint); 84 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
82 if (new_msg_imprint == NULL) 85 if (new_msg_imprint == NULL) {
83 {
84 TSerr(TS_F_TS_REQ_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE); 86 TSerr(TS_F_TS_REQ_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
85 return 0; 87 return 0;
86 } 88 }
87 TS_MSG_IMPRINT_free(a->msg_imprint); 89 TS_MSG_IMPRINT_free(a->msg_imprint);
88 a->msg_imprint = new_msg_imprint; 90 a->msg_imprint = new_msg_imprint;
89 return 1; 91 return 1;
90 } 92}
91 93
92TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a) 94TS_MSG_IMPRINT *
93 { 95TS_REQ_get_msg_imprint(TS_REQ *a)
96{
94 return a->msg_imprint; 97 return a->msg_imprint;
95 } 98}
96 99
97int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg) 100int
98 { 101TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg)
102{
99 X509_ALGOR *new_alg; 103 X509_ALGOR *new_alg;
100 104
101 if (a->hash_algo == alg) 105 if (a->hash_algo == alg)
102 return 1; 106 return 1;
103 new_alg = X509_ALGOR_dup(alg); 107 new_alg = X509_ALGOR_dup(alg);
104 if (new_alg == NULL) 108 if (new_alg == NULL) {
105 {
106 TSerr(TS_F_TS_MSG_IMPRINT_SET_ALGO, ERR_R_MALLOC_FAILURE); 109 TSerr(TS_F_TS_MSG_IMPRINT_SET_ALGO, ERR_R_MALLOC_FAILURE);
107 return 0; 110 return 0;
108 } 111 }
109 X509_ALGOR_free(a->hash_algo); 112 X509_ALGOR_free(a->hash_algo);
110 a->hash_algo = new_alg; 113 a->hash_algo = new_alg;
111 return 1; 114 return 1;
112 } 115}
113 116
114X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a) 117X509_ALGOR *
115 { 118TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a)
119{
116 return a->hash_algo; 120 return a->hash_algo;
117 } 121}
118 122
119int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len) 123int
120 { 124TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len)
125{
121 return ASN1_OCTET_STRING_set(a->hashed_msg, d, len); 126 return ASN1_OCTET_STRING_set(a->hashed_msg, d, len);
122 } 127}
123 128
124ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a) 129ASN1_OCTET_STRING *
125 { 130TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a)
131{
126 return a->hashed_msg; 132 return a->hashed_msg;
127 } 133}
128 134
129int TS_REQ_set_policy_id(TS_REQ *a, ASN1_OBJECT *policy) 135int
130 { 136TS_REQ_set_policy_id(TS_REQ *a, ASN1_OBJECT *policy)
137{
131 ASN1_OBJECT *new_policy; 138 ASN1_OBJECT *new_policy;
132 139
133 if (a->policy_id == policy) 140 if (a->policy_id == policy)
134 return 1; 141 return 1;
135 new_policy = OBJ_dup(policy); 142 new_policy = OBJ_dup(policy);
136 if (new_policy == NULL) 143 if (new_policy == NULL) {
137 {
138 TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE); 144 TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
139 return 0; 145 return 0;
140 } 146 }
141 ASN1_OBJECT_free(a->policy_id); 147 ASN1_OBJECT_free(a->policy_id);
142 a->policy_id = new_policy; 148 a->policy_id = new_policy;
143 return 1; 149 return 1;
144 } 150}
145 151
146ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a) 152ASN1_OBJECT *
147 { 153TS_REQ_get_policy_id(TS_REQ *a)
154{
148 return a->policy_id; 155 return a->policy_id;
149 } 156}
150 157
151int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce) 158int
152 { 159TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce)
160{
153 ASN1_INTEGER *new_nonce; 161 ASN1_INTEGER *new_nonce;
154 162
155 if (a->nonce == nonce) 163 if (a->nonce == nonce)
156 return 1; 164 return 1;
157 new_nonce = ASN1_INTEGER_dup(nonce); 165 new_nonce = ASN1_INTEGER_dup(nonce);
158 if (new_nonce == NULL) 166 if (new_nonce == NULL) {
159 {
160 TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE); 167 TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE);
161 return 0; 168 return 0;
162 } 169 }
163 ASN1_INTEGER_free(a->nonce); 170 ASN1_INTEGER_free(a->nonce);
164 a->nonce = new_nonce; 171 a->nonce = new_nonce;
165 return 1; 172 return 1;
166 } 173}
167 174
168const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a) 175const ASN1_INTEGER *
169 { 176TS_REQ_get_nonce(const TS_REQ *a)
177{
170 return a->nonce; 178 return a->nonce;
171 } 179}
172 180
173int TS_REQ_set_cert_req(TS_REQ *a, int cert_req) 181int
174 { 182TS_REQ_set_cert_req(TS_REQ *a, int cert_req)
183{
175 a->cert_req = cert_req ? 0xFF : 0x00; 184 a->cert_req = cert_req ? 0xFF : 0x00;
176 return 1; 185 return 1;
177 } 186}
178 187
179int TS_REQ_get_cert_req(const TS_REQ *a) 188int
180 { 189TS_REQ_get_cert_req(const TS_REQ *a)
190{
181 return a->cert_req ? 1 : 0; 191 return a->cert_req ? 1 : 0;
182 } 192}
183 193
184STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a) 194STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a)
185 { 195{
186 return a->extensions; 196 return a->extensions;
187 } 197}
188 198
189void TS_REQ_ext_free(TS_REQ *a) 199void
190 { 200TS_REQ_ext_free(TS_REQ *a)
191 if (!a) return; 201{
202 if (!a)
203 return;
192 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free); 204 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
193 a->extensions = NULL; 205 a->extensions = NULL;
194 } 206}
195 207
196int TS_REQ_get_ext_count(TS_REQ *a) 208int
197 { 209TS_REQ_get_ext_count(TS_REQ *a)
210{
198 return X509v3_get_ext_count(a->extensions); 211 return X509v3_get_ext_count(a->extensions);
199 } 212}
200 213
201int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos) 214int
202 { 215TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos)
216{
203 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos); 217 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
204 } 218}
205 219
206int TS_REQ_get_ext_by_OBJ(TS_REQ *a, ASN1_OBJECT *obj, int lastpos) 220int
207 { 221TS_REQ_get_ext_by_OBJ(TS_REQ *a, ASN1_OBJECT *obj, int lastpos)
222{
208 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos); 223 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
209 } 224}
210 225
211int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos) 226int
212 { 227TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos)
228{
213 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos); 229 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
214 } 230}
215 231
216X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc) 232X509_EXTENSION *
217 { 233TS_REQ_get_ext(TS_REQ *a, int loc)
218 return X509v3_get_ext(a->extensions,loc); 234{
219 } 235 return X509v3_get_ext(a->extensions, loc);
220 236}
221X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc) 237
222 { 238X509_EXTENSION *
223 return X509v3_delete_ext(a->extensions,loc); 239TS_REQ_delete_ext(TS_REQ *a, int loc)
224 } 240{
225 241 return X509v3_delete_ext(a->extensions, loc);
226int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc) 242}
227 { 243
228 return X509v3_add_ext(&a->extensions,ex,loc) != NULL; 244int
229 } 245TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc)
230 246{
231void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx) 247 return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
232 { 248}
249
250void *
251TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx)
252{
233 return X509V3_get_d2i(a->extensions, nid, crit, idx); 253 return X509V3_get_d2i(a->extensions, nid, crit, idx);
234 } 254}