Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Unified Diff: webrtc/base/opensslidentity.cc

Issue 2718663005: Replace NULL with nullptr or null in webrtc/base/. (Closed)
Patch Set: Fixing Windows and formatting issues. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/opensslidentity.h ('k') | webrtc/base/opensslstreamadapter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/opensslidentity.cc
diff --git a/webrtc/base/opensslidentity.cc b/webrtc/base/opensslidentity.cc
index 7b96f6a20616b228db03bb07cb06b94934a5ffe2..9495496ffe888332372dac914352bb3a501d2c9f 100644
--- a/webrtc/base/opensslidentity.cc
+++ b/webrtc/base/opensslidentity.cc
@@ -46,13 +46,13 @@ static EVP_PKEY* MakeKey(const KeyParams& key_params) {
RSA* rsa = RSA_new();
if (!pkey || !exponent || !rsa ||
!BN_set_word(exponent, key_params.rsa_params().pub_exp) ||
- !RSA_generate_key_ex(rsa, key_length, exponent, NULL) ||
+ !RSA_generate_key_ex(rsa, key_length, exponent, nullptr) ||
!EVP_PKEY_assign_RSA(pkey, rsa)) {
EVP_PKEY_free(pkey);
BN_free(exponent);
RSA_free(rsa);
LOG(LS_ERROR) << "Failed to make RSA key pair";
- return NULL;
+ return nullptr;
}
// ownership of rsa struct was assigned, don't free it.
BN_free(exponent);
@@ -71,19 +71,19 @@ static EVP_PKEY* MakeKey(const KeyParams& key_params) {
EVP_PKEY_free(pkey);
EC_KEY_free(ec_key);
LOG(LS_ERROR) << "Failed to make EC key pair";
- return NULL;
+ return nullptr;
}
// ownership of ec_key struct was assigned, don't free it.
} else {
// Add generation of any other curves here.
EVP_PKEY_free(pkey);
LOG(LS_ERROR) << "ECDSA key requested for unknown curve";
- return NULL;
+ return nullptr;
}
} else {
EVP_PKEY_free(pkey);
LOG(LS_ERROR) << "Key type requested not understood";
- return NULL;
+ return nullptr;
}
LOG(LS_INFO) << "Returning key pair";
@@ -94,12 +94,12 @@ static EVP_PKEY* MakeKey(const KeyParams& key_params) {
// given key pair. Caller is responsible for freeing the returned object.
static X509* MakeCertificate(EVP_PKEY* pkey, const SSLIdentityParams& params) {
LOG(LS_INFO) << "Making certificate for " << params.common_name;
- X509* x509 = NULL;
- BIGNUM* serial_number = NULL;
- X509_NAME* name = NULL;
+ X509* x509 = nullptr;
+ BIGNUM* serial_number = nullptr;
+ X509_NAME* name = nullptr;
time_t epoch_off = 0; // Time offset since epoch.
- if ((x509=X509_new()) == NULL)
+ if ((x509 = X509_new()) == nullptr)
goto error;
if (!X509_set_pubkey(x509, pkey))
@@ -108,9 +108,9 @@ static X509* MakeCertificate(EVP_PKEY* pkey, const SSLIdentityParams& params) {
// serial number
// temporary reference to serial number inside x509 struct
ASN1_INTEGER* asn1_serial_number;
- if ((serial_number = BN_new()) == NULL ||
+ if ((serial_number = BN_new()) == nullptr ||
!BN_pseudo_rand(serial_number, SERIAL_RAND_BITS, 0, 0) ||
- (asn1_serial_number = X509_get_serialNumber(x509)) == NULL ||
+ (asn1_serial_number = X509_get_serialNumber(x509)) == nullptr ||
!BN_to_ASN1_INTEGER(serial_number, asn1_serial_number))
goto error;
@@ -124,12 +124,11 @@ static X509* MakeCertificate(EVP_PKEY* pkey, const SSLIdentityParams& params) {
// arbitrary common_name. Note that this certificate goes out in
// clear during SSL negotiation, so there may be a privacy issue in
// putting anything recognizable here.
- if ((name = X509_NAME_new()) == NULL ||
- !X509_NAME_add_entry_by_NID(
- name, NID_commonName, MBSTRING_UTF8,
- (unsigned char*)params.common_name.c_str(), -1, -1, 0) ||
- !X509_set_subject_name(x509, name) ||
- !X509_set_issuer_name(x509, name))
+ if ((name = X509_NAME_new()) == nullptr ||
+ !X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
+ (unsigned char*)params.common_name.c_str(),
+ -1, -1, 0) ||
+ !X509_set_subject_name(x509, name) || !X509_set_issuer_name(x509, name))
goto error;
if (!X509_time_adj(X509_get_notBefore(x509), params.not_before, &epoch_off) ||
@@ -148,7 +147,7 @@ static X509* MakeCertificate(EVP_PKEY* pkey, const SSLIdentityParams& params) {
BN_free(serial_number);
X509_NAME_free(name);
X509_free(x509);
- return NULL;
+ return nullptr;
}
// This dumps the SSL error stack to the log.
@@ -166,7 +165,7 @@ OpenSSLKeyPair* OpenSSLKeyPair::Generate(const KeyParams& key_params) {
EVP_PKEY* pkey = MakeKey(key_params);
if (!pkey) {
LogSSLErrors("Generating key pair");
- return NULL;
+ return nullptr;
}
return new OpenSSLKeyPair(pkey);
}
@@ -289,7 +288,7 @@ OpenSSLCertificate* OpenSSLCertificate::Generate(
X509* x509 = MakeCertificate(key_pair->pkey(), actual_params);
if (!x509) {
LogSSLErrors("Generating certificate");
- return NULL;
+ return nullptr;
}
#if !defined(NDEBUG)
PrintCert(x509);
@@ -303,13 +302,14 @@ OpenSSLCertificate* OpenSSLCertificate::FromPEMString(
const std::string& pem_string) {
BIO* bio = BIO_new_mem_buf(const_cast<char*>(pem_string.c_str()), -1);
if (!bio)
- return NULL;
+ return nullptr;
BIO_set_mem_eof_return(bio, 0);
- X509* x509 = PEM_read_bio_X509(bio, NULL, NULL, const_cast<char*>("\0"));
+ X509* x509 =
+ PEM_read_bio_X509(bio, nullptr, nullptr, const_cast<char*>("\0"));
BIO_free(bio); // Frees the BIO, but not the pointed-to string.
if (!x509)
- return NULL;
+ return nullptr;
OpenSSLCertificate* ret = new OpenSSLCertificate(x509);
X509_free(x509);
@@ -441,7 +441,7 @@ void OpenSSLCertificate::ToDER(Buffer* der_buffer) const {
}
void OpenSSLCertificate::AddReference() const {
- RTC_DCHECK(x509_ != NULL);
+ RTC_DCHECK(x509_ != nullptr);
#if defined(OPENSSL_IS_BORINGSSL)
X509_up_ref(x509_);
#else
@@ -476,8 +476,8 @@ int64_t OpenSSLCertificate::CertificateExpirationTime() const {
OpenSSLIdentity::OpenSSLIdentity(OpenSSLKeyPair* key_pair,
OpenSSLCertificate* certificate)
: key_pair_(key_pair), certificate_(certificate) {
- RTC_DCHECK(key_pair != NULL);
- RTC_DCHECK(certificate != NULL);
+ RTC_DCHECK(key_pair != nullptr);
+ RTC_DCHECK(certificate != nullptr);
}
OpenSSLIdentity::~OpenSSLIdentity() = default;
@@ -493,7 +493,7 @@ OpenSSLIdentity* OpenSSLIdentity::GenerateInternal(
delete key_pair;
}
LOG(LS_INFO) << "Identity generation failed";
- return NULL;
+ return nullptr;
}
OpenSSLIdentity* OpenSSLIdentity::GenerateWithExpiration(
@@ -503,7 +503,7 @@ OpenSSLIdentity* OpenSSLIdentity::GenerateWithExpiration(
SSLIdentityParams params;
params.key_params = key_params;
params.common_name = common_name;
- time_t now = time(NULL);
+ time_t now = time(nullptr);
params.not_before = now + kCertificateWindowInSeconds;
params.not_after = now + certificate_lifetime;
if (params.not_before > params.not_after)
« no previous file with comments | « webrtc/base/opensslidentity.h ('k') | webrtc/base/opensslstreamadapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698