From: Alexis Goodfellow Date: Thu, 12 Jun 2025 03:31:31 +0000 (-0400) Subject: Begin incorporating stdbool usage when json encoding X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52dba1c098d9b0388afa4db2fbe3461df67461c6;p=thirdparty%2Fopenssl.git Begin incorporating stdbool usage when json encoding Reviewed-by: Neil Horman Reviewed-by: Kurt Roeckx (Merged from https://github.com/openssl/openssl/pull/27812) --- diff --git a/CHANGES.md b/CHANGES.md index 00bf0c7861e..441a143a885 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -31,6 +31,12 @@ OpenSSL 3.6 ### Changes between 3.5 and 3.6 [xx XXX xxxx] + * Introduces use of `` when handling JSON encoding in + the OpenSSL codebase, replacing the previous use of `int` for + these boolean values. + + *Alexis Goodfellow* + * An ANSI-C toolchain is no longer sufficient for building OpenSSL. The code should build on compilers supporting C-99 features. diff --git a/include/internal/json_enc.h b/include/internal/json_enc.h index c2e82720286..9b04cb8d73f 100644 --- a/include/internal/json_enc.h +++ b/include/internal/json_enc.h @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,6 +10,7 @@ #ifndef OSSL_JSON_ENC_H # define OSSL_JSON_ENC_H +# include # include /* @@ -194,7 +195,7 @@ void ossl_json_key(OSSL_JSON_ENC *json, const char *key); void ossl_json_null(OSSL_JSON_ENC *json); /* Encode a JSON boolean value. */ -void ossl_json_bool(OSSL_JSON_ENC *json, int value); +void ossl_json_bool(OSSL_JSON_ENC *json, bool value); /* Encode a JSON integer from a uint64_t. */ void ossl_json_u64(OSSL_JSON_ENC *json, uint64_t value); diff --git a/include/internal/qlog.h b/include/internal/qlog.h index b81bfe7e4b9..3778c8032d2 100644 --- a/include/internal/qlog.h +++ b/include/internal/qlog.h @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,6 +11,7 @@ # define OSSL_QLOG_H # include +# include # include "internal/quic_types.h" # include "internal/time.h" @@ -110,7 +111,7 @@ void ossl_qlog_str_len(QLOG *qlog, const char *name, const char *value, size_t value_len); void ossl_qlog_u64(QLOG *qlog, const char *name, uint64_t value); void ossl_qlog_i64(QLOG *qlog, const char *name, int64_t value); -void ossl_qlog_bool(QLOG *qlog, const char *name, int value); +void ossl_qlog_bool(QLOG *qlog, const char *name, bool value); void ossl_qlog_bin(QLOG *qlog, const char *name, const void *value, size_t value_len); diff --git a/ssl/quic/json_enc.c b/ssl/quic/json_enc.c index 1d1e17b7525..3f4c5296d64 100644 --- a/ssl/quic/json_enc.c +++ b/ssl/quic/json_enc.c @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,6 +11,7 @@ #include "internal/nelem.h" #include "internal/numbers.h" #include +#include /* * wbuf @@ -521,12 +522,12 @@ void ossl_json_null(OSSL_JSON_ENC *json) json_post_item(json); } -void ossl_json_bool(OSSL_JSON_ENC *json, int v) +void ossl_json_bool(OSSL_JSON_ENC *json, bool v) { if (!json_pre_item(json)) return; - json_write_str(json, v > 0 ? "true" : "false"); + json_write_str(json, v ? "true" : "false"); json_post_item(json); } diff --git a/ssl/quic/qlog.c b/ssl/quic/qlog.c index 3aadda046f7..2115424efe7 100644 --- a/ssl/quic/qlog.c +++ b/ssl/quic/qlog.c @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,6 +7,7 @@ * https://www.openssl.org/source/license.html */ +#include #include "internal/qlog.h" #include "internal/json_enc.h" #include "internal/common.h" @@ -492,7 +493,7 @@ void ossl_qlog_i64(QLOG *qlog, const char *name, int64_t value) ossl_json_i64(&qlog->json, value); } -void ossl_qlog_bool(QLOG *qlog, const char *name, int value) +void ossl_qlog_bool(QLOG *qlog, const char *name, bool value) { if (name != NULL) ossl_json_key(&qlog->json, name); diff --git a/test/json_test.c b/test/json_test.c index 6372f1beb50..64aa9b55bec 100644 --- a/test/json_test.c +++ b/test/json_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,6 +8,7 @@ */ #include +#include #include #include "testutil.h" @@ -172,11 +173,11 @@ BEGIN_SCRIPT(array_empty, "serialize an empty array", 0) END_SCRIPT_EXPECTING_Q([]) BEGIN_SCRIPT(bool_false, "serialize false", 0) - OPJ_BOOL(0) + OPJ_BOOL(false) END_SCRIPT_EXPECTING_Q(false) BEGIN_SCRIPT(bool_true, "serialize true", 0) - OPJ_BOOL(1) + OPJ_BOOL(true) END_SCRIPT_EXPECTING_Q(true) BEGIN_SCRIPT(u64_0, "serialize u64(0)", 0)