diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_i2d_fp.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_i2d_fp.c | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c index 66c3df68d5..f4f1b73ebe 100644 --- a/src/lib/libcrypto/asn1/a_i2d_fp.c +++ b/src/lib/libcrypto/asn1/a_i2d_fp.c | |||
@@ -58,14 +58,13 @@ | |||
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.h> |
63 | 63 | ||
64 | #ifndef NO_FP_API | 64 | #ifndef NO_OLD_ASN1 |
65 | int ASN1_i2d_fp(i2d,out,x) | 65 | |
66 | int (*i2d)(); | 66 | #ifndef OPENSSL_NO_FP_API |
67 | FILE *out; | 67 | int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x) |
68 | unsigned char *x; | ||
69 | { | 68 | { |
70 | BIO *b; | 69 | BIO *b; |
71 | int ret; | 70 | int ret; |
@@ -82,17 +81,14 @@ unsigned char *x; | |||
82 | } | 81 | } |
83 | #endif | 82 | #endif |
84 | 83 | ||
85 | int ASN1_i2d_bio(i2d,out,x) | 84 | int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x) |
86 | int (*i2d)(); | ||
87 | BIO *out; | ||
88 | unsigned char *x; | ||
89 | { | 85 | { |
90 | char *b; | 86 | char *b; |
91 | unsigned char *p; | 87 | unsigned char *p; |
92 | int i,j=0,n,ret=1; | 88 | int i,j=0,n,ret=1; |
93 | 89 | ||
94 | n=i2d(x,NULL); | 90 | n=i2d(x,NULL); |
95 | b=(char *)Malloc(n); | 91 | b=(char *)OPENSSL_malloc(n); |
96 | if (b == NULL) | 92 | if (b == NULL) |
97 | { | 93 | { |
98 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | 94 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); |
@@ -114,6 +110,54 @@ unsigned char *x; | |||
114 | j+=i; | 110 | j+=i; |
115 | n-=i; | 111 | n-=i; |
116 | } | 112 | } |
117 | Free((char *)b); | 113 | OPENSSL_free(b); |
114 | return(ret); | ||
115 | } | ||
116 | |||
117 | #endif | ||
118 | |||
119 | #ifndef OPENSSL_NO_FP_API | ||
120 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) | ||
121 | { | ||
122 | BIO *b; | ||
123 | int ret; | ||
124 | |||
125 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
126 | { | ||
127 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); | ||
128 | return(0); | ||
129 | } | ||
130 | BIO_set_fp(b,out,BIO_NOCLOSE); | ||
131 | ret=ASN1_item_i2d_bio(it,b,x); | ||
132 | BIO_free(b); | ||
133 | return(ret); | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) | ||
138 | { | ||
139 | unsigned char *b = NULL; | ||
140 | int i,j=0,n,ret=1; | ||
141 | |||
142 | n = ASN1_item_i2d(x, &b, it); | ||
143 | if (b == NULL) | ||
144 | { | ||
145 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | ||
146 | return(0); | ||
147 | } | ||
148 | |||
149 | for (;;) | ||
150 | { | ||
151 | i=BIO_write(out,&(b[j]),n); | ||
152 | if (i == n) break; | ||
153 | if (i <= 0) | ||
154 | { | ||
155 | ret=0; | ||
156 | break; | ||
157 | } | ||
158 | j+=i; | ||
159 | n-=i; | ||
160 | } | ||
161 | OPENSSL_free(b); | ||
118 | return(ret); | 162 | return(ret); |
119 | } | 163 | } |