From 95a1400a2ac9de1a29fa305f45b928ce8e3044bd Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Thu, 2 Apr 2020 01:20:12 +0200 Subject: Replace NULL with nullptr --- modules/mbedtls/crypto_mbedtls.cpp | 26 +++++++++++++------------- modules/mbedtls/crypto_mbedtls.h | 4 ++-- modules/mbedtls/dtls_server_mbedtls.cpp | 2 +- modules/mbedtls/packet_peer_mbed_dtls.cpp | 16 ++++++++-------- modules/mbedtls/ssl_context_mbedtls.cpp | 14 +++++++------- modules/mbedtls/stream_peer_mbedtls.cpp | 14 +++++++------- 6 files changed, 38 insertions(+), 38 deletions(-) (limited to 'modules/mbedtls') diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index c8a8240a19..a47a4503a5 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -66,7 +66,7 @@ Error CryptoKeyMbedTLS::load(String p_path) { } memdelete(f); - int ret = mbedtls_pk_parse_key(&pkey, out.ptr(), out.size(), NULL, 0); + int ret = mbedtls_pk_parse_key(&pkey, out.ptr(), out.size(), nullptr, 0); // We MUST zeroize the memory for safety! mbedtls_platform_zeroize(out.ptrw(), out.size()); ERR_FAIL_COND_V_MSG(ret, FAILED, "Error parsing private key '" + itos(ret) + "'."); @@ -167,11 +167,11 @@ void CryptoMbedTLS::initialize_crypto() { } void CryptoMbedTLS::finalize_crypto() { - Crypto::_create = NULL; - Crypto::_load_default_certificates = NULL; + Crypto::_create = nullptr; + Crypto::_load_default_certificates = nullptr; if (default_certs) { memdelete(default_certs); - default_certs = NULL; + default_certs = nullptr; } X509CertificateMbedTLS::finalize(); CryptoKeyMbedTLS::finalize(); @@ -180,7 +180,7 @@ void CryptoMbedTLS::finalize_crypto() { CryptoMbedTLS::CryptoMbedTLS() { mbedtls_ctr_drbg_init(&ctr_drbg); mbedtls_entropy_init(&entropy); - int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0); + int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, nullptr, 0); if (ret != 0) { ERR_PRINT(" failed\n ! mbedtls_ctr_drbg_seed returned an error" + itos(ret)); } @@ -191,17 +191,17 @@ CryptoMbedTLS::~CryptoMbedTLS() { mbedtls_entropy_free(&entropy); } -X509CertificateMbedTLS *CryptoMbedTLS::default_certs = NULL; +X509CertificateMbedTLS *CryptoMbedTLS::default_certs = nullptr; X509CertificateMbedTLS *CryptoMbedTLS::get_default_certificates() { return default_certs; } void CryptoMbedTLS::load_default_certificates(String p_path) { - ERR_FAIL_COND(default_certs != NULL); + ERR_FAIL_COND(default_certs != nullptr); default_certs = memnew(X509CertificateMbedTLS); - ERR_FAIL_COND(default_certs == NULL); + ERR_FAIL_COND(default_certs == nullptr); if (p_path != "") { // Use certs defined in project settings. @@ -227,15 +227,15 @@ Ref CryptoMbedTLS::generate_rsa(int p_bytes) { Ref out; out.instance(); int ret = mbedtls_pk_setup(&(out->pkey), mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)); - ERR_FAIL_COND_V(ret != 0, NULL); + ERR_FAIL_COND_V(ret != 0, nullptr); ret = mbedtls_rsa_gen_key(mbedtls_pk_rsa(out->pkey), mbedtls_ctr_drbg_random, &ctr_drbg, p_bytes, 65537); - ERR_FAIL_COND_V(ret != 0, NULL); + ERR_FAIL_COND_V(ret != 0, nullptr); return out; } Ref CryptoMbedTLS::generate_self_signed_certificate(Ref p_key, String p_issuer_name, String p_not_before, String p_not_after) { Ref key = static_cast>(p_key); - ERR_FAIL_COND_V_MSG(key.is_null(), NULL, "Invalid private key argument."); + ERR_FAIL_COND_V_MSG(key.is_null(), nullptr, "Invalid private key argument."); mbedtls_x509write_cert crt; mbedtls_x509write_crt_init(&crt); @@ -250,7 +250,7 @@ Ref CryptoMbedTLS::generate_self_signed_certificate(Ref CryptoMbedTLS::generate_self_signed_certificate(Refbase->put_packet((const uint8_t *)buf, len); if (err == ERR_BUSY) { @@ -53,11 +53,11 @@ int PacketPeerMbedDTLS::bio_send(void *ctx, const unsigned char *buf, size_t len int PacketPeerMbedDTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { - if (buf == NULL || len <= 0) return 0; + if (buf == nullptr || len <= 0) return 0; PacketPeerMbedDTLS *sp = (PacketPeerMbedDTLS *)ctx; - ERR_FAIL_COND_V(sp == NULL, 0); + ERR_FAIL_COND_V(sp == nullptr, 0); int pc = sp->base->get_available_packet_count(); if (pc == 0) { @@ -125,7 +125,7 @@ Error PacketPeerMbedDTLS::connect_to_peer(Ref p_base, bool p_vali ERR_FAIL_COND_V(err != OK, err); mbedtls_ssl_set_hostname(ssl_ctx->get_context(), p_for_hostname.utf8().get_data()); - mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, NULL); + mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, nullptr); mbedtls_ssl_set_timer_cb(ssl_ctx->get_context(), &timer, mbedtls_timing_set_delay, mbedtls_timing_get_delay); status = STATUS_HANDSHAKING; @@ -154,7 +154,7 @@ Error PacketPeerMbedDTLS::accept_peer(Ref p_base, Ref ERR_FAIL_V_MSG(FAILED, "Error setting DTLS client cookie"); } - mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, NULL); + mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, nullptr); mbedtls_ssl_set_timer_cb(ssl_ctx->get_context(), &timer, mbedtls_timing_set_delay, mbedtls_timing_get_delay); status = STATUS_HANDSHAKING; @@ -223,7 +223,7 @@ void PacketPeerMbedDTLS::poll() { ERR_FAIL_COND(!base.is_valid()); - int ret = mbedtls_ssl_read(ssl_ctx->get_context(), NULL, 0); + int ret = mbedtls_ssl_read(ssl_ctx->get_context(), nullptr, 0); if (ret < 0 && ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) { @@ -292,6 +292,6 @@ void PacketPeerMbedDTLS::initialize_dtls() { } void PacketPeerMbedDTLS::finalize_dtls() { - _create = NULL; + _create = nullptr; available = false; } diff --git a/modules/mbedtls/ssl_context_mbedtls.cpp b/modules/mbedtls/ssl_context_mbedtls.cpp index 52630bd98c..1ffb9bda05 100644 --- a/modules/mbedtls/ssl_context_mbedtls.cpp +++ b/modules/mbedtls/ssl_context_mbedtls.cpp @@ -53,7 +53,7 @@ Error CookieContextMbedTLS::setup() { mbedtls_ssl_cookie_init(&cookie_ctx); inited = true; - int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0); + int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, nullptr, 0); if (ret != 0) { clear(); // Never leave unusable resources around. ERR_FAIL_V_MSG(FAILED, "mbedtls_ctr_drbg_seed returned an error " + itos(ret)); @@ -94,7 +94,7 @@ Error SSLContextMbedTLS::_setup(int p_endpoint, int p_transport, int p_authmode) mbedtls_entropy_init(&entropy); inited = true; - int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0); + int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, nullptr, 0); if (ret != 0) { clear(); // Never leave unusable resources around. ERR_FAIL_V_MSG(FAILED, "mbedtls_ctr_drbg_seed returned an error " + itos(ret)); @@ -134,7 +134,7 @@ Error SSLContextMbedTLS::init_server(int p_transport, int p_authmode, Refcert.next) { - mbedtls_ssl_conf_ca_chain(&conf, certs->cert.next, NULL); + mbedtls_ssl_conf_ca_chain(&conf, certs->cert.next, nullptr); } // DTLS Cookies if (p_transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { @@ -153,7 +153,7 @@ Error SSLContextMbedTLS::init_client(int p_transport, int p_authmode, Refcert), NULL); + mbedtls_ssl_conf_ca_chain(&conf, &(cas->cert), nullptr); mbedtls_ssl_setup(&ssl, &conf); return OK; } @@ -195,7 +195,7 @@ void SSLContextMbedTLS::clear() { } mbedtls_ssl_context *SSLContextMbedTLS::get_context() { - ERR_FAIL_COND_V(!inited, NULL); + ERR_FAIL_COND_V(!inited, nullptr); return &ssl; } diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp index 03c5922267..983095c536 100755 --- a/modules/mbedtls/stream_peer_mbedtls.cpp +++ b/modules/mbedtls/stream_peer_mbedtls.cpp @@ -35,11 +35,11 @@ int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) { - if (buf == NULL || len <= 0) return 0; + if (buf == nullptr || len <= 0) return 0; StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx; - ERR_FAIL_COND_V(sp == NULL, 0); + ERR_FAIL_COND_V(sp == nullptr, 0); int sent; Error err = sp->base->put_partial_data((const uint8_t *)buf, len, sent); @@ -54,11 +54,11 @@ int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) int StreamPeerMbedTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { - if (buf == NULL || len <= 0) return 0; + if (buf == nullptr || len <= 0) return 0; StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx; - ERR_FAIL_COND_V(sp == NULL, 0); + ERR_FAIL_COND_V(sp == nullptr, 0); int got; Error err = sp->base->get_partial_data((uint8_t *)buf, len, got); @@ -112,7 +112,7 @@ Error StreamPeerMbedTLS::connect_to_stream(Ref p_base, bool p_valida ERR_FAIL_COND_V(err != OK, err); mbedtls_ssl_set_hostname(ssl_ctx->get_context(), p_for_hostname.utf8().get_data()); - mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, NULL); + mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, nullptr); status = STATUS_HANDSHAKING; @@ -133,7 +133,7 @@ Error StreamPeerMbedTLS::accept_stream(Ref p_base, Ref p_ base = p_base; - mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, NULL); + mbedtls_ssl_set_bio(ssl_ctx->get_context(), this, bio_send, bio_recv, nullptr); status = STATUS_HANDSHAKING; @@ -320,5 +320,5 @@ void StreamPeerMbedTLS::initialize_ssl() { void StreamPeerMbedTLS::finalize_ssl() { available = false; - _create = NULL; + _create = nullptr; } -- cgit v1.2.3