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.c129
1 files changed, 78 insertions, 51 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
index db84ad3d47..8397cfab6a 100644
--- a/src/lib/libcrypto/bio/b_dump.c
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -62,64 +62,91 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio.h" 65#include <openssl/bio.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 70
70int BIO_dump(bio,s,len) 71int BIO_dump(BIO *bio, const char *s, int len)
71BIO *bio; 72 {
72char *s; 73 return BIO_dump_indent(bio, s, len, 0);
73int len; 74 }
74{
75 int ret=0;
76 char buf[160+1],tmp[20];
77 int i,j,rows,trunc;
78 unsigned char ch;
79
80 trunc=0;
81 75
76int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
77 {
78 int ret=0;
79 char buf[288+1],tmp[20],str[128+1];
80 int i,j,rows,trunc;
81 unsigned char ch;
82 int dump_width;
83
84 trunc=0;
85
82#ifdef TRUNCATE 86#ifdef TRUNCATE
83 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) 87 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
84 trunc++; 88 trunc++;
85#endif 89#endif
86 90
87 rows=(len/DUMP_WIDTH); 91 if (indent < 0)
88 if ((rows*DUMP_WIDTH)<len) 92 indent = 0;
89 rows++; 93 if (indent)
90 for(i=0;i<rows;i++) { 94 {
91 buf[0]='\0'; /* start with empty string */ 95 if (indent > 128) indent=128;
92 sprintf(tmp,"%04x - ",i*DUMP_WIDTH); 96 memset(str,' ',indent);
93 strcpy(buf,tmp); 97 }
94 for(j=0;j<DUMP_WIDTH;j++) { 98 str[indent]='\0';
95 if (((i*DUMP_WIDTH)+j)>=len) { 99
96 strcat(buf," "); 100 dump_width=DUMP_WIDTH_LESS_INDENT(indent);
97 } else { 101 rows=(len/dump_width);
98 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; 102 if ((rows*dump_width)<len)
99 sprintf(tmp,"%02x%c",ch,j==7?'-':' '); 103 rows++;
100 strcat(buf,tmp); 104 for(i=0;i<rows;i++)
101 } 105 {
102 } 106 buf[0]='\0'; /* start with empty string */
103 strcat(buf," "); 107 strcpy(buf,str);
104 for(j=0;j<DUMP_WIDTH;j++) { 108 sprintf(tmp,"%04x - ",i*dump_width);
105 if (((i*DUMP_WIDTH)+j)>=len) 109 strcat(buf,tmp);
106 break; 110 for(j=0;j<dump_width;j++)
107 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; 111 {
108 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); 112 if (((i*dump_width)+j)>=len)
109 strcat(buf,tmp); 113 {
110 } 114 strcat(buf," ");
111 strcat(buf,"\n"); 115 }
112 /* if this is the last call then update the ddt_dump thing so that 116 else
113 * we will move the selection point in the debug window 117 {
114 */ 118 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
115 ret+=BIO_write(bio,(char *)buf,strlen(buf)); 119 sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
116 } 120 strcat(buf,tmp);
121 }
122 }
123 strcat(buf," ");
124 for(j=0;j<dump_width;j++)
125 {
126 if (((i*dump_width)+j)>=len)
127 break;
128 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
129#ifndef CHARSET_EBCDIC
130 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
131#else
132 sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
133 ? os_toebcdic[ch]
134 : '.');
135#endif
136 strcat(buf,tmp);
137 }
138 strcat(buf,"\n");
139 /* if this is the last call then update the ddt_dump thing so that
140 * we will move the selection point in the debug window
141 */
142 ret+=BIO_write(bio,(char *)buf,strlen(buf));
143 }
117#ifdef TRUNCATE 144#ifdef TRUNCATE
118 if (trunc > 0) { 145 if (trunc > 0)
119 sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc); 146 {
120 ret+=BIO_write(bio,(char *)buf,strlen(buf)); 147 sprintf(buf,"%s%04x - <SPACES/NULS>\n",str,len+trunc);
121 } 148 ret+=BIO_write(bio,(char *)buf,strlen(buf));
149 }
122#endif 150#endif
123 return(ret); 151 return(ret);
124} 152 }
125