diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_d2i_fp.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_d2i_fp.c | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c index a49d1cb289..a80fbe9ff7 100644 --- a/src/lib/libcrypto/asn1/a_d2i_fp.c +++ b/src/lib/libcrypto/asn1/a_d2i_fp.c | |||
@@ -61,9 +61,11 @@ | |||
61 | #include <openssl/buffer.h> | 61 | #include <openssl/buffer.h> |
62 | #include <openssl/asn1_mac.h> | 62 | #include <openssl/asn1_mac.h> |
63 | 63 | ||
64 | #define HEADER_SIZE 8 | 64 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); |
65 | |||
66 | #ifndef NO_OLD_ASN1 | ||
67 | #ifndef OPENSSL_NO_FP_API | ||
65 | 68 | ||
66 | #ifndef NO_FP_API | ||
67 | char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in, | 69 | char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in, |
68 | unsigned char **x) | 70 | unsigned char **x) |
69 | { | 71 | { |
@@ -85,10 +87,65 @@ char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in, | |||
85 | char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in, | 87 | char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in, |
86 | unsigned char **x) | 88 | unsigned char **x) |
87 | { | 89 | { |
90 | BUF_MEM *b = NULL; | ||
91 | unsigned char *p; | ||
92 | char *ret=NULL; | ||
93 | int len; | ||
94 | |||
95 | len = asn1_d2i_read_bio(in, &b); | ||
96 | if(len < 0) goto err; | ||
97 | |||
98 | p=(unsigned char *)b->data; | ||
99 | ret=d2i(x,&p,len); | ||
100 | err: | ||
101 | if (b != NULL) BUF_MEM_free(b); | ||
102 | return(ret); | ||
103 | } | ||
104 | |||
105 | #endif | ||
106 | |||
107 | void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) | ||
108 | { | ||
109 | BUF_MEM *b = NULL; | ||
110 | unsigned char *p; | ||
111 | void *ret=NULL; | ||
112 | int len; | ||
113 | |||
114 | len = asn1_d2i_read_bio(in, &b); | ||
115 | if(len < 0) goto err; | ||
116 | |||
117 | p=(unsigned char *)b->data; | ||
118 | ret=ASN1_item_d2i(x,&p,len, it); | ||
119 | err: | ||
120 | if (b != NULL) BUF_MEM_free(b); | ||
121 | return(ret); | ||
122 | } | ||
123 | |||
124 | #ifndef OPENSSL_NO_FP_API | ||
125 | void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) | ||
126 | { | ||
127 | BIO *b; | ||
128 | char *ret; | ||
129 | |||
130 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
131 | { | ||
132 | ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB); | ||
133 | return(NULL); | ||
134 | } | ||
135 | BIO_set_fp(b,in,BIO_NOCLOSE); | ||
136 | ret=ASN1_item_d2i_bio(it,b,x); | ||
137 | BIO_free(b); | ||
138 | return(ret); | ||
139 | } | ||
140 | #endif | ||
141 | |||
142 | #define HEADER_SIZE 8 | ||
143 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | ||
144 | { | ||
88 | BUF_MEM *b; | 145 | BUF_MEM *b; |
89 | unsigned char *p; | 146 | unsigned char *p; |
90 | int i; | 147 | int i; |
91 | char *ret=NULL; | 148 | int ret=-1; |
92 | ASN1_CTX c; | 149 | ASN1_CTX c; |
93 | int want=HEADER_SIZE; | 150 | int want=HEADER_SIZE; |
94 | int eos=0; | 151 | int eos=0; |
@@ -99,7 +156,7 @@ char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in, | |||
99 | if (b == NULL) | 156 | if (b == NULL) |
100 | { | 157 | { |
101 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | 158 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); |
102 | return(NULL); | 159 | return -1; |
103 | } | 160 | } |
104 | 161 | ||
105 | ERR_clear_error(); | 162 | ERR_clear_error(); |
@@ -187,8 +244,8 @@ char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in, | |||
187 | } | 244 | } |
188 | } | 245 | } |
189 | 246 | ||
190 | p=(unsigned char *)b->data; | 247 | *pb = b; |
191 | ret=d2i(x,&p,off); | 248 | return off; |
192 | err: | 249 | err: |
193 | if (b != NULL) BUF_MEM_free(b); | 250 | if (b != NULL) BUF_MEM_free(b); |
194 | return(ret); | 251 | return(ret); |