diff options
| author | jsing <> | 2014-04-15 16:37:22 +0000 |
|---|---|---|
| committer | jsing <> | 2014-04-15 16:37:22 +0000 |
| commit | 405f0a76509e0e96df735b5b902a28b8ab6c9c55 (patch) | |
| tree | 41dd30d546977ed0c409d7de59564fa1a2e3b100 /src/lib/libcrypto/bio/b_dump.c | |
| parent | 4e5cf8d1c0be703d2956348c807ab6ac39172547 (diff) | |
| download | openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.tar.gz openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.tar.bz2 openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.zip | |
First pass at applying KNF to the OpenSSL code, which almost makes it
readable. This pass is whitespace only and can readily be verified using
tr and md5.
Diffstat (limited to 'src/lib/libcrypto/bio/b_dump.c')
| -rw-r--r-- | src/lib/libcrypto/bio/b_dump.c | 171 |
1 files changed, 87 insertions, 84 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c index 492ee09275..bea94969a2 100644 --- a/src/lib/libcrypto/bio/b_dump.c +++ b/src/lib/libcrypto/bio/b_dump.c | |||
| @@ -66,122 +66,125 @@ | |||
| 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 |
| 72 | void *u, const char *s, int len) | 72 | BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), |
| 73 | { | 73 | void *u, const char *s, int len) |
| 74 | { | ||
| 74 | return BIO_dump_indent_cb(cb, u, s, len, 0); | 75 | return BIO_dump_indent_cb(cb, u, s, len, 0); |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), | 78 | int |
| 78 | void *u, const char *s, int len, int indent) | 79 | BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), |
| 79 | { | 80 | void *u, const char *s, int len, int indent) |
| 80 | int ret=0; | 81 | { |
| 81 | char buf[288+1],tmp[20],str[128+1]; | 82 | int ret = 0; |
| 82 | int i,j,rows,trc; | 83 | char buf[288 + 1], tmp[20], str[128 + 1]; |
| 84 | int i, j, rows, trc; | ||
| 83 | unsigned char ch; | 85 | unsigned char ch; |
| 84 | int dump_width; | 86 | int dump_width; |
| 85 | 87 | ||
| 86 | trc=0; | 88 | trc = 0; |
| 87 | 89 | ||
| 88 | #ifdef TRUNCATE | 90 | #ifdef TRUNCATE |
| 89 | for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) | 91 | for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--) |
| 90 | trc++; | 92 | trc++; |
| 91 | #endif | 93 | #endif |
| 92 | 94 | ||
| 93 | if (indent < 0) | 95 | if (indent < 0) |
| 94 | indent = 0; | 96 | indent = 0; |
| 95 | if (indent) | 97 | if (indent) { |
| 96 | { | 98 | if (indent > 128) |
| 97 | if (indent > 128) indent=128; | 99 | indent = 128; |
| 98 | memset(str,' ',indent); | 100 | memset(str, ' ', indent); |
| 99 | } | 101 | } |
| 100 | str[indent]='\0'; | 102 | str[indent] = '\0'; |
| 101 | 103 | ||
| 102 | dump_width=DUMP_WIDTH_LESS_INDENT(indent); | 104 | dump_width = DUMP_WIDTH_LESS_INDENT(indent); |
| 103 | rows=(len/dump_width); | 105 | rows = (len / dump_width); |
| 104 | if ((rows*dump_width)<len) | 106 | if ((rows * dump_width) < len) |
| 105 | rows++; | 107 | rows++; |
| 106 | for(i=0;i<rows;i++) | 108 | for (i = 0; i < rows; i++) { |
| 107 | { | 109 | buf[0] = '\0'; /* start with empty string */ |
| 108 | buf[0]='\0'; /* start with empty string */ | 110 | BUF_strlcpy(buf, str, sizeof buf); |
| 109 | BUF_strlcpy(buf,str,sizeof buf); | 111 | (void) snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width); |
| 110 | (void) snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width); | 112 | BUF_strlcat(buf, tmp, sizeof buf); |
| 111 | BUF_strlcat(buf,tmp,sizeof buf); | 113 | for (j = 0; j < dump_width; j++) { |
| 112 | for(j=0;j<dump_width;j++) | 114 | if (((i*dump_width) + j) >= len) { |
| 113 | { | 115 | BUF_strlcat(buf, " ", sizeof buf); |
| 114 | if (((i*dump_width)+j)>=len) | 116 | } else { |
| 115 | { | 117 | ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff; |
| 116 | BUF_strlcat(buf," ",sizeof buf); | 118 | (void) snprintf(tmp, sizeof tmp, "%02x%c", ch, |
| 117 | } | 119 | j == 7 ? '-' : ' '); |
| 118 | else | 120 | BUF_strlcat(buf, tmp, sizeof buf); |
| 119 | { | ||
| 120 | ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; | ||
| 121 | (void) snprintf(tmp,sizeof tmp,"%02x%c",ch, | ||
| 122 | j==7?'-':' '); | ||
| 123 | BUF_strlcat(buf,tmp,sizeof buf); | ||
| 124 | } | ||
| 125 | } | 121 | } |
| 126 | BUF_strlcat(buf," ",sizeof buf); | 122 | } |
| 127 | for(j=0;j<dump_width;j++) | 123 | BUF_strlcat(buf, " ", sizeof buf); |
| 128 | { | 124 | for (j = 0; j < dump_width; j++) { |
| 129 | if (((i*dump_width)+j)>=len) | 125 | if (((i*dump_width) + j) >= len) |
| 130 | break; | 126 | break; |
| 131 | ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; | 127 | ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; |
| 132 | #ifndef CHARSET_EBCDIC | 128 | #ifndef CHARSET_EBCDIC |
| 133 | (void) snprintf(tmp,sizeof tmp,"%c", | 129 | (void) snprintf(tmp, sizeof tmp, "%c", |
| 134 | ((ch>=' ')&&(ch<='~'))?ch:'.'); | 130 | ((ch >= ' ') && (ch <= '~')) ? ch : '.'); |
| 135 | #else | 131 | #else |
| 136 | (void) snprintf(tmp,sizeof tmp,"%c", | 132 | (void) snprintf(tmp, sizeof tmp, "%c", |
| 137 | ((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) | 133 | ((ch >= os_toascii[' ']) && (ch <= os_toascii['~'])) |
| 138 | ? os_toebcdic[ch] | 134 | ? os_toebcdic[ch] : '.'); |
| 139 | : '.'); | ||
| 140 | #endif | 135 | #endif |
| 141 | BUF_strlcat(buf,tmp,sizeof buf); | 136 | BUF_strlcat(buf, tmp, sizeof buf); |
| 142 | } | 137 | } |
| 143 | BUF_strlcat(buf,"\n",sizeof buf); | 138 | BUF_strlcat(buf, "\n", sizeof buf); |
| 144 | /* if this is the last call then update the ddt_dump thing so | 139 | /* 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 | 140 | * that we will move the selection point in the debug window |
| 146 | */ | 141 | */ |
| 147 | ret+=cb((void *)buf,strlen(buf),u); | 142 | ret += cb((void *)buf, strlen(buf), u); |
| 148 | } | 143 | } |
| 149 | #ifdef TRUNCATE | 144 | #ifdef TRUNCATE |
| 150 | if (trc > 0) | 145 | if (trc > 0) { |
| 151 | { | 146 | (void) snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n", |
| 152 | (void) snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str, | 147 | str, len + trc); |
| 153 | len+trc); | 148 | ret += cb((void *)buf, strlen(buf), u); |
| 154 | ret+=cb((void *)buf,strlen(buf),u); | ||
| 155 | } | ||
| 156 | #endif | ||
| 157 | return(ret); | ||
| 158 | } | 149 | } |
| 150 | #endif | ||
| 151 | return (ret); | ||
| 152 | } | ||
| 159 | 153 | ||
| 160 | #ifndef OPENSSL_NO_FP_API | 154 | #ifndef OPENSSL_NO_FP_API |
| 161 | static int write_fp(const void *data, size_t len, void *fp) | 155 | static int |
| 162 | { | 156 | write_fp(const void *data, size_t len, void *fp) |
| 157 | { | ||
| 163 | return UP_fwrite(data, len, 1, fp); | 158 | return UP_fwrite(data, len, 1, fp); |
| 164 | } | 159 | } |
| 165 | int BIO_dump_fp(FILE *fp, const char *s, int len) | 160 | |
| 166 | { | 161 | int |
| 162 | BIO_dump_fp(FILE *fp, const char *s, int len) | ||
| 163 | { | ||
| 167 | return BIO_dump_cb(write_fp, fp, s, len); | 164 | return BIO_dump_cb(write_fp, fp, s, len); |
| 168 | } | 165 | } |
| 169 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) | 166 | |
| 170 | { | 167 | int |
| 168 | BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) | ||
| 169 | { | ||
| 171 | return BIO_dump_indent_cb(write_fp, fp, s, len, indent); | 170 | return BIO_dump_indent_cb(write_fp, fp, s, len, indent); |
| 172 | } | 171 | } |
| 173 | #endif | 172 | #endif |
| 174 | 173 | ||
| 175 | static int write_bio(const void *data, size_t len, void *bp) | 174 | static int |
| 176 | { | 175 | write_bio(const void *data, size_t len, void *bp) |
| 176 | { | ||
| 177 | return BIO_write((BIO *)bp, (const char *)data, len); | 177 | return BIO_write((BIO *)bp, (const char *)data, len); |
| 178 | } | 178 | } |
| 179 | int BIO_dump(BIO *bp, const char *s, int len) | 179 | |
| 180 | { | 180 | int |
| 181 | BIO_dump(BIO *bp, const char *s, int len) | ||
| 182 | { | ||
| 181 | return BIO_dump_cb(write_bio, bp, s, len); | 183 | return BIO_dump_cb(write_bio, bp, s, len); |
| 182 | } | 184 | } |
| 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 | 185 | ||
| 186 | int | ||
| 187 | BIO_dump_indent(BIO *bp, const char *s, int len, int indent) | ||
| 188 | { | ||
| 189 | return BIO_dump_indent_cb(write_bio, bp, s, len, indent); | ||
| 190 | } | ||
