From 3b1577ab7eb2000a3477a0aa489b888fb1256434 Mon Sep 17 00:00:00 2001
From: lurumdare <8020186+lurumdare@users.noreply.github.com>
Date: 周六, 07 9月 2019 20:40:25 +0800
Subject: [PATCH] const everywhere (#30)

---
 src/tools/base_lib/win/CryptoHelperWindows.cpp |   24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/tools/base_lib/win/CryptoHelperWindows.cpp b/src/tools/base_lib/win/CryptoHelperWindows.cpp
index 8669926..4cdb31d 100644
--- a/src/tools/base_lib/win/CryptoHelperWindows.cpp
+++ b/src/tools/base_lib/win/CryptoHelperWindows.cpp
@@ -62,7 +62,7 @@
 	KEYLENGTH | CRYPT_EXPORTABLE, &m_hCryptKey)) {
 		dwErrCode = GetLastError();
 		throw logic_error(
-				string("Error generating keys ") + to_string(dwErrCode));
+				string("Error generating keys ") + to_string(static_cast<long long>(dwErrCode)));
 	}
 }
 
@@ -86,7 +86,7 @@
 		dwErrCode = GetLastError();
 		throw logic_error(
 				string("Error calculating size of public key ")
-						+ to_string(dwErrCode));
+						+ to_string(static_cast<long long>(dwErrCode)));
 	}
 	// Allocate memory for the pbKeyBlob.
 	if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
@@ -98,7 +98,7 @@
 		delete pbKeyBlob;
 		dwErrCode = GetLastError();
 		throw logic_error(
-				string("Error exporting public key ") + to_string(dwErrCode));
+				string("Error exporting public key ") + to_string(static_cast<long long>(dwErrCode)));
 	} else {
 		ss << "\t";
 		for (unsigned int i = 0; i < dwBlobLen; i++) {
@@ -108,7 +108,7 @@
 					ss << "\\" << endl << "\t";
 				}
 			}
-			ss << to_string(pbKeyBlob[i]);
+			ss << to_string(static_cast<long long>(pbKeyBlob[i]));
 		}
 		delete pbKeyBlob;
 	}
@@ -146,7 +146,7 @@
 		dwErrCode = GetLastError();
 		throw logic_error(
 				string("Error calculating size of private key ")
-						+ to_string(dwErrCode));
+						+ to_string(static_cast<long long>(dwErrCode)));
 	}
 	// Allocate memory for the pbKeyBlob.
 	if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
@@ -159,7 +159,7 @@
 		delete pbKeyBlob;
 		dwErrCode = GetLastError();
 		throw logic_error(
-				string("Error exporting private key ") + to_string(dwErrCode));
+				string("Error exporting private key ") + to_string(static_cast<long long>(dwErrCode)));
 	} else {
 		ss << "\t";
 		for (unsigned int i = 0; i < dwBlobLen; i++) {
@@ -169,7 +169,7 @@
 					ss << "\\" << endl << "\t";
 				}
 			}
-			ss << to_string(pbKeyBlob[i]);
+			ss << to_string(static_cast<long long>(pbKeyBlob[i]));
 		}
 		delete pbKeyBlob;
 	}
@@ -181,7 +181,7 @@
 	DWORD dwHashLen;
 	DWORD dwHashLenSize = sizeof(DWORD);
 	char* hashStr;
-	int i;
+	unsigned int i;
 
 	if (CryptGetHashParam(*hHash, HP_HASHSIZE, (BYTE *) &dwHashLen,
 			&dwHashLenSize, 0)) {
@@ -201,24 +201,22 @@
 const string CryptoHelperWindows::signString(const void* privateKey,
 		size_t pklen, const string& license) const {
 	BYTE *pbBuffer = (BYTE *) license.c_str();
-	DWORD dwBufferLen = strlen((char *) pbBuffer);
+	const DWORD dwBufferLen = (DWORD)strlen((char *)pbBuffer);
 	HCRYPTHASH hHash;
 
 	HCRYPTKEY hKey;
-	BYTE *pbKeyBlob;
 	BYTE *pbSignature;
 	DWORD dwSigLen;
-	DWORD dwBlobLen;
 	DWORD strLen;
 
 	//-------------------------------------------------------------------
 	// Acquire a cryptographic provider context handle.
 
-	if (!CryptImportKey(m_hCryptProv, (const BYTE *) privateKey, pklen, 0, 0,
+	if (!CryptImportKey(m_hCryptProv, (const BYTE *) privateKey, (DWORD) pklen, 0, 0,
 			&hKey)) {
 		throw logic_error(
 				string("Error in importing the PrivateKey ")
-						+ to_string(GetLastError()));
+						+ to_string(static_cast<long long>(GetLastError())));
 	}
 
 	//-------------------------------------------------------------------

--
Gitblit v1.9.1