diff options
author | jsing <> | 2014-04-18 07:09:23 +0000 |
---|---|---|
committer | jsing <> | 2014-04-18 07:09:23 +0000 |
commit | 47f3f755de44fe72026c26b61f3534245e51ce63 (patch) | |
tree | 530ccfa4465ec1e141f16ac55eccd5e456d9dadf /src/lib/libcrypto/asn1/a_object.c | |
parent | f843014abcc7498613638ca7bdc47b3123ea2544 (diff) | |
download | openbsd-47f3f755de44fe72026c26b61f3534245e51ce63.tar.gz openbsd-47f3f755de44fe72026c26b61f3534245e51ce63.tar.bz2 openbsd-47f3f755de44fe72026c26b61f3534245e51ce63.zip |
More KNF.
Diffstat (limited to 'src/lib/libcrypto/asn1/a_object.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_object.c | 287 |
1 files changed, 159 insertions, 128 deletions
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index e73b1223de..293b269c21 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -64,28 +64,32 @@ | |||
64 | #include <openssl/objects.h> | 64 | #include <openssl/objects.h> |
65 | #include <openssl/bn.h> | 65 | #include <openssl/bn.h> |
66 | 66 | ||
67 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | 67 | int |
68 | i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | ||
68 | { | 69 | { |
69 | unsigned char *p; | 70 | unsigned char *p; |
70 | int objsize; | 71 | int objsize; |
71 | 72 | ||
72 | if ((a == NULL) || (a->data == NULL)) return(0); | 73 | if ((a == NULL) || (a->data == NULL)) |
74 | return (0); | ||
73 | 75 | ||
74 | objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT); | 76 | objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT); |
75 | if (pp == NULL) return objsize; | 77 | if (pp == NULL) |
78 | return objsize; | ||
76 | 79 | ||
77 | p= *pp; | 80 | p = *pp; |
78 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | 81 | ASN1_put_object(&p, 0,a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL); |
79 | memcpy(p,a->data,a->length); | 82 | memcpy(p, a->data, a->length); |
80 | p+=a->length; | 83 | p += a->length; |
81 | 84 | ||
82 | *pp=p; | 85 | *pp = p; |
83 | return(objsize); | 86 | return (objsize); |
84 | } | 87 | } |
85 | 88 | ||
86 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | 89 | int |
90 | a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | ||
87 | { | 91 | { |
88 | int i,first,len=0,c, use_bn; | 92 | int i, first, len = 0, c, use_bn; |
89 | char ftmp[24], *tmp = ftmp; | 93 | char ftmp[24], *tmp = ftmp; |
90 | int tmpsize = sizeof ftmp; | 94 | int tmpsize = sizeof ftmp; |
91 | const char *p; | 95 | const char *p; |
@@ -93,42 +97,46 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
93 | BIGNUM *bl = NULL; | 97 | BIGNUM *bl = NULL; |
94 | 98 | ||
95 | if (num == 0) | 99 | if (num == 0) |
96 | return(0); | 100 | return (0); |
97 | else if (num == -1) | 101 | else if (num == -1) |
98 | num=strlen(buf); | 102 | num = strlen(buf); |
99 | 103 | ||
100 | p=buf; | 104 | p = buf; |
101 | c= *(p++); | 105 | c = *(p++); |
102 | num--; | 106 | num--; |
103 | if ((c >= '0') && (c <= '2')) { | 107 | if ((c >= '0') && (c <= '2')) { |
104 | first= c-'0'; | 108 | first= c-'0'; |
105 | } else { | 109 | } else { |
106 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); | 110 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE); |
107 | goto err; | 111 | goto err; |
108 | } | 112 | } |
109 | 113 | ||
110 | if (num <= 0) { | 114 | if (num <= 0) { |
111 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); | 115 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER); |
112 | goto err; | 116 | goto err; |
113 | } | 117 | } |
114 | c= *(p++); | 118 | c = *(p++); |
115 | num--; | 119 | num--; |
116 | for (;;) { | 120 | for (;;) { |
117 | if (num <= 0) break; | 121 | if (num <= 0) |
122 | break; | ||
118 | if ((c != '.') && (c != ' ')) { | 123 | if ((c != '.') && (c != ' ')) { |
119 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); | 124 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, |
125 | ASN1_R_INVALID_SEPARATOR); | ||
120 | goto err; | 126 | goto err; |
121 | } | 127 | } |
122 | l=0; | 128 | l = 0; |
123 | use_bn = 0; | 129 | use_bn = 0; |
124 | for (;;) { | 130 | for (;;) { |
125 | if (num <= 0) break; | 131 | if (num <= 0) |
132 | break; | ||
126 | num--; | 133 | num--; |
127 | c= *(p++); | 134 | c = *(p++); |
128 | if ((c == ' ') || (c == '.')) | 135 | if ((c == ' ') || (c == '.')) |
129 | break; | 136 | break; |
130 | if ((c < '0') || (c > '9')) { | 137 | if ((c < '0') || (c > '9')) { |
131 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); | 138 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, |
139 | ASN1_R_INVALID_DIGIT); | ||
132 | goto err; | 140 | goto err; |
133 | } | 141 | } |
134 | if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { | 142 | if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { |
@@ -139,30 +147,29 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
139 | goto err; | 147 | goto err; |
140 | } | 148 | } |
141 | if (use_bn) { | 149 | if (use_bn) { |
142 | if (!BN_mul_word(bl, 10L) | 150 | if (!BN_mul_word(bl, 10L) || |
143 | || !BN_add_word(bl, c-'0')) | 151 | !BN_add_word(bl, c-'0')) |
144 | goto err; | 152 | goto err; |
145 | } | 153 | } else |
146 | else | 154 | l = l * 10L + (long)(c - '0'); |
147 | l=l*10L+(long)(c-'0'); | ||
148 | } | 155 | } |
149 | if (len == 0) { | 156 | if (len == 0) { |
150 | if ((first < 2) && (l >= 40)) { | 157 | if ((first < 2) && (l >= 40)) { |
151 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); | 158 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, |
159 | ASN1_R_SECOND_NUMBER_TOO_LARGE); | ||
152 | goto err; | 160 | goto err; |
153 | } | 161 | } |
154 | if (use_bn) { | 162 | if (use_bn) { |
155 | if (!BN_add_word(bl, first * 40)) | 163 | if (!BN_add_word(bl, first * 40)) |
156 | goto err; | 164 | goto err; |
157 | } | 165 | } else |
158 | else | 166 | l += (long)first * 40; |
159 | l+=(long)first*40; | ||
160 | } | 167 | } |
161 | i=0; | 168 | i = 0; |
162 | if (use_bn) { | 169 | if (use_bn) { |
163 | int blsize; | 170 | int blsize; |
164 | blsize = BN_num_bits(bl); | 171 | blsize = BN_num_bits(bl); |
165 | blsize = (blsize + 6)/7; | 172 | blsize = (blsize + 6) / 7; |
166 | if (blsize > tmpsize) { | 173 | if (blsize > tmpsize) { |
167 | if (tmp != ftmp) | 174 | if (tmp != ftmp) |
168 | free(tmp); | 175 | free(tmp); |
@@ -171,108 +178,118 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
171 | if (!tmp) | 178 | if (!tmp) |
172 | goto err; | 179 | goto err; |
173 | } | 180 | } |
174 | while(blsize--) | 181 | while (blsize--) |
175 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); | 182 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); |
176 | } else { | 183 | } else { |
177 | 184 | ||
178 | for (;;) { | 185 | for (;;) { |
179 | tmp[i++]=(unsigned char)l&0x7f; | 186 | tmp[i++] = (unsigned char)l & 0x7f; |
180 | l>>=7L; | 187 | l >>= 7L; |
181 | if (l == 0L) break; | 188 | if (l == 0L) |
189 | break; | ||
182 | } | 190 | } |
183 | 191 | ||
184 | } | 192 | } |
185 | if (out != NULL) { | 193 | if (out != NULL) { |
186 | if (len+i > olen) { | 194 | if (len + i > olen) { |
187 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); | 195 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, |
196 | ASN1_R_BUFFER_TOO_SMALL); | ||
188 | goto err; | 197 | goto err; |
189 | } | 198 | } |
190 | while (--i > 0) | 199 | while (--i > 0) |
191 | out[len++]=tmp[i]|0x80; | 200 | out[len++] = tmp[i]|0x80; |
192 | out[len++]=tmp[0]; | 201 | out[len++] = tmp[0]; |
193 | } | 202 | } else |
194 | else | 203 | len += i; |
195 | len+=i; | ||
196 | } | 204 | } |
197 | if (tmp != ftmp) | 205 | if (tmp != ftmp) |
198 | free(tmp); | 206 | free(tmp); |
199 | if (bl) | 207 | if (bl) |
200 | BN_free(bl); | 208 | BN_free(bl); |
201 | return(len); | 209 | return (len); |
210 | |||
202 | err: | 211 | err: |
203 | if (tmp != ftmp) | 212 | if (tmp != ftmp) |
204 | free(tmp); | 213 | free(tmp); |
205 | if (bl) | 214 | if (bl) |
206 | BN_free(bl); | 215 | BN_free(bl); |
207 | return(0); | 216 | return (0); |
208 | } | 217 | } |
209 | 218 | ||
210 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | 219 | int |
220 | i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | ||
211 | { | 221 | { |
212 | return OBJ_obj2txt(buf, buf_len, a, 0); | 222 | return OBJ_obj2txt(buf, buf_len, a, 0); |
213 | } | 223 | } |
214 | 224 | ||
215 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | 225 | int |
226 | i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | ||
216 | { | 227 | { |
217 | char buf[80], *p = buf; | 228 | char buf[80], *p = buf; |
218 | int i; | 229 | int i; |
219 | 230 | ||
220 | if ((a == NULL) || (a->data == NULL)) | 231 | if ((a == NULL) || (a->data == NULL)) |
221 | return(BIO_write(bp,"NULL",4)); | 232 | return(BIO_write(bp, "NULL",4)); |
222 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); | 233 | i = i2t_ASN1_OBJECT(buf, sizeof buf, a); |
223 | if (i > (int)(sizeof(buf) - 1)) { | 234 | if (i > (int)(sizeof(buf) - 1)) { |
224 | p = malloc(i + 1); | 235 | p = malloc(i + 1); |
225 | if (!p) | 236 | if (!p) |
226 | return -1; | 237 | return -1; |
227 | i2t_ASN1_OBJECT(p,i + 1,a); | 238 | i2t_ASN1_OBJECT(p, i + 1, a); |
228 | } | 239 | } |
229 | if (i <= 0) | 240 | if (i <= 0) |
230 | return BIO_write(bp, "<INVALID>", 9); | 241 | return BIO_write(bp, "<INVALID>", 9); |
231 | BIO_write(bp,p,i); | 242 | BIO_write(bp, p, i); |
232 | if (p != buf) | 243 | if (p != buf) |
233 | free(p); | 244 | free(p); |
234 | return(i); | 245 | return (i); |
235 | } | 246 | } |
236 | 247 | ||
237 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | 248 | ASN1_OBJECT * |
238 | long length) | 249 | d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length) |
239 | { | 250 | { |
240 | const unsigned char *p; | 251 | const unsigned char *p; |
241 | long len; | 252 | long len; |
242 | int tag,xclass; | 253 | int tag, xclass; |
243 | int inf,i; | 254 | int inf, i; |
244 | ASN1_OBJECT *ret = NULL; | 255 | ASN1_OBJECT *ret = NULL; |
245 | p= *pp; | 256 | |
246 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 257 | p = *pp; |
258 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); | ||
247 | if (inf & 0x80) { | 259 | if (inf & 0x80) { |
248 | i=ASN1_R_BAD_OBJECT_HEADER; | 260 | i = ASN1_R_BAD_OBJECT_HEADER; |
249 | goto err; | 261 | goto err; |
250 | } | 262 | } |
251 | 263 | ||
252 | if (tag != V_ASN1_OBJECT) { | 264 | if (tag != V_ASN1_OBJECT) { |
253 | i=ASN1_R_EXPECTING_AN_OBJECT; | 265 | i = ASN1_R_EXPECTING_AN_OBJECT; |
254 | goto err; | 266 | goto err; |
255 | } | 267 | } |
256 | ret = c2i_ASN1_OBJECT(a, &p, len); | 268 | ret = c2i_ASN1_OBJECT(a, &p, len); |
257 | if(ret) *pp = p; | 269 | if (ret) |
270 | *pp = p; | ||
258 | return ret; | 271 | return ret; |
272 | |||
259 | err: | 273 | err: |
260 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | 274 | ASN1err(ASN1_F_D2I_ASN1_OBJECT, i); |
261 | return(NULL); | 275 | return (NULL); |
262 | } | 276 | } |
263 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | 277 | |
264 | long len) | 278 | ASN1_OBJECT * |
279 | c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) | ||
265 | { | 280 | { |
266 | ASN1_OBJECT *ret=NULL; | 281 | ASN1_OBJECT *ret = NULL; |
267 | const unsigned char *p; | 282 | const unsigned char *p; |
268 | unsigned char *data; | 283 | unsigned char *data; |
269 | int i; | 284 | int i; |
285 | |||
270 | /* Sanity check OID encoding: can't have leading 0x80 in | 286 | /* Sanity check OID encoding: can't have leading 0x80 in |
271 | * subidentifiers, see: X.690 8.19.2 | 287 | * subidentifiers, see: X.690 8.19.2 |
272 | */ | 288 | */ |
273 | for (i = 0, p = *pp; i < len; i++, p++) { | 289 | for (i = 0, p = *pp; i < len; i++, p++) { |
274 | if (*p == 0x80 && (!i || !(p[-1] & 0x80))) { | 290 | if (*p == 0x80 && (!i || !(p[-1] & 0x80))) { |
275 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); | 291 | ASN1err(ASN1_F_C2I_ASN1_OBJECT, |
292 | ASN1_R_INVALID_OBJECT_ENCODING); | ||
276 | return NULL; | 293 | return NULL; |
277 | } | 294 | } |
278 | } | 295 | } |
@@ -280,92 +297,106 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | |||
280 | /* only the ASN1_OBJECTs from the 'table' will have values | 297 | /* only the ASN1_OBJECTs from the 'table' will have values |
281 | * for ->sn or ->ln */ | 298 | * for ->sn or ->ln */ |
282 | if ((a == NULL) || ((*a) == NULL) || | 299 | if ((a == NULL) || ((*a) == NULL) || |
283 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) { | 300 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) { |
284 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | 301 | if ((ret = ASN1_OBJECT_new()) == NULL) |
285 | } | 302 | return (NULL); |
286 | else ret=(*a); | 303 | } else |
304 | ret = (*a); | ||
287 | 305 | ||
288 | p= *pp; | 306 | p = *pp; |
289 | /* detach data from object */ | 307 | /* detach data from object */ |
290 | data = (unsigned char *)ret->data; | 308 | data = (unsigned char *)ret->data; |
291 | ret->data = NULL; | 309 | ret->data = NULL; |
292 | /* once detached we can change it */ | 310 | /* once detached we can change it */ |
293 | if ((data == NULL) || (ret->length < len)) { | 311 | if ((data == NULL) || (ret->length < len)) { |
294 | ret->length=0; | 312 | ret->length = 0; |
295 | if (data != NULL) free(data); | 313 | if (data != NULL) |
296 | data=(unsigned char *)malloc(len ? (int)len : 1); | 314 | free(data); |
297 | if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; } | 315 | data = (unsigned char *)malloc(len ? (int)len : 1); |
298 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 316 | if (data == NULL) { |
317 | i = ERR_R_MALLOC_FAILURE; | ||
318 | goto err; | ||
319 | } | ||
320 | ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
299 | } | 321 | } |
300 | memcpy(data,p,(int)len); | 322 | memcpy(data, p, (int)len); |
301 | /* reattach data to object, after which it remains const */ | 323 | /* reattach data to object, after which it remains const */ |
302 | ret->data =data; | 324 | ret->data = data; |
303 | ret->length=(int)len; | 325 | ret->length = (int)len; |
304 | ret->sn=NULL; | 326 | ret->sn = NULL; |
305 | ret->ln=NULL; | 327 | ret->ln = NULL; |
306 | /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ | 328 | /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ |
307 | p+=len; | 329 | p += len; |
330 | |||
331 | if (a != NULL) | ||
332 | (*a) = ret; | ||
333 | *pp = p; | ||
334 | return (ret); | ||
308 | 335 | ||
309 | if (a != NULL) (*a)=ret; | ||
310 | *pp=p; | ||
311 | return(ret); | ||
312 | err: | 336 | err: |
313 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,i); | 337 | ASN1err(ASN1_F_C2I_ASN1_OBJECT, i); |
314 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 338 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
315 | ASN1_OBJECT_free(ret); | 339 | ASN1_OBJECT_free(ret); |
316 | return(NULL); | 340 | return (NULL); |
317 | } | 341 | } |
318 | 342 | ||
319 | ASN1_OBJECT *ASN1_OBJECT_new(void) | 343 | ASN1_OBJECT * |
344 | ASN1_OBJECT_new(void) | ||
320 | { | 345 | { |
321 | ASN1_OBJECT *ret; | 346 | ASN1_OBJECT *ret; |
322 | 347 | ||
323 | ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); | 348 | ret = (ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); |
324 | if (ret == NULL) { | 349 | if (ret == NULL) { |
325 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | 350 | ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE); |
326 | return(NULL); | 351 | return (NULL); |
327 | } | 352 | } |
328 | ret->length=0; | 353 | ret->length = 0; |
329 | ret->data=NULL; | 354 | ret->data = NULL; |
330 | ret->nid=0; | 355 | ret->nid = 0; |
331 | ret->sn=NULL; | 356 | ret->sn = NULL; |
332 | ret->ln=NULL; | 357 | ret->ln = NULL; |
333 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; | 358 | ret->flags = ASN1_OBJECT_FLAG_DYNAMIC; |
334 | return(ret); | 359 | return (ret); |
335 | } | 360 | } |
336 | 361 | ||
337 | void ASN1_OBJECT_free(ASN1_OBJECT *a) | 362 | void |
363 | ASN1_OBJECT_free(ASN1_OBJECT *a) | ||
338 | { | 364 | { |
339 | if (a == NULL) return; | 365 | if (a == NULL) |
366 | return; | ||
340 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) { | 367 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) { |
341 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ | 368 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ |
342 | if (a->sn != NULL) free((void *)a->sn); | 369 | if (a->sn != NULL) |
343 | if (a->ln != NULL) free((void *)a->ln); | 370 | free((void *)a->sn); |
371 | if (a->ln != NULL) | ||
372 | free((void *)a->ln); | ||
344 | #endif | 373 | #endif |
345 | a->sn=a->ln=NULL; | 374 | a->sn = a->ln = NULL; |
346 | } | 375 | } |
347 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) { | 376 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) { |
348 | if (a->data != NULL) free((void *)a->data); | 377 | if (a->data != NULL) |
349 | a->data=NULL; | 378 | free((void *)a->data); |
350 | a->length=0; | 379 | a->data = NULL; |
380 | a->length = 0; | ||
351 | } | 381 | } |
352 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | 382 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) |
353 | free(a); | 383 | free(a); |
354 | } | 384 | } |
355 | 385 | ||
356 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | 386 | ASN1_OBJECT * |
357 | const char *sn, const char *ln) | 387 | ASN1_OBJECT_create(int nid, unsigned char *data, int len, |
388 | const char *sn, const char *ln) | ||
358 | { | 389 | { |
359 | ASN1_OBJECT o; | 390 | ASN1_OBJECT o; |
360 | 391 | ||
361 | o.sn=sn; | 392 | o.sn = sn; |
362 | o.ln=ln; | 393 | o.ln = ln; |
363 | o.data=data; | 394 | o.data = data; |
364 | o.nid=nid; | 395 | o.nid = nid; |
365 | o.length=len; | 396 | o.length = len; |
366 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| | 397 | o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | |
367 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 398 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
368 | return(OBJ_dup(&o)); | 399 | return (OBJ_dup(&o)); |
369 | } | 400 | } |
370 | 401 | ||
371 | IMPLEMENT_STACK_OF(ASN1_OBJECT) | 402 | IMPLEMENT_STACK_OF(ASN1_OBJECT) |