From e0460fa15be022a5b705adcdc178f411ffc962aa Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 15 Jun 2016 10:52:23 +0200 Subject: [PATCH] Redundant sizeof(char) removed for code clarity --- lib/EAPBase/include/EAPSerial.h | 2 +- lib/EAPBase/src/Credentials.cpp | 32 ++++++++++++++++---------------- lib/TLS/src/Credentials.cpp | 28 ++++++++++++++-------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/EAPBase/include/EAPSerial.h b/lib/EAPBase/include/EAPSerial.h index 8e0be3c..8d6556e 100644 --- a/lib/EAPBase/include/EAPSerial.h +++ b/lib/EAPBase/include/EAPSerial.h @@ -251,7 +251,7 @@ namespace eapserial template inline size_t get_pk_size(const std::basic_string &val) { - return sizeof(std::string::size_type) + sizeof(char)*WideCharToMultiByte(CP_UTF8, 0, val.c_str(), (int)val.length(), NULL, 0, NULL, NULL); + return sizeof(std::string::size_type) + WideCharToMultiByte(CP_UTF8, 0, val.c_str(), (int)val.length(), NULL, 0, NULL, NULL); } diff --git a/lib/EAPBase/src/Credentials.cpp b/lib/EAPBase/src/Credentials.cpp index 7cdc451..55bbf61 100644 --- a/lib/EAPBase/src/Credentials.cpp +++ b/lib/EAPBase/src/Credentials.cpp @@ -238,7 +238,7 @@ DWORD eap::credentials_pass::store(_In_ LPCTSTR pszTargetName, _Out_ EAP_ERROR * // Encrypt password. vector password; - if ((dwResult = encrypt(cp, password_utf8.c_str(), password_utf8.length()*sizeof(sanitizing_string::value_type), password, ppEapError, hash)) != ERROR_SUCCESS) + if ((dwResult = encrypt(cp, password_utf8.c_str(), password_utf8.length(), password, ppEapError, hash)) != ERROR_SUCCESS) return dwResult; // Calculate MD5 hash and append it. @@ -261,21 +261,21 @@ DWORD eap::credentials_pass::store(_In_ LPCTSTR pszTargetName, _Out_ EAP_ERROR * tstring target(target_name(pszTargetName)); // Write credentials. - assert(password_enc.size()*sizeof(char) < CRED_MAX_CREDENTIAL_BLOB_SIZE); - assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH ); + assert(password_enc.size() < CRED_MAX_CREDENTIAL_BLOB_SIZE); + assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH ); CREDENTIAL cred = { - 0, // Flags - CRED_TYPE_GENERIC, // Type - (LPTSTR)target.c_str(), // TargetName - _T(""), // Comment - { 0, 0 }, // LastWritten - (DWORD)password_enc.size()*sizeof(char), // CredentialBlobSize - (LPBYTE)password_enc.data(), // CredentialBlob - CRED_PERSIST_ENTERPRISE, // Persist - 0, // AttributeCount - NULL, // Attributes - NULL, // TargetAlias - (LPTSTR)m_identity.c_str() // UserName + 0, // Flags + CRED_TYPE_GENERIC, // Type + (LPTSTR)target.c_str(), // TargetName + _T(""), // Comment + { 0, 0 }, // LastWritten + (DWORD)password_enc.size(), // CredentialBlobSize + (LPBYTE)password_enc.data(),// CredentialBlob + CRED_PERSIST_ENTERPRISE, // Persist + 0, // AttributeCount + NULL, // Attributes + NULL, // TargetAlias + (LPTSTR)m_identity.c_str() // UserName }; if (!CredWrite(&cred, 0)) { *ppEapError = m_module.make_error(dwResult = GetLastError(), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" CredWrite failed."), NULL); @@ -302,7 +302,7 @@ DWORD eap::credentials_pass::retrieve(_In_ LPCTSTR pszTargetName, _Out_ EAP_ERRO // Decrypt the password using user's key. string password_base64; - if (!CredUnprotectA(TRUE, (LPCSTR)(cred->CredentialBlob), cred->CredentialBlobSize/sizeof(char), password_base64)) { + if (!CredUnprotectA(TRUE, (LPCSTR)(cred->CredentialBlob), cred->CredentialBlobSize, password_base64)) { *ppEapError = m_module.make_error(dwResult = GetLastError(), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" CredUnprotect failed."), NULL); return dwResult; } diff --git a/lib/TLS/src/Credentials.cpp b/lib/TLS/src/Credentials.cpp index 1c627c8..f997764 100644 --- a/lib/TLS/src/Credentials.cpp +++ b/lib/TLS/src/Credentials.cpp @@ -104,21 +104,21 @@ DWORD eap::credentials_tls::store(_In_ LPCTSTR pszTargetName, _Out_ EAP_ERROR ** tstring target(target_name(pszTargetName)); // Write credentials. - assert(m_cert_hash.size()*sizeof(char) < CRED_MAX_CREDENTIAL_BLOB_SIZE); - assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH ); + assert(m_cert_hash.size() < CRED_MAX_CREDENTIAL_BLOB_SIZE); + assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH ); CREDENTIAL cred = { - 0, // Flags - CRED_TYPE_GENERIC, // Type - (LPTSTR)target.c_str(), // TargetName - _T(""), // Comment - { 0, 0 }, // LastWritten - (DWORD)m_cert_hash.size()*sizeof(char), // CredentialBlobSize - (LPBYTE)m_cert_hash.data(), // CredentialBlob - CRED_PERSIST_ENTERPRISE, // Persist - 0, // AttributeCount - NULL, // Attributes - NULL, // TargetAlias - (LPTSTR)m_identity.c_str() // UserName + 0, // Flags + CRED_TYPE_GENERIC, // Type + (LPTSTR)target.c_str(), // TargetName + _T(""), // Comment + { 0, 0 }, // LastWritten + (DWORD)m_cert_hash.size(), // CredentialBlobSize + (LPBYTE)m_cert_hash.data(), // CredentialBlob + CRED_PERSIST_ENTERPRISE, // Persist + 0, // AttributeCount + NULL, // Attributes + NULL, // TargetAlias + (LPTSTR)m_identity.c_str() // UserName }; if (!CredWrite(&cred, 0)) { *ppEapError = m_module.make_error(dwResult = GetLastError(), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" CredWrite failed."), NULL);