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