summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bio/b_dump.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
index e46424e699..ef965b61d0 100644
--- a/src/lib/libcrypto/bio/b_dump.c
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: b_dump.c,v 1.26 2023/07/29 02:32:00 tb Exp $ */ 1/* $OpenBSD: b_dump.c,v 1.27 2024/02/01 17:04:09 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -64,21 +64,14 @@
64#include <string.h> 64#include <string.h>
65 65
66#include <openssl/bio.h> 66#include <openssl/bio.h>
67#include <openssl/err.h>
67 68
68#define TRUNCATE 69#define TRUNCATE
69#define DUMP_WIDTH 16 70#define DUMP_WIDTH 16
70#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4)) 71#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4))
71 72
72int 73int
73BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), 74BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
74 void *u, const char *s, int len)
75{
76 return BIO_dump_indent_cb(cb, u, s, len, 0);
77}
78
79int
80BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
81 void *u, const char *s, int len, int indent)
82{ 75{
83 char buf[288 + 1], tmp[20], str[128 + 1]; 76 char buf[288 + 1], tmp[20], str[128 + 1];
84 int i, j, rows, trc, written; 77 int i, j, rows, trc, written;
@@ -132,7 +125,7 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
132 /* if this is the last call then update the ddt_dump thing so 125 /* if this is the last call then update the ddt_dump thing so
133 * that we will move the selection point in the debug window 126 * that we will move the selection point in the debug window
134 */ 127 */
135 if ((written = cb((void *)buf, strlen(buf), u)) < 0) 128 if ((written = BIO_write(bio, buf, strlen(buf))) < 0)
136 return -1; 129 return -1;
137 ret += written; 130 ret += written;
138 131
@@ -141,50 +134,54 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
141 if (trc > 0) { 134 if (trc > 0) {
142 snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n", 135 snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n",
143 str, len + trc); 136 str, len + trc);
144 if ((written = cb((void *)buf, strlen(buf), u)) < 0) 137 if ((written = BIO_write(bio, buf, strlen(buf))) < 0)
145 return -1; 138 return -1;
146 ret += written; 139 ret += written;
147 } 140 }
148#endif 141#endif
149 return (ret); 142 return (ret);
150} 143}
151 144LCRYPTO_ALIAS(BIO_dump_indent);
152static int
153write_fp(const void *data, size_t len, void *fp)
154{
155 return fwrite(data, 1, len, fp);
156}
157 145
158int 146int
159BIO_dump_fp(FILE *fp, const char *s, int len) 147BIO_dump(BIO *bio, const char *s, int len)
160{ 148{
161 return BIO_dump_cb(write_fp, fp, s, len); 149 return BIO_dump_indent(bio, s, len, 0);
162} 150}
163LCRYPTO_ALIAS(BIO_dump_fp); 151LCRYPTO_ALIAS(BIO_dump);
152
153/*
154 * XXX - remove the functions below in the next major bump.
155 */
164 156
165int 157int
166BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) 158BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
159 void *u, const char *s, int len)
167{ 160{
168 return BIO_dump_indent_cb(write_fp, fp, s, len, indent); 161 BIOerror(ERR_R_DISABLED);
162 return -1;
169} 163}
170LCRYPTO_ALIAS(BIO_dump_indent_fp);
171 164
172static int 165int
173write_bio(const void *data, size_t len, void *bp) 166BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
167 void *u, const char *s, int len, int indent)
174{ 168{
175 return BIO_write((BIO *)bp, (const char *)data, len); 169 BIOerror(ERR_R_DISABLED);
170 return -1;
176} 171}
177 172
178int 173int
179BIO_dump(BIO *bp, const char *s, int len) 174BIO_dump_fp(FILE *fp, const char *s, int len)
180{ 175{
181 return BIO_dump_cb(write_bio, bp, s, len); 176 BIOerror(ERR_R_DISABLED);
177 return -1;
182} 178}
183LCRYPTO_ALIAS(BIO_dump); 179LCRYPTO_ALIAS(BIO_dump_fp);
184 180
185int 181int
186BIO_dump_indent(BIO *bp, const char *s, int len, int indent) 182BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
187{ 183{
188 return BIO_dump_indent_cb(write_bio, bp, s, len, indent); 184 BIOerror(ERR_R_DISABLED);
185 return -1;
189} 186}
190LCRYPTO_ALIAS(BIO_dump_indent); 187LCRYPTO_ALIAS(BIO_dump_indent_fp);