summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/b_dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/b_dump.c')
-rw-r--r--src/lib/libcrypto/bio/b_dump.c75
1 files changed, 53 insertions, 22 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
index f671e722fa..c80ecc4295 100644
--- a/src/lib/libcrypto/bio/b_dump.c
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -62,30 +62,32 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include <openssl/bio.h> 65#include "bio_lcl.h"
66 66
67#define TRUNCATE 67#define TRUNCATE
68#define DUMP_WIDTH 16 68#define DUMP_WIDTH 16
69#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4)) 69#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
70 70
71int BIO_dump(BIO *bio, const char *s, int len) 71int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
72 void *u, const char *s, int len)
72 { 73 {
73 return BIO_dump_indent(bio, s, len, 0); 74 return BIO_dump_indent_cb(cb, u, s, len, 0);
74 } 75 }
75 76
76int BIO_dump_indent(BIO *bio, const char *s, int len, int indent) 77int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
78 void *u, const char *s, int len, int indent)
77 { 79 {
78 int ret=0; 80 int ret=0;
79 char buf[288+1],tmp[20],str[128+1]; 81 char buf[288+1],tmp[20],str[128+1];
80 int i,j,rows,trunc; 82 int i,j,rows,trc;
81 unsigned char ch; 83 unsigned char ch;
82 int dump_width; 84 int dump_width;
83 85
84 trunc=0; 86 trc=0;
85 87
86#ifdef TRUNCATE 88#ifdef TRUNCATE
87 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) 89 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
88 trunc++; 90 trc++;
89#endif 91#endif
90 92
91 if (indent < 0) 93 if (indent < 0)
@@ -96,7 +98,7 @@ int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
96 memset(str,' ',indent); 98 memset(str,' ',indent);
97 } 99 }
98 str[indent]='\0'; 100 str[indent]='\0';
99 101
100 dump_width=DUMP_WIDTH_LESS_INDENT(indent); 102 dump_width=DUMP_WIDTH_LESS_INDENT(indent);
101 rows=(len/dump_width); 103 rows=(len/dump_width);
102 if ((rows*dump_width)<len) 104 if ((rows*dump_width)<len)
@@ -117,7 +119,7 @@ int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
117 { 119 {
118 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; 120 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
119 BIO_snprintf(tmp,sizeof tmp,"%02x%c",ch, 121 BIO_snprintf(tmp,sizeof tmp,"%02x%c",ch,
120 j==7?'-':' '); 122 j==7?'-':' ');
121 BUF_strlcat(buf,tmp,sizeof buf); 123 BUF_strlcat(buf,tmp,sizeof buf);
122 } 124 }
123 } 125 }
@@ -129,28 +131,57 @@ int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
129 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; 131 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
130#ifndef CHARSET_EBCDIC 132#ifndef CHARSET_EBCDIC
131 BIO_snprintf(tmp,sizeof tmp,"%c", 133 BIO_snprintf(tmp,sizeof tmp,"%c",
132 ((ch>=' ')&&(ch<='~'))?ch:'.'); 134 ((ch>=' ')&&(ch<='~'))?ch:'.');
133#else 135#else
134 BIO_snprintf(tmp,sizeof tmp,"%c", 136 BIO_snprintf(tmp,sizeof tmp,"%c",
135 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) 137 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
136 ? os_toebcdic[ch] 138 ? os_toebcdic[ch]
137 : '.'); 139 : '.');
138#endif 140#endif
139 BUF_strlcat(buf,tmp,sizeof buf); 141 BUF_strlcat(buf,tmp,sizeof buf);
140 } 142 }
141 BUF_strlcat(buf,"\n",sizeof buf); 143 BUF_strlcat(buf,"\n",sizeof buf);
142 /* if this is the last call then update the ddt_dump thing so that 144 /* if this is the last call then update the ddt_dump thing so
143 * we will move the selection point in the debug window 145 * that we will move the selection point in the debug window
144 */ 146 */
145 ret+=BIO_write(bio,(char *)buf,strlen(buf)); 147 ret+=cb((void *)buf,strlen(buf),u);
146 } 148 }
147#ifdef TRUNCATE 149#ifdef TRUNCATE
148 if (trunc > 0) 150 if (trc > 0)
149 { 151 {
150 BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str, 152 BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
151 len+trunc); 153 len+trc);
152 ret+=BIO_write(bio,(char *)buf,strlen(buf)); 154 ret+=cb((void *)buf,strlen(buf),u);
153 } 155 }
154#endif 156#endif
155 return(ret); 157 return(ret);
156 } 158 }
159
160#ifndef OPENSSL_NO_FP_API
161static int write_fp(const void *data, size_t len, void *fp)
162 {
163 return UP_fwrite(data, len, 1, fp);
164 }
165int BIO_dump_fp(FILE *fp, const char *s, int len)
166 {
167 return BIO_dump_cb(write_fp, fp, s, len);
168 }
169int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
170 {
171 return BIO_dump_indent_cb(write_fp, fp, s, len, indent);
172 }
173#endif
174
175static int write_bio(const void *data, size_t len, void *bp)
176 {
177 return BIO_write((BIO *)bp, (const char *)data, len);
178 }
179int BIO_dump(BIO *bp, const char *s, int len)
180 {
181 return BIO_dump_cb(write_bio, bp, s, len);
182 }
183int BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
184 {
185 return BIO_dump_indent_cb(write_bio, bp, s, len, indent);
186 }
187