diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_d2i_fp.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_d2i_fp.c | 87 |
1 files changed, 69 insertions, 18 deletions
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c index d952836a91..a80fbe9ff7 100644 --- a/src/lib/libcrypto/asn1/a_d2i_fp.c +++ b/src/lib/libcrypto/asn1/a_d2i_fp.c | |||
@@ -58,17 +58,16 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "buffer.h" | 61 | #include <openssl/buffer.h> |
62 | #include "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 | 69 | char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in, |
67 | char *ASN1_d2i_fp(xnew,d2i,in,x) | 70 | unsigned char **x) |
68 | char *(*xnew)(); | ||
69 | char *(*d2i)(); | ||
70 | FILE *in; | ||
71 | unsigned char **x; | ||
72 | { | 71 | { |
73 | BIO *b; | 72 | BIO *b; |
74 | char *ret; | 73 | char *ret; |
@@ -85,16 +84,68 @@ unsigned char **x; | |||
85 | } | 84 | } |
86 | #endif | 85 | #endif |
87 | 86 | ||
88 | char *ASN1_d2i_bio(xnew,d2i,in,x) | 87 | char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in, |
89 | char *(*xnew)(); | 88 | unsigned char **x) |
90 | char *(*d2i)(); | 89 | { |
91 | BIO *in; | 90 | BUF_MEM *b = NULL; |
92 | unsigned char **x; | 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) | ||
93 | { | 144 | { |
94 | BUF_MEM *b; | 145 | BUF_MEM *b; |
95 | unsigned char *p; | 146 | unsigned char *p; |
96 | int i; | 147 | int i; |
97 | char *ret=NULL; | 148 | int ret=-1; |
98 | ASN1_CTX c; | 149 | ASN1_CTX c; |
99 | int want=HEADER_SIZE; | 150 | int want=HEADER_SIZE; |
100 | int eos=0; | 151 | int eos=0; |
@@ -105,7 +156,7 @@ unsigned char **x; | |||
105 | if (b == NULL) | 156 | if (b == NULL) |
106 | { | 157 | { |
107 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | 158 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); |
108 | return(NULL); | 159 | return -1; |
109 | } | 160 | } |
110 | 161 | ||
111 | ERR_clear_error(); | 162 | ERR_clear_error(); |
@@ -193,8 +244,8 @@ unsigned char **x; | |||
193 | } | 244 | } |
194 | } | 245 | } |
195 | 246 | ||
196 | p=(unsigned char *)b->data; | 247 | *pb = b; |
197 | ret=d2i(x,&p,off); | 248 | return off; |
198 | err: | 249 | err: |
199 | if (b != NULL) BUF_MEM_free(b); | 250 | if (b != NULL) BUF_MEM_free(b); |
200 | return(ret); | 251 | return(ret); |