summaryrefslogtreecommitdiffstats
path: root/crypto/asn1/a_d2i_fp.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2000-12-30 02:40:26 +0000
committerDr. Stephen Henson <steve@openssl.org>2000-12-30 02:40:26 +0000
commit4e1209ebf8603d7f51a37d1645dfc0c09bac8686 (patch)
treee4487e9a433aba1030433f98b95e46588bf22a9f /crypto/asn1/a_d2i_fp.c
parent78d3b819f04fcefa67294a840ea7fbf167418109 (diff)
ASN1_ITEM versions of ASN1_d2i_{fp, bio} and replacement of
most of the old wrappers. A few of the old versions remain because they are non standard and the corresponding ASN1 code has not been reimplemented yet.
Diffstat (limited to 'crypto/asn1/a_d2i_fp.c')
-rw-r--r--crypto/asn1/a_d2i_fp.c67
1 files changed, 62 insertions, 5 deletions
diff --git a/crypto/asn1/a_d2i_fp.c b/crypto/asn1/a_d2i_fp.c
index a49d1cb289..a5904be498 100644
--- a/crypto/asn1/a_d2i_fp.c
+++ b/crypto/asn1/a_d2i_fp.c
@@ -61,9 +61,11 @@
#include <openssl/buffer.h>
#include <openssl/asn1_mac.h>
-#define HEADER_SIZE 8
+static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
+#ifndef NO_OLD_ASN1
#ifndef NO_FP_API
+
char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
unsigned char **x)
{
@@ -85,10 +87,65 @@ char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
unsigned char **x)
{
+ BUF_MEM *b = NULL;
+ unsigned char *p;
+ char *ret=NULL;
+ int len;
+
+ len = asn1_d2i_read_bio(in, &b);
+ if(len < 0) goto err;
+
+ p=(unsigned char *)b->data;
+ ret=d2i(x,&p,len);
+err:
+ if (b != NULL) BUF_MEM_free(b);
+ return(ret);
+ }
+
+#endif
+
+void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
+ {
+ BUF_MEM *b = NULL;
+ unsigned char *p;
+ void *ret=NULL;
+ int len;
+
+ len = asn1_d2i_read_bio(in, &b);
+ if(len < 0) goto err;
+
+ p=(unsigned char *)b->data;
+ ret=ASN1_item_d2i(x,&p,len, it);
+err:
+ if (b != NULL) BUF_MEM_free(b);
+ return(ret);
+ }
+
+#ifndef NO_FP_API
+void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
+ {
+ BIO *b;
+ char *ret;
+
+ if ((b=BIO_new(BIO_s_file())) == NULL)
+ {
+ ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
+ return(NULL);
+ }
+ BIO_set_fp(b,in,BIO_NOCLOSE);
+ ret=ASN1_item_d2i_bio(it,b,x);
+ BIO_free(b);
+ return(ret);
+ }
+#endif
+
+#define HEADER_SIZE 8
+static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
+ {
BUF_MEM *b;
unsigned char *p;
int i;
- char *ret=NULL;
+ int ret=-1;
ASN1_CTX c;
int want=HEADER_SIZE;
int eos=0;
@@ -99,7 +156,7 @@ char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
if (b == NULL)
{
ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
- return(NULL);
+ return -1;
}
ERR_clear_error();
@@ -187,8 +244,8 @@ char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
}
}
- p=(unsigned char *)b->data;
- ret=d2i(x,&p,off);
+ *pb = b;
+ return off;
err:
if (b != NULL) BUF_MEM_free(b);
return(ret);