]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Begin incorporating stdbool usage when json encoding
authorAlexis Goodfellow <alexis.goodfellow@sodahealth.com>
Thu, 12 Jun 2025 03:31:31 +0000 (23:31 -0400)
committerNeil Horman <nhorman@openssl.org>
Fri, 13 Jun 2025 15:26:46 +0000 (11:26 -0400)
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/27812)

CHANGES.md
include/internal/json_enc.h
include/internal/qlog.h
ssl/quic/json_enc.c
ssl/quic/qlog.c
test/json_test.c

index 00bf0c7861ebd85641283f77f80a3107f386ef05..441a143a885b4146aa710d2d03cf63feb0b1698d 100644 (file)
@@ -31,6 +31,12 @@ OpenSSL 3.6
 
 ### Changes between 3.5 and 3.6 [xx XXX xxxx]
 
+ * Introduces use of `<stdbool.h>` 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.
 
index c2e82720286bcd7106e140869d75d74c36710b2f..9b04cb8d73fa9583699ab9a5b8adb38da78a91d6 100644 (file)
@@ -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 <stdbool.h>
 # include <openssl/bio.h>
 
 /*
@@ -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);
index b81bfe7e4b96759ccfaca6e8e5b7dd61546a22e8..3778c8032d2990ec7d162b4d3014007b4bf3e073 100644 (file)
@@ -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 <openssl/ssl.h>
+# include <stdbool.h>
 # 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);
 
index 1d1e17b7525ce0d652ce6659e2ae898ee0d969a9..3f4c5296d6411a4d013a8284f01de211f5d6f8c6 100644 (file)
@@ -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 <string.h>
+#include <stdbool.h>
 
 /*
  * 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);
 }
 
index 3aadda046f7493f527172a397d2370fe3cb8da8b..2115424efe7d848b0e7f10b7002f111d916392a3 100644 (file)
@@ -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 <stdbool.h>
 #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);
index 6372f1beb50c3c2aab7913f489535c31f67fe7ee..64aa9b55becce6f87302ce43a77f451c1eff425c 100644 (file)
@@ -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 <stdio.h>
+#include <stdbool.h>
 #include <string.h>
 
 #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)