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