Redundant sizeof(char) removed for code clarity

This commit is contained in:
Simon Rozman 2016-06-15 10:52:23 +02:00
parent 8bff2d3060
commit e0460fa15b
3 changed files with 31 additions and 31 deletions

View File

@ -251,7 +251,7 @@ namespace eapserial
template<class _Traits, class _Ax> template<class _Traits, class _Ax>
inline size_t get_pk_size(const std::basic_string<wchar_t, _Traits, _Ax> &val) inline size_t get_pk_size(const std::basic_string<wchar_t, _Traits, _Ax> &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);
} }

View File

@ -238,7 +238,7 @@ DWORD eap::credentials_pass::store(_In_ LPCTSTR pszTargetName, _Out_ EAP_ERROR *
// Encrypt password. // Encrypt password.
vector<unsigned char> password; vector<unsigned char> 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; return dwResult;
// Calculate MD5 hash and append it. // 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)); tstring target(target_name(pszTargetName));
// Write credentials. // Write credentials.
assert(password_enc.size()*sizeof(char) < CRED_MAX_CREDENTIAL_BLOB_SIZE); assert(password_enc.size() < CRED_MAX_CREDENTIAL_BLOB_SIZE);
assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH ); assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH );
CREDENTIAL cred = { CREDENTIAL cred = {
0, // Flags 0, // Flags
CRED_TYPE_GENERIC, // Type CRED_TYPE_GENERIC, // Type
(LPTSTR)target.c_str(), // TargetName (LPTSTR)target.c_str(), // TargetName
_T(""), // Comment _T(""), // Comment
{ 0, 0 }, // LastWritten { 0, 0 }, // LastWritten
(DWORD)password_enc.size()*sizeof(char), // CredentialBlobSize (DWORD)password_enc.size(), // CredentialBlobSize
(LPBYTE)password_enc.data(), // CredentialBlob (LPBYTE)password_enc.data(),// CredentialBlob
CRED_PERSIST_ENTERPRISE, // Persist CRED_PERSIST_ENTERPRISE, // Persist
0, // AttributeCount 0, // AttributeCount
NULL, // Attributes NULL, // Attributes
NULL, // TargetAlias NULL, // TargetAlias
(LPTSTR)m_identity.c_str() // UserName (LPTSTR)m_identity.c_str() // UserName
}; };
if (!CredWrite(&cred, 0)) { if (!CredWrite(&cred, 0)) {
*ppEapError = m_module.make_error(dwResult = GetLastError(), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" CredWrite failed."), NULL); *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. // Decrypt the password using user's key.
string password_base64; 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); *ppEapError = m_module.make_error(dwResult = GetLastError(), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" CredUnprotect failed."), NULL);
return dwResult; return dwResult;
} }

View File

@ -104,21 +104,21 @@ DWORD eap::credentials_tls::store(_In_ LPCTSTR pszTargetName, _Out_ EAP_ERROR **
tstring target(target_name(pszTargetName)); tstring target(target_name(pszTargetName));
// Write credentials. // Write credentials.
assert(m_cert_hash.size()*sizeof(char) < CRED_MAX_CREDENTIAL_BLOB_SIZE); assert(m_cert_hash.size() < CRED_MAX_CREDENTIAL_BLOB_SIZE);
assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH ); assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH );
CREDENTIAL cred = { CREDENTIAL cred = {
0, // Flags 0, // Flags
CRED_TYPE_GENERIC, // Type CRED_TYPE_GENERIC, // Type
(LPTSTR)target.c_str(), // TargetName (LPTSTR)target.c_str(), // TargetName
_T(""), // Comment _T(""), // Comment
{ 0, 0 }, // LastWritten { 0, 0 }, // LastWritten
(DWORD)m_cert_hash.size()*sizeof(char), // CredentialBlobSize (DWORD)m_cert_hash.size(), // CredentialBlobSize
(LPBYTE)m_cert_hash.data(), // CredentialBlob (LPBYTE)m_cert_hash.data(), // CredentialBlob
CRED_PERSIST_ENTERPRISE, // Persist CRED_PERSIST_ENTERPRISE, // Persist
0, // AttributeCount 0, // AttributeCount
NULL, // Attributes NULL, // Attributes
NULL, // TargetAlias NULL, // TargetAlias
(LPTSTR)m_identity.c_str() // UserName (LPTSTR)m_identity.c_str() // UserName
}; };
if (!CredWrite(&cred, 0)) { if (!CredWrite(&cred, 0)) {
*ppEapError = m_module.make_error(dwResult = GetLastError(), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" CredWrite failed."), NULL); *ppEapError = m_module.make_error(dwResult = GetLastError(), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" CredWrite failed."), NULL);