summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_enum.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/a_enum.c')
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
index 9239ecc439..ccf62e5a04 100644
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ b/src/lib/libcrypto/asn1/a_enum.c
@@ -65,6 +65,12 @@
65 * for comments on encoding see a_int.c 65 * for comments on encoding see a_int.c
66 */ 66 */
67 67
68ASN1_ENUMERATED *ASN1_ENUMERATED_new(void)
69{ return M_ASN1_ENUMERATED_new(); }
70
71void ASN1_ENUMERATED_free(ASN1_ENUMERATED *x)
72{ M_ASN1_ENUMERATED_free(x); }
73
68int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp) 74int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
69 { 75 {
70 int pad=0,ret,r,i,t; 76 int pad=0,ret,r,i,t;
@@ -142,7 +148,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
142 148
143 if ((a == NULL) || ((*a) == NULL)) 149 if ((a == NULL) || ((*a) == NULL))
144 { 150 {
145 if ((ret=ASN1_ENUMERATED_new()) == NULL) return(NULL); 151 if ((ret=M_ASN1_ENUMERATED_new()) == NULL) return(NULL);
146 ret->type=V_ASN1_ENUMERATED; 152 ret->type=V_ASN1_ENUMERATED;
147 } 153 }
148 else 154 else
@@ -171,7 +177,12 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
171 goto err; 177 goto err;
172 } 178 }
173 to=s; 179 to=s;
174 if (*p & 0x80) /* a negative number */ 180 if(!len) {
181 /* Strictly speaking this is an illegal ENUMERATED but we
182 * tolerate it.
183 */
184 ret->type=V_ASN1_ENUMERATED;
185 } else if (*p & 0x80) /* a negative number */
175 { 186 {
176 ret->type=V_ASN1_NEG_ENUMERATED; 187 ret->type=V_ASN1_NEG_ENUMERATED;
177 if ((*p == 0xff) && (len != 1)) { 188 if ((*p == 0xff) && (len != 1)) {
@@ -208,7 +219,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
208 p+=len; 219 p+=len;
209 } 220 }
210 221
211 if (ret->data != NULL) Free((char *)ret->data); 222 if (ret->data != NULL) Free(ret->data);
212 ret->data=s; 223 ret->data=s;
213 ret->length=(int)len; 224 ret->length=(int)len;
214 if (a != NULL) (*a)=ret; 225 if (a != NULL) (*a)=ret;
@@ -217,7 +228,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
217err: 228err:
218 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i); 229 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
219 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 230 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
220 ASN1_ENUMERATED_free(ret); 231 M_ASN1_ENUMERATED_free(ret);
221 return(NULL); 232 return(NULL);
222 } 233 }
223 234
@@ -231,7 +242,7 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
231 if (a->length < (sizeof(long)+1)) 242 if (a->length < (sizeof(long)+1))
232 { 243 {
233 if (a->data != NULL) 244 if (a->data != NULL)
234 Free((char *)a->data); 245 Free(a->data);
235 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL) 246 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
236 memset((char *)a->data,0,sizeof(long)+1); 247 memset((char *)a->data,0,sizeof(long)+1);
237 } 248 }
@@ -295,7 +306,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
295 int len,j; 306 int len,j;
296 307
297 if (ai == NULL) 308 if (ai == NULL)
298 ret=ASN1_ENUMERATED_new(); 309 ret=M_ASN1_ENUMERATED_new();
299 else 310 else
300 ret=ai; 311 ret=ai;
301 if (ret == NULL) 312 if (ret == NULL)
@@ -311,7 +322,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
311 ret->length=BN_bn2bin(bn,ret->data); 322 ret->length=BN_bn2bin(bn,ret->data);
312 return(ret); 323 return(ret);
313err: 324err:
314 if (ret != ai) ASN1_ENUMERATED_free(ret); 325 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
315 return(NULL); 326 return(NULL);
316 } 327 }
317 328