diff options
Diffstat (limited to 'core/crypto/crypto.cpp')
-rw-r--r-- | core/crypto/crypto.cpp | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index 793bf719b7..eb942c60c9 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -36,11 +36,12 @@ /// Resources -CryptoKey *(*CryptoKey::_create)() = NULL; +CryptoKey *(*CryptoKey::_create)() = nullptr; CryptoKey *CryptoKey::create() { - if (_create) + if (_create) { return _create(); - return NULL; + } + return nullptr; } void CryptoKey::_bind_methods() { @@ -48,11 +49,12 @@ void CryptoKey::_bind_methods() { ClassDB::bind_method(D_METHOD("load", "path"), &CryptoKey::load); } -X509Certificate *(*X509Certificate::_create)() = NULL; +X509Certificate *(*X509Certificate::_create)() = nullptr; X509Certificate *X509Certificate::create() { - if (_create) + if (_create) { return _create(); - return NULL; + } + return nullptr; } void X509Certificate::_bind_methods() { @@ -62,18 +64,19 @@ void X509Certificate::_bind_methods() { /// Crypto -void (*Crypto::_load_default_certificates)(String p_path) = NULL; -Crypto *(*Crypto::_create)() = NULL; +void (*Crypto::_load_default_certificates)(String p_path) = nullptr; +Crypto *(*Crypto::_create)() = nullptr; Crypto *Crypto::create() { - if (_create) + if (_create) { return _create(); + } return memnew(Crypto); } void Crypto::load_default_certificates(String p_path) { - - if (_load_default_certificates) + if (_load_default_certificates) { _load_default_certificates(p_path); + } } void Crypto::_bind_methods() { @@ -87,58 +90,53 @@ PackedByteArray Crypto::generate_random_bytes(int p_bytes) { } Ref<CryptoKey> Crypto::generate_rsa(int p_bytes) { - ERR_FAIL_V_MSG(NULL, "generate_rsa is not available when mbedtls module is disabled."); + ERR_FAIL_V_MSG(nullptr, "generate_rsa is not available when mbedtls module is disabled."); } Ref<X509Certificate> Crypto::generate_self_signed_certificate(Ref<CryptoKey> p_key, String p_issuer_name, String p_not_before, String p_not_after) { - ERR_FAIL_V_MSG(NULL, "generate_self_signed_certificate is not available when mbedtls module is disabled."); -} - -Crypto::Crypto() { + ERR_FAIL_V_MSG(nullptr, "generate_self_signed_certificate is not available when mbedtls module is disabled."); } /// Resource loader/saver -RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { - +RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { String el = p_path.get_extension().to_lower(); if (el == "crt") { X509Certificate *cert = X509Certificate::create(); - if (cert) + if (cert) { cert->load(p_path); + } return cert; } else if (el == "key") { CryptoKey *key = CryptoKey::create(); - if (key) + if (key) { key->load(p_path); + } return key; } - return NULL; + return nullptr; } void ResourceFormatLoaderCrypto::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("crt"); p_extensions->push_back("key"); } bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const { - return p_type == "X509Certificate" || p_type == "CryptoKey"; } String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); - if (el == "crt") + if (el == "crt") { return "X509Certificate"; - else if (el == "key") + } else if (el == "key") { return "CryptoKey"; + } return ""; } Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Error err; Ref<X509Certificate> cert = p_resource; Ref<CryptoKey> key = p_resource; @@ -154,7 +152,6 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc } void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - const X509Certificate *cert = Object::cast_to<X509Certificate>(*p_resource); const CryptoKey *key = Object::cast_to<CryptoKey>(*p_resource); if (cert) { @@ -164,7 +161,7 @@ void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, p_extensions->push_back("key"); } } -bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const { +bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const { return Object::cast_to<X509Certificate>(*p_resource) || Object::cast_to<CryptoKey>(*p_resource); } |