Skip to content

Commit 52dba1c

Browse files
RulerOfTheQueendomnhorman
authored andcommitted
Begin incorporating stdbool usage when json encoding
Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Kurt Roeckx <kurt@roeckx.be> (Merged from openssl#27812)
1 parent 49885ae commit 52dba1c

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ OpenSSL 3.6
3131

3232
### Changes between 3.5 and 3.6 [xx XXX xxxx]
3333

34+
* Introduces use of `<stdbool.h>` when handling JSON encoding in
35+
the OpenSSL codebase, replacing the previous use of `int` for
36+
these boolean values.
37+
38+
*Alexis Goodfellow*
39+
3440
* An ANSI-C toolchain is no longer sufficient for building OpenSSL. The code
3541
should build on compilers supporting C-99 features.
3642

include/internal/json_enc.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
@@ -10,6 +10,7 @@
1010
#ifndef OSSL_JSON_ENC_H
1111
# define OSSL_JSON_ENC_H
1212

13+
# include <stdbool.h>
1314
# include <openssl/bio.h>
1415

1516
/*
@@ -194,7 +195,7 @@ void ossl_json_key(OSSL_JSON_ENC *json, const char *key);
194195
void ossl_json_null(OSSL_JSON_ENC *json);
195196

196197
/* Encode a JSON boolean value. */
197-
void ossl_json_bool(OSSL_JSON_ENC *json, int value);
198+
void ossl_json_bool(OSSL_JSON_ENC *json, bool value);
198199

199200
/* Encode a JSON integer from a uint64_t. */
200201
void ossl_json_u64(OSSL_JSON_ENC *json, uint64_t value);

include/internal/qlog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
@@ -11,6 +11,7 @@
1111
# define OSSL_QLOG_H
1212

1313
# include <openssl/ssl.h>
14+
# include <stdbool.h>
1415
# include "internal/quic_types.h"
1516
# include "internal/time.h"
1617

@@ -110,7 +111,7 @@ void ossl_qlog_str_len(QLOG *qlog, const char *name,
110111
const char *value, size_t value_len);
111112
void ossl_qlog_u64(QLOG *qlog, const char *name, uint64_t value);
112113
void ossl_qlog_i64(QLOG *qlog, const char *name, int64_t value);
113-
void ossl_qlog_bool(QLOG *qlog, const char *name, int value);
114+
void ossl_qlog_bool(QLOG *qlog, const char *name, bool value);
114115
void ossl_qlog_bin(QLOG *qlog, const char *name,
115116
const void *value, size_t value_len);
116117

ssl/quic/json_enc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
@@ -11,6 +11,7 @@
1111
#include "internal/nelem.h"
1212
#include "internal/numbers.h"
1313
#include <string.h>
14+
#include <stdbool.h>
1415

1516
/*
1617
* wbuf
@@ -521,12 +522,12 @@ void ossl_json_null(OSSL_JSON_ENC *json)
521522
json_post_item(json);
522523
}
523524

524-
void ossl_json_bool(OSSL_JSON_ENC *json, int v)
525+
void ossl_json_bool(OSSL_JSON_ENC *json, bool v)
525526
{
526527
if (!json_pre_item(json))
527528
return;
528529

529-
json_write_str(json, v > 0 ? "true" : "false");
530+
json_write_str(json, v ? "true" : "false");
530531
json_post_item(json);
531532
}
532533

ssl/quic/qlog.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
66
* in the file LICENSE in the source distribution or at
77
* https://www.openssl.org/source/license.html
88
*/
99

10+
#include <stdbool.h>
1011
#include "internal/qlog.h"
1112
#include "internal/json_enc.h"
1213
#include "internal/common.h"
@@ -492,7 +493,7 @@ void ossl_qlog_i64(QLOG *qlog, const char *name, int64_t value)
492493
ossl_json_i64(&qlog->json, value);
493494
}
494495

495-
void ossl_qlog_bool(QLOG *qlog, const char *name, int value)
496+
void ossl_qlog_bool(QLOG *qlog, const char *name, bool value)
496497
{
497498
if (name != NULL)
498499
ossl_json_key(&qlog->json, name);

test/json_test.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <stdio.h>
11+
#include <stdbool.h>
1112
#include <string.h>
1213

1314
#include "testutil.h"
@@ -172,11 +173,11 @@ BEGIN_SCRIPT(array_empty, "serialize an empty array", 0)
172173
END_SCRIPT_EXPECTING_Q([])
173174

174175
BEGIN_SCRIPT(bool_false, "serialize false", 0)
175-
OPJ_BOOL(0)
176+
OPJ_BOOL(false)
176177
END_SCRIPT_EXPECTING_Q(false)
177178

178179
BEGIN_SCRIPT(bool_true, "serialize true", 0)
179-
OPJ_BOOL(1)
180+
OPJ_BOOL(true)
180181
END_SCRIPT_EXPECTING_Q(true)
181182

182183
BEGIN_SCRIPT(u64_0, "serialize u64(0)", 0)

0 commit comments

Comments
 (0)