64
64
#include "cryptlib.h"
65
#include <openssl/bio.h>
68
68
#define DUMP_WIDTH 16
69
69
#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
71
int BIO_dump(BIO *bio, const char *s, int len)
71
int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
72
void *u, const char *s, int len)
73
return BIO_dump_indent(bio, s, len, 0);
74
return BIO_dump_indent_cb(cb, u, s, len, 0);
76
int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
77
int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
78
void *u, const char *s, int len, int indent)
79
81
char buf[288+1],tmp[20],str[128+1];
87
for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
89
for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
129
131
ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
130
132
#ifndef CHARSET_EBCDIC
131
133
BIO_snprintf(tmp,sizeof tmp,"%c",
132
((ch>=' ')&&(ch<='~'))?ch:'.');
134
((ch>=' ')&&(ch<='~'))?ch:'.');
134
136
BIO_snprintf(tmp,sizeof tmp,"%c",
135
((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
137
((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
139
141
BUF_strlcat(buf,tmp,sizeof buf);
141
143
BUF_strlcat(buf,"\n",sizeof buf);
142
/* if this is the last call then update the ddt_dump thing so that
143
* we will move the selection point in the debug window
144
/* if this is the last call then update the ddt_dump thing so
145
* that we will move the selection point in the debug window
145
ret+=BIO_write(bio,(char *)buf,strlen(buf));
147
ret+=cb((void *)buf,strlen(buf),u);
150
152
BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
152
ret+=BIO_write(bio,(char *)buf,strlen(buf));
154
ret+=cb((void *)buf,strlen(buf),u);
160
#ifndef OPENSSL_NO_FP_API
161
static int write_fp(const void *data, size_t len, void *fp)
163
return UP_fwrite(data, len, 1, fp);
165
int BIO_dump_fp(FILE *fp, const char *s, int len)
167
return BIO_dump_cb(write_fp, fp, s, len);
169
int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
171
return BIO_dump_indent_cb(write_fp, fp, s, len, indent);
175
static int write_bio(const void *data, size_t len, void *bp)
177
return BIO_write((BIO *)bp, (const char *)data, len);
179
int BIO_dump(BIO *bp, const char *s, int len)
181
return BIO_dump_cb(write_bio, bp, s, len);
183
int BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
185
return BIO_dump_indent_cb(write_bio, bp, s, len, indent);