diff options
author | markus <> | 2002-09-05 12:51:50 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 12:51:50 +0000 |
commit | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch) | |
tree | bf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/asn1/a_bytes.c | |
parent | 027351f729b9e837200dae6e1520cda6577ab930 (diff) | |
download | openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2 openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/asn1/a_bytes.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_bytes.c | 78 |
1 files changed, 22 insertions, 56 deletions
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c index 14168d61ad..bb88660f58 100644 --- a/src/lib/libcrypto/asn1/a_bytes.c +++ b/src/lib/libcrypto/asn1/a_bytes.c | |||
@@ -58,38 +58,13 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "asn1_mac.h" | 61 | #include <openssl/asn1.h> |
62 | 62 | ||
63 | /* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); | 63 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c); |
64 | * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_ERROR_STACK); | 64 | /* type is a 'bitmap' of acceptable string types. |
65 | * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE); | ||
66 | * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG); | ||
67 | */ | 65 | */ |
68 | 66 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp, | |
69 | static unsigned long tag2bit[32]={ | 67 | long length, int type) |
70 | 0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ | ||
71 | B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ | ||
72 | B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ | ||
73 | B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */ | ||
74 | 0, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, | ||
75 | B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0, | ||
76 | 0,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, | ||
77 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, | ||
78 | }; | ||
79 | |||
80 | #ifndef NOPROTO | ||
81 | static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c); | ||
82 | #else | ||
83 | static int asn1_collate_primative(); | ||
84 | #endif | ||
85 | |||
86 | /* type is a 'bitmap' of acceptable string types to be accepted. | ||
87 | */ | ||
88 | ASN1_STRING *d2i_ASN1_type_bytes(a, pp, length, type) | ||
89 | ASN1_STRING **a; | ||
90 | unsigned char **pp; | ||
91 | long length; | ||
92 | int type; | ||
93 | { | 68 | { |
94 | ASN1_STRING *ret=NULL; | 69 | ASN1_STRING *ret=NULL; |
95 | unsigned char *p,*s; | 70 | unsigned char *p,*s; |
@@ -106,7 +81,7 @@ int type; | |||
106 | i=ASN1_R_TAG_VALUE_TOO_HIGH;; | 81 | i=ASN1_R_TAG_VALUE_TOO_HIGH;; |
107 | goto err; | 82 | goto err; |
108 | } | 83 | } |
109 | if (!(tag2bit[tag] & type)) | 84 | if (!(ASN1_tag2bit(tag) & type)) |
110 | { | 85 | { |
111 | i=ASN1_R_WRONG_TYPE; | 86 | i=ASN1_R_WRONG_TYPE; |
112 | goto err; | 87 | goto err; |
@@ -125,7 +100,7 @@ int type; | |||
125 | 100 | ||
126 | if (len != 0) | 101 | if (len != 0) |
127 | { | 102 | { |
128 | s=(unsigned char *)Malloc((int)len+1); | 103 | s=(unsigned char *)OPENSSL_malloc((int)len+1); |
129 | if (s == NULL) | 104 | if (s == NULL) |
130 | { | 105 | { |
131 | i=ERR_R_MALLOC_FAILURE; | 106 | i=ERR_R_MALLOC_FAILURE; |
@@ -138,7 +113,7 @@ int type; | |||
138 | else | 113 | else |
139 | s=NULL; | 114 | s=NULL; |
140 | 115 | ||
141 | if (ret->data != NULL) Free((char *)ret->data); | 116 | if (ret->data != NULL) OPENSSL_free(ret->data); |
142 | ret->length=(int)len; | 117 | ret->length=(int)len; |
143 | ret->data=s; | 118 | ret->data=s; |
144 | ret->type=tag; | 119 | ret->type=tag; |
@@ -152,11 +127,7 @@ err: | |||
152 | return(NULL); | 127 | return(NULL); |
153 | } | 128 | } |
154 | 129 | ||
155 | int i2d_ASN1_bytes(a, pp, tag, xclass) | 130 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) |
156 | ASN1_STRING *a; | ||
157 | unsigned char **pp; | ||
158 | int tag; | ||
159 | int xclass; | ||
160 | { | 131 | { |
161 | int ret,r,constructed; | 132 | int ret,r,constructed; |
162 | unsigned char *p; | 133 | unsigned char *p; |
@@ -182,12 +153,8 @@ int xclass; | |||
182 | return(r); | 153 | return(r); |
183 | } | 154 | } |
184 | 155 | ||
185 | ASN1_STRING *d2i_ASN1_bytes(a, pp, length, Ptag, Pclass) | 156 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length, |
186 | ASN1_STRING **a; | 157 | int Ptag, int Pclass) |
187 | unsigned char **pp; | ||
188 | long length; | ||
189 | int Ptag; | ||
190 | int Pclass; | ||
191 | { | 158 | { |
192 | ASN1_STRING *ret=NULL; | 159 | ASN1_STRING *ret=NULL; |
193 | unsigned char *p,*s; | 160 | unsigned char *p,*s; |
@@ -227,7 +194,7 @@ int Pclass; | |||
227 | c.tag=Ptag; | 194 | c.tag=Ptag; |
228 | c.xclass=Pclass; | 195 | c.xclass=Pclass; |
229 | c.max=(length == 0)?0:(p+length); | 196 | c.max=(length == 0)?0:(p+length); |
230 | if (!asn1_collate_primative(ret,&c)) | 197 | if (!asn1_collate_primitive(ret,&c)) |
231 | goto err; | 198 | goto err; |
232 | else | 199 | else |
233 | { | 200 | { |
@@ -240,8 +207,8 @@ int Pclass; | |||
240 | { | 207 | { |
241 | if ((ret->length < len) || (ret->data == NULL)) | 208 | if ((ret->length < len) || (ret->data == NULL)) |
242 | { | 209 | { |
243 | if (ret->data != NULL) Free((char *)ret->data); | 210 | if (ret->data != NULL) OPENSSL_free(ret->data); |
244 | s=(unsigned char *)Malloc((int)len); | 211 | s=(unsigned char *)OPENSSL_malloc((int)len + 1); |
245 | if (s == NULL) | 212 | if (s == NULL) |
246 | { | 213 | { |
247 | i=ERR_R_MALLOC_FAILURE; | 214 | i=ERR_R_MALLOC_FAILURE; |
@@ -251,12 +218,13 @@ int Pclass; | |||
251 | else | 218 | else |
252 | s=ret->data; | 219 | s=ret->data; |
253 | memcpy(s,p,(int)len); | 220 | memcpy(s,p,(int)len); |
221 | s[len] = '\0'; | ||
254 | p+=len; | 222 | p+=len; |
255 | } | 223 | } |
256 | else | 224 | else |
257 | { | 225 | { |
258 | s=NULL; | 226 | s=NULL; |
259 | if (ret->data != NULL) Free((char *)ret->data); | 227 | if (ret->data != NULL) OPENSSL_free(ret->data); |
260 | } | 228 | } |
261 | 229 | ||
262 | ret->length=(int)len; | 230 | ret->length=(int)len; |
@@ -275,13 +243,11 @@ err: | |||
275 | } | 243 | } |
276 | 244 | ||
277 | 245 | ||
278 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapes | 246 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse |
279 | * them into the one struture that is then returned */ | 247 | * them into the one structure that is then returned */ |
280 | /* There have been a few bug fixes for this function from | 248 | /* There have been a few bug fixes for this function from |
281 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ | 249 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ |
282 | static int asn1_collate_primative(a,c) | 250 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c) |
283 | ASN1_STRING *a; | ||
284 | ASN1_CTX *c; | ||
285 | { | 251 | { |
286 | ASN1_STRING *os=NULL; | 252 | ASN1_STRING *os=NULL; |
287 | BUF_MEM b; | 253 | BUF_MEM b; |
@@ -333,14 +299,14 @@ ASN1_CTX *c; | |||
333 | if (!asn1_Finish(c)) goto err; | 299 | if (!asn1_Finish(c)) goto err; |
334 | 300 | ||
335 | a->length=num; | 301 | a->length=num; |
336 | if (a->data != NULL) Free(a->data); | 302 | if (a->data != NULL) OPENSSL_free(a->data); |
337 | a->data=(unsigned char *)b.data; | 303 | a->data=(unsigned char *)b.data; |
338 | if (os != NULL) ASN1_STRING_free(os); | 304 | if (os != NULL) ASN1_STRING_free(os); |
339 | return(1); | 305 | return(1); |
340 | err: | 306 | err: |
341 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,c->error); | 307 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); |
342 | if (os != NULL) ASN1_STRING_free(os); | 308 | if (os != NULL) ASN1_STRING_free(os); |
343 | if (b.data != NULL) Free(b.data); | 309 | if (b.data != NULL) OPENSSL_free(b.data); |
344 | return(0); | 310 | return(0); |
345 | } | 311 | } |
346 | 312 | ||