From 1e166c13aaabe8d2aad1d604c77020a14dc577cd Mon Sep 17 00:00:00 2001
From: open-license-manager <rillf@maildrop.cc>
Date: 周二, 16 9月 2014 06:22:21 +0800
Subject: [PATCH] refactorings

---
 src/scratch/bootstrap_linux.cpp                   |    0 
 src/library/os/linux/os-linux.cpp                 |    6 +
 src/tools/license-generator/license-generator.cpp |   48 +++++------
 test/functional/generate-license.cpp              |    2 
 CMakeLists.txt                                    |    2 
 test/functional/standard-license_test.cpp         |    2 
 test/license-generator/license-generator_test.cpp |    2 
 src/tools/license-generator/license-generator.h   |    2 
 src/scratch/LicenseSigner_linux.cpp               |    0 
 test/functional/date_test.cpp                     |    2 
 src/library/base/EventRegistry.cpp                |    2 
 src/library/os/linux/os-linux.c                   |    4 
 src/tools/base_lib/linux/CryptoHelperLinux.h      |    2 
 src/scratch/win/LicenseSigner.cpp                 |    0 
 test/functional/volid_test.cpp                    |    2 
 src/tools/license-generator/CMakeLists.txt        |    3 
 src/tools/bootstrap/CMakeLists.txt                |   10 +-
 /dev/null                                         |   34 --------
 .cproject                                         |   18 ++++
 src/tools/base_lib/linux/CryptoHelperLinux.cpp    |   42 +++++----
 src/library/LicenseReader.cpp                     |    2 
 src/tools/base_lib/win/CryptoHelperWindows.h      |    8 ++
 src/tools/base_lib/CryptoHelper.h                 |    2 
 test/library/Os_Linux_test.cpp                    |    6 
 src/tools/bootstrap/bootstrap.cpp                 |    8 +-
 25 files changed, 102 insertions(+), 107 deletions(-)

diff --git a/.cproject b/.cproject
index 4fa2f95..3eafb3a 100644
--- a/.cproject
+++ b/.cproject
@@ -48,8 +48,24 @@
 							</tool>
 						</toolChain>
 					</folderInfo>
+					<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1941555127.1870622802" name="/" resourcePath="src">
+						<toolChain id="cdt.managedbuild.toolchain.gnu.base.1412322516" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base" unusedChildren="">
+							<tool id="cdt.managedbuild.tool.gnu.archiver.base.924146927" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base.1063978701"/>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.455275272" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732">
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.743382935" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1499862118" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base.589770174">
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.16209603" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1934467411" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base.1466986479"/>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.263030776" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base.233385682"/>
+							<tool id="cdt.managedbuild.tool.gnu.assembler.base.1495429968" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base.1674253564">
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1348112222" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+							</tool>
+						</toolChain>
+					</folderInfo>
 					<sourceEntries>
-						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
+						<entry excluding="**/win/**" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
 						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="test"/>
 					</sourceEntries>
 				</configuration>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ae9dad4..39ca96d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,7 +12,7 @@
 SET(LICENSECC_VERSION "${LICENSECC_MAJOR_VERSION}.${LICENSECC_MINOR_VERSION}.${LICENSECC_PATCH_VERSION}")
 SET(LICENSECC_SHORT_LICENSE "BSD Software License")
 
-SET(CMAKE_DISABLE_SOURCE_CHANGES OFF)
+SET(CMAKE_DISABLE_SOURCE_CHANGES ON)
 SET(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
 SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "CMake verbose" FORCE)
 
diff --git a/src/library/LicenseReader.cpp b/src/library/LicenseReader.cpp
index 3f49c19..ab50379 100644
--- a/src/library/LicenseReader.cpp
+++ b/src/library/LicenseReader.cpp
@@ -21,7 +21,7 @@
 #include "pc-identifiers.h"
 #include "LicenseReader.h"
 #include "base/StringUtils.h"
-#include "base/public-key.h"
+#include "public-key.h"
 #include <build_properties.h>
 
 #include "os/os-cpp.h"
diff --git a/src/library/base/EventRegistry.cpp b/src/library/base/EventRegistry.cpp
index f24275f..3119afa 100644
--- a/src/library/base/EventRegistry.cpp
+++ b/src/library/base/EventRegistry.cpp
@@ -79,7 +79,7 @@
 }
 
 void EventRegistry::addError(EVENT_TYPE event) {
-	addEvent(event, SVRT_ERROR);
+	this->addEvent(event, SVRT_ERROR);
 }
 
 void EventRegistry::addEvent(EVENT_TYPE event, SEVERITY severity) {
diff --git a/src/library/os/linux/os-linux.c b/src/library/os/linux/os-linux.c
index c394891..2373985 100644
--- a/src/library/os/linux/os-linux.c
+++ b/src/library/os/linux/os-linux.c
@@ -1,4 +1,6 @@
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE     /* To get defns of NI_MAXSERV and NI_MAXHOST */
+#endif
 #include <arpa/inet.h>
 #include <sys/socket.h>
 #include <netdb.h>
@@ -20,7 +22,7 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include "../os.h"
-#include "../../base/public-key.h"
+#include "public-key.h"
 
 #include <openssl/evp.h>
 #include <openssl/bio.h>
diff --git a/src/library/os/linux/os-linux.cpp b/src/library/os/linux/os-linux.cpp
index ed3427b..1f65304 100644
--- a/src/library/os/linux/os-linux.cpp
+++ b/src/library/os/linux/os-linux.cpp
@@ -1,4 +1,6 @@
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE     /* To get defns of NI_MAXSERV and NI_MAXHOST */
+#endif
 #include <arpa/inet.h>
 #include <sys/socket.h>
 #include <netdb.h>
@@ -21,7 +23,7 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include "../os-cpp.h"
-#include "../../base/public-key.h"
+#include "public-key.h"
 
 #include <openssl/evp.h>
 #include <openssl/bio.h>
@@ -57,7 +59,7 @@
 		const char* signatureB64) {
 	EVP_MD_CTX *mdctx = NULL;
 
-	char *pubKey = PUBLIC_KEY;
+	const char *pubKey = PUBLIC_KEY;
 
 	BIO* bio = BIO_new_mem_buf((void*) (pubKey), strlen(pubKey));
 	RSA *rsa = PEM_read_bio_RSAPublicKey(bio, NULL, NULL, NULL);
diff --git a/src/tools/license-generator/linux/LicenseSigner.cpp b/src/scratch/LicenseSigner_linux.cpp
similarity index 100%
rename from src/tools/license-generator/linux/LicenseSigner.cpp
rename to src/scratch/LicenseSigner_linux.cpp
diff --git a/src/tools/bootstrap/bootstrap_linux.cpp b/src/scratch/bootstrap_linux.cpp
similarity index 100%
rename from src/tools/bootstrap/bootstrap_linux.cpp
rename to src/scratch/bootstrap_linux.cpp
diff --git a/src/tools/license-generator/win/LicenseSigner.cpp b/src/scratch/win/LicenseSigner.cpp
similarity index 100%
rename from src/tools/license-generator/win/LicenseSigner.cpp
rename to src/scratch/win/LicenseSigner.cpp
diff --git a/src/tools/base_lib/CryptoHelper.h b/src/tools/base_lib/CryptoHelper.h
index cce02cc..545c6ab 100644
--- a/src/tools/base_lib/CryptoHelper.h
+++ b/src/tools/base_lib/CryptoHelper.h
@@ -27,7 +27,7 @@
 	virtual const string exportPrivateKey() const = 0;
 	virtual const string exportPublicKey() const = 0;
 
-	virtual const string signString(const unsigned char* privateKey,
+	virtual const string signString(const void* privateKey,
 			size_t pklen, const string& license) const = 0;
 	static unique_ptr<CryptoHelper> getInstance();
 	virtual ~CryptoHelper();
diff --git a/src/tools/base_lib/linux/CryptoHelperLinux.cpp b/src/tools/base_lib/linux/CryptoHelperLinux.cpp
index ba094f5..d65ac77 100644
--- a/src/tools/base_lib/linux/CryptoHelperLinux.cpp
+++ b/src/tools/base_lib/linux/CryptoHelperLinux.cpp
@@ -10,6 +10,7 @@
 #include <openssl/bio.h>
 #include <openssl/pem.h>
 #include <openssl/err.h>
+#include <openssl/rsa.h>
 #include <stdexcept>
 #include <string>
 #include <cstddef>
@@ -28,7 +29,6 @@
 	return subject;
 }
 
-
 CryptoHelperLinux::CryptoHelperLinux() {
 	static int initialized = 0;
 	rsa = NULL;
@@ -41,22 +41,22 @@
 
 }
 void CryptoHelperLinux::generateKeyPair() {
-	srand(time(NULL)); /* seed random number generator */
-	int random = rand();
 	rsa = RSA_generate_key(kBits, kExp, 0, 0);
 }
 
 const string CryptoHelperLinux::exportPrivateKey() const {
 	if (rsa == NULL) {
-		throw logic_error(string("Export not initialized.Call generateKeyPair first."));
+		throw logic_error(
+				string("Export not initialized.Call generateKeyPair first."));
 	}
 	BIO* bio_private = BIO_new(BIO_s_mem());
 	PEM_write_bio_RSAPrivateKey(bio_private, rsa, NULL, NULL, 0, NULL, NULL);
 	int keylen = BIO_pending(bio_private);
 	char* pem_key = (char*) (calloc(keylen + 1, 1)); /* Null-terminate */
 	BIO_read(bio_private, pem_key, keylen);
-	string dest = replaceAll(string(pem_key), string("\n"),
-			string("\\n\" \\\n\""));
+	string dest = string("\"")
+			+ replaceAll(string(pem_key), string("\n"), string("\\n\" \\\n\""))
+			+ string("\"");
 	BIO_free_all(bio_private);
 	free(pem_key);
 	return dest;
@@ -64,22 +64,24 @@
 
 const string CryptoHelperLinux::exportPublicKey() const {
 	if (rsa == NULL) {
-		throw logic_error(string("Export not initialized.Call generateKeyPair first."));
+		throw logic_error(
+				string("Export not initialized.Call generateKeyPair first."));
 	}
-	BIO* bio_private = BIO_new(BIO_s_mem());
-	PEM_write_bio_RSAPrivateKey(bio_private, rsa, NULL, NULL, 0, NULL, NULL);
-	int keylen = BIO_pending(bio_private);
+	BIO* bio_public = BIO_new(BIO_s_mem());
+	PEM_write_bio_RSAPublicKey(bio_public, rsa);
+	int keylen = BIO_pending(bio_public);
 	char* pem_key = (char*) (calloc(keylen + 1, 1)); /* Null-terminate */
-	BIO_read(bio_private, pem_key, keylen);
-	std::string dest = replaceAll(string(pem_key), string("\n"),
-			string("\\n\" \\\n\""));
-	BIO_free_all(bio_private);
+	BIO_read(bio_public, pem_key, keylen);
+	std::string dest = string("\"")
+			+ replaceAll(string(pem_key), string("\n"), string("\\n\" \\\n\""))
+			+ string("\"");
+	BIO_free_all(bio_public);
 	free(pem_key);
 	return dest;
 }
 
-string CryptoHelperLinux::signString(const unsigned char* privateKey, size_t pklen,
-		const string& license) const {
+string CryptoHelperLinux::signString(const void* privateKey,
+		size_t pklen, const string& license) const {
 	size_t slen;
 	unsigned char* signature;
 	signature = NULL;
@@ -88,7 +90,6 @@
 	if (!mdctx) {
 		throw logic_error("Message digest creation context");
 	}
-
 
 	BIO* bio = BIO_new_mem_buf((void*) (privateKey), pklen);
 	EVP_PKEY *pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
@@ -99,7 +100,9 @@
 		EVP_MD_CTX_destroy(mdctx);
 	}
 	/* Call update with the message */
-	if (EVP_DigestSignUpdate(mdctx, (const void*) license.c_str(), (size_t) license.length()) != 1) {
+	if (EVP_DigestSignUpdate(mdctx, (const void* ) license.c_str(),
+			(size_t ) license.length())
+			!= 1) {
 		EVP_MD_CTX_destroy(mdctx);
 		throw logic_error("Message signing exception");
 	}
@@ -164,7 +167,8 @@
 	return signatureStr;
 }
 
-const string CryptoHelperLinux::Opensslb64Encode(size_t slen, unsigned char* signature) const{
+const string CryptoHelperLinux::Opensslb64Encode(size_t slen,
+		unsigned char* signature) const {
 	/*
 	 FILE*  stream = fmemopen(*buffer, encodedSize+1, "w");
 	 */
diff --git a/src/tools/base_lib/linux/CryptoHelperLinux.h b/src/tools/base_lib/linux/CryptoHelperLinux.h
index 2573ca3..534b1e3 100644
--- a/src/tools/base_lib/linux/CryptoHelperLinux.h
+++ b/src/tools/base_lib/linux/CryptoHelperLinux.h
@@ -27,7 +27,7 @@
 	virtual const string exportPrivateKey() const;
 	virtual const string exportPublicKey() const;
 
-	virtual string signString(const unsigned char* privateKey, size_t pklen,
+	virtual string signString(const void* privateKey, size_t pklen,
 			const string& license) const;
 	virtual ~CryptoHelperLinux();
 };
diff --git a/src/tools/base_lib/win/CryptoHelperWindows.h b/src/tools/base_lib/win/CryptoHelperWindows.h
index 83ac21c..293f4e9 100644
--- a/src/tools/base_lib/win/CryptoHelperWindows.h
+++ b/src/tools/base_lib/win/CryptoHelperWindows.h
@@ -19,6 +19,14 @@
 class CryptoHelperWindows: public CryptoHelper {
 public:
 	CryptoHelperWindows();
+
+	virtual void generateKeyPair();
+	virtual const string exportPrivateKey() const;
+	virtual const string exportPublicKey() const;
+
+	virtual string signString(const void* privateKey, size_t pklen,
+			const string& license) const;
+
 	virtual ~CryptoHelperWindows();
 };
 
diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt
index 8ea8f08..a47eecb 100644
--- a/src/tools/bootstrap/CMakeLists.txt
+++ b/src/tools/bootstrap/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_executable(
  bootstrap
- Main.cpp
+ bootstrap.cpp
 )
 
 
@@ -14,13 +14,13 @@
 
 # add the command to generate the source code
 add_custom_command (
-  OUTPUT "${CMAKE_BINARY_DIR}/src/tools/license-generator/private-key.h" "${CMAKE_BINARY_DIR}/src/library/base/public-key.h"
-  COMMAND bootstrap "${CMAKE_BINARY_DIR}/src/tools/license-generator/private-key.h" "${CMAKE_BINARY_DIR}/src/library/base/public-key.h"
+  OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
+  COMMAND bootstrap "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
   DEPENDS bootstrap
 )
 
-add_custom_target(private_key DEPENDS "${CMAKE_BINARY_DIR}/src/tools/license-generator/private-key.h")
-add_custom_target(public_key DEPENDS "${CMAKE_BINARY_DIR}/src/library/base/public-key.h")
+add_custom_target(private_key DEPENDS "${CMAKE_BINARY_DIR}/private-key.h")
+add_custom_target(public_key DEPENDS "${CMAKE_BINARY_DIR}/public-key.h")
 
 
 # add the command to generate the source code
diff --git a/src/tools/bootstrap/Main.cpp b/src/tools/bootstrap/bootstrap.cpp
similarity index 94%
rename from src/tools/bootstrap/Main.cpp
rename to src/tools/bootstrap/bootstrap.cpp
index d4faa46..6b22d59 100644
--- a/src/tools/bootstrap/Main.cpp
+++ b/src/tools/bootstrap/bootstrap.cpp
@@ -14,9 +14,9 @@
 	}
 	fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n");
 	fprintf(fp, "#ifndef PUBLIC_KEY_H_\n#define PUBLIC_KEY_H_\n");
-	fprintf(fp, "define PUBLIC_KEY { \n");
+	fprintf(fp, "#define PUBLIC_KEY { \\\n");
 	fprintf(fp, "%s", pbPublicKey.c_str());
-	fprintf(fp, "\n};\n\n");
+	fprintf(fp, "}\n\n");
 	int random = rand() % 1000;
 	fprintf(fp, "#define SHARED_RANDOM %d;\n", random);
 	fprintf(fp, "#endif\n");
@@ -30,9 +30,9 @@
 	}
 	fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n");
 	fprintf(fp, "#ifndef PRIVATE_KEY_H_\n#define PRIVATE_KEY_H_\n");
-	fprintf(fp, "define PRIVATE_KEY = {\n");
+	fprintf(fp, "#define PRIVATE_KEY { \\\n");
 	fprintf(fp, "%s", privateKey.c_str());
-	fprintf(fp, "\n};\n\n");
+	fprintf(fp, "}\n\n");
 	fprintf(fp, "#endif\n");
 	fclose(fp);
 }
diff --git a/src/tools/bootstrap/win/CmakeLists.txt b/src/tools/bootstrap/win/CmakeLists.txt
deleted file mode 100644
index a710cb4..0000000
--- a/src/tools/bootstrap/win/CmakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-add_executable(
- bootstrap
- CryptoHelper.cpp
- Main.cpp
-)
\ No newline at end of file
diff --git a/src/tools/license-generator/CMakeLists.txt b/src/tools/license-generator/CMakeLists.txt
index 35199f7..2e25026 100644
--- a/src/tools/license-generator/CMakeLists.txt
+++ b/src/tools/license-generator/CMakeLists.txt
@@ -12,12 +12,11 @@
 target_link_libraries(
      license_generator_lib
      tools_base
+     license++_static
 	 $<$<CONFIG:Debug>:${Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG}>
      $<$<NOT:$<CONFIG:Debug>>:${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE}>	 
 	 $<$<CONFIG:Debug>:${Boost_SYSTEM_LIBRARY_DEBUG}>
      $<$<NOT:$<CONFIG:Debug>>:${Boost_SYSTEM_LIBRARY_RELEASE}>	 
-	 $<$<CONFIG:Debug>:${Boost_DATE_TIME_LIBRARY_DEBUG}>
-     $<$<NOT:$<CONFIG:Debug>>:${Boost_DATE_TIME_LIBRARY_RELEASE}>	 
      ${EXTERNAL_LIBS}
 )
 
diff --git a/src/tools/license-generator/LicenseSigner.h b/src/tools/license-generator/LicenseSigner.h
deleted file mode 100644
index 4c91000..0000000
--- a/src/tools/license-generator/LicenseSigner.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * LicenseSigner.h
- *
- *  Created on: Apr 6, 2014
- *      
- */
-
-#ifndef LICENSESIGNER_H_
-#define LICENSESIGNER_H_
-
-#include "../library/LicenseReader.h"
-
-namespace license {
-
-class LicenseSigner {
-#ifdef __unix__
-	const string privateKey;
-#else
-	HCRYPTPROV hProv;
-	HCRYPTKEY hPubKey;
-#endif
-	string signString(const string& license);
-	string Opensslb64Encode(size_t slen, unsigned char* signature);
-
-public:
-	LicenseSigner();
-	LicenseSigner(const string& alternatePrimaryKey);
-	void signLicense(FullLicenseInfo& licenseInfo);
-	virtual ~LicenseSigner();
-};
-
-} /* namespace license */
-
-#endif /* LICENSESIGNER_H_ */
diff --git a/src/tools/license-generator/license-generator.cpp b/src/tools/license-generator/license-generator.cpp
index 846d5d9..ce456cc 100644
--- a/src/tools/license-generator/license-generator.cpp
+++ b/src/tools/license-generator/license-generator.cpp
@@ -1,7 +1,7 @@
 #include <build_properties.h>
-#include "LicenseSigner.h"
+#include <private-key.h>
 #include "license-generator.h"
-#include "../library/base/StringUtils.h"
+#include "../base_lib/CryptoHelper.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <iostream>
@@ -103,22 +103,20 @@
 		client_signature = vm["client_signature"].as<string>();
 		//fixme match + and /
 		/*regex e("(A-Za-z0-9){4}-(A-Za-z0-9){4}-(A-Za-z0-9){4}-(A-Za-z0-9){4}");
-		if (!regex_match(client_signature, e)) {
-			cerr << endl << "Client signature not recognized: "
-					<< client_signature
-					<< " Please enter a valid signature in format XXXX-XXXX-XXXX-XXXX"
-					<< endl;
-			exit(2);
-		}*/
+		 if (!regex_match(client_signature, e)) {
+		 cerr << endl << "Client signature not recognized: "
+		 << client_signature
+		 << " Please enter a valid signature in format XXXX-XXXX-XXXX-XXXX"
+		 << endl;
+		 exit(2);
+		 }*/
 	}
 	string extra_data = "";
 	if (vm.count("extra_data")) {
 		extra_data = vm["extra_data"].as<string>();
 	}
-	unsigned int from_sw_version = vm["start_version"].as<
-			unsigned int>();
-	unsigned int to_sw_version =
-			vm["end_version"].as<unsigned int>();
+	unsigned int from_sw_version = vm["start_version"].as<unsigned int>();
+	unsigned int to_sw_version = vm["end_version"].as<unsigned int>();
 	if (vm.count("product") == 0) {
 		cerr << endl << "Parameter [product] not found. " << endl;
 		exit(2);
@@ -140,12 +138,13 @@
 void LicenseGenerator::generateAndOutputLicenses(const po::variables_map& vm,
 		ostream& outputFile) {
 	vector<FullLicenseInfo> licenseInfo = parseLicenseInfo(vm);
-	license::LicenseSigner licSigner =
-			vm.count("private_key") == 0 ?
-					license::LicenseSigner() :
-					license::LicenseSigner(vm["private_key"].as<string>());
+	unique_ptr<CryptoHelper> helper = CryptoHelper::getInstance();
+	const char pkey[] = PRIVATE_KEY;
+	size_t len = sizeof(pkey);
 	for (auto it = licenseInfo.begin(); it != licenseInfo.end(); ++it) {
-		licSigner.signLicense(*it);
+		const string license = it->printForSign();
+		string signature = helper->signString((const void *)pkey,len,license);
+		it->license_signature = signature;
 		it->printAsIni(outputFile);
 	}
 }
@@ -188,25 +187,24 @@
 	return 0;
 }
 
-
-const std::string formats[] = { "%4u-%2u-%2u","%4u/%2u/%2u","%4u%2u%2u" };
+const std::string formats[] = { "%4u-%2u-%2u", "%4u/%2u/%2u", "%4u%2u%2u" };
 const size_t formats_n = 3;
 
 string LicenseGenerator::normalize_date(const char * s) {
 	unsigned int year, month, day;
 	int chread;
 	bool found = false;
-	for (size_t i = 0; i < formats_n &&!found; ++i) {
-		chread = sscanf(s, formats[i].c_str(),&year, &month, &day);
-		if (chread == 3){
+	for (size_t i = 0; i < formats_n && !found; ++i) {
+		chread = sscanf(s, formats[i].c_str(), &year, &month, &day);
+		if (chread == 3) {
 			found = true;
 		}
 	}
-	if (!found){
+	if (!found) {
 		throw invalid_argument("Date not recognized.");
 	}
 	ostringstream oss;
-	oss << year << "-"<<setfill('0') << std::setw(2)<< month<<"-"<<day;
+	oss << year << "-" << setfill('0') << std::setw(2) << month << "-" << day;
 	//delete (facet);
 	return oss.str();
 }
diff --git a/src/tools/license-generator/license-generator.h b/src/tools/license-generator/license-generator.h
index 26fe56d..7201aef 100644
--- a/src/tools/license-generator/license-generator.h
+++ b/src/tools/license-generator/license-generator.h
@@ -9,7 +9,7 @@
 #define LICENSE_GENERATOR_H_
 
 #include <boost/program_options.hpp>
-#include "../library/LicenseReader.h"
+#include "../../library/LicenseReader.h"
 
 namespace license {
 
diff --git a/test/functional/date_test.cpp b/test/functional/date_test.cpp
index a522a16..3210a45 100644
--- a/test/functional/date_test.cpp
+++ b/test/functional/date_test.cpp
@@ -2,7 +2,7 @@
 //#define BOOST_TEST_MAIN
 //#define BOOST_TEST_DYN_LINK
 #include <boost/test/unit_test.hpp>
-#include "../../../src/license-generator/license-generator.h"
+#include "../../../src/tools/license-generator/license-generator.h"
 #include "../../../src/library/api/license++.h"
 #include <build_properties.h>
 #include <boost/filesystem.hpp>
diff --git a/test/functional/generate-license.cpp b/test/functional/generate-license.cpp
index 27b2f60..c5c9059 100644
--- a/test/functional/generate-license.cpp
+++ b/test/functional/generate-license.cpp
@@ -6,7 +6,7 @@
  */
 
 #include <boost/test/unit_test.hpp>
-#include "../../../src/license-generator/license-generator.h"
+#include "../../../src/tools/license-generator/license-generator.h"
 #include <build_properties.h>
 #include <boost/filesystem.hpp>
 #include "../../src/library/ini/SimpleIni.h"
diff --git a/test/functional/standard-license_test.cpp b/test/functional/standard-license_test.cpp
index 7c3f58e..ec6ae45 100644
--- a/test/functional/standard-license_test.cpp
+++ b/test/functional/standard-license_test.cpp
@@ -2,7 +2,7 @@
 //#define BOOST_TEST_MAIN
 //#define BOOST_TEST_DYN_LINK
 #include <boost/test/unit_test.hpp>
-#include "../../../src/license-generator/license-generator.h"
+#include "../../../src/tools/license-generator/license-generator.h"
 #include "../../../src/library/api/license++.h"
 #include <build_properties.h>
 #include <boost/filesystem.hpp>
diff --git a/test/functional/volid_test.cpp b/test/functional/volid_test.cpp
index b289af5..d6cff73 100644
--- a/test/functional/volid_test.cpp
+++ b/test/functional/volid_test.cpp
@@ -4,7 +4,7 @@
 #include <boost/test/unit_test.hpp>
 #include <fstream>
 #include <cstring>
-#include "../../../src/license-generator/license-generator.h"
+#include "../../../src/tools/license-generator/license-generator.h"
 #include "../../../src/library/api/license++.h"
 #include <build_properties.h>
 #include <boost/filesystem.hpp>
diff --git a/test/library/Os_Linux_test.cpp b/test/library/Os_Linux_test.cpp
index 01b25ff..bbb0bf6 100644
--- a/test/library/Os_Linux_test.cpp
+++ b/test/library/Os_Linux_test.cpp
@@ -25,13 +25,13 @@
 }
 
 BOOST_AUTO_TEST_CASE( read_network_adapters ) {
-	AdapterInfo * adapter_info = NULL;
+	OsAdapterInfo * adapter_info = NULL;
 	size_t adapter_info_size = 0;
 	FUNCTION_RETURN result = getAdapterInfos(NULL, &adapter_info_size);
 	BOOST_CHECK_EQUAL(result, FUNC_RET_OK);
 	BOOST_CHECK_GT(adapter_info_size, 0);
-	adapter_info = (AdapterInfo*) malloc(
-			sizeof(AdapterInfo) * adapter_info_size);
+	adapter_info = (OsAdapterInfo*) malloc(
+			sizeof(OsAdapterInfo) * adapter_info_size);
 	result = getAdapterInfos(adapter_info, &adapter_info_size);
 	BOOST_CHECK_EQUAL(result, FUNC_RET_OK);
 	for (size_t i = 0; i < adapter_info_size; i++) {
diff --git a/test/license-generator/license-generator_test.cpp b/test/license-generator/license-generator_test.cpp
index 05ce78d..d3b396f 100644
--- a/test/license-generator/license-generator_test.cpp
+++ b/test/license-generator/license-generator_test.cpp
@@ -2,7 +2,7 @@
 //#define BOOST_TEST_MAIN
 //#define BOOST_TEST_DYN_LINK
 #include <boost/test/unit_test.hpp>
-#include "../../../src/license-generator/license-generator.h"
+#include "../../../src/tools/license-generator/license-generator.h"
 #include <build_properties.h>
 #include <boost/filesystem.hpp>
 #include "../../src/library/ini/SimpleIni.h"

--
Gitblit v1.9.1