diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2022-07-01 22:09:18 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2023-01-26 09:16:51 +0100 |
commit | 0243e821473ef6dedc8d5f3d6ebefc1b06f2e46f (patch) | |
tree | cd39a1120c206dbcf8b19676a17447291403f3f7 /crypto | |
parent | 114d99b46bfb212ffc510865df317ca2c1542623 (diff) |
add OSSL_TRACE_STRING(), OSSL_TRACE_STRING_MAX, and OSSL_trace_string()
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/18704)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/trace.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/crypto/trace.c b/crypto/trace.c index 3bf9ff62f7..8e5836de32 100644 --- a/crypto/trace.c +++ b/crypto/trace.c @@ -18,6 +18,7 @@ #include "internal/nelem.h" #include "internal/refcount.h" #include "crypto/cryptlib.h" +#include "crypto/ctype.h" #ifndef OPENSSL_NO_TRACE @@ -530,3 +531,27 @@ void OSSL_trace_end(int category, BIO * channel) } #endif } + +int OSSL_trace_string(BIO *out, int text, int full, + const unsigned char *data, size_t size) +{ + unsigned char buf[OSSL_TRACE_STRING_MAX + 1]; + int len, i; + + if (!full && size > OSSL_TRACE_STRING_MAX) { + BIO_printf(out, "[len %zu limited to %d]: ", + size, OSSL_TRACE_STRING_MAX); + len = OSSL_TRACE_STRING_MAX; + } else { + len = (int)size; + } + if (!text) { /* mask control characters while preserving newlines */ + for (i = 0; i < len; i++, data++) + buf[i] = (char)*data != '\n' && ossl_iscntrl((int)*data) + ? ' ' : *data; + if (len == 0 || data[-1] != '\n') + buf[len++] = '\n'; + data = buf; + } + return BIO_printf(out, "%.*s", len, data); +} |