Commits

Andreas Tscharner committed 63737aa

Complete encryption: Add option -e

* Add option -e for encrypting the whole file
- Check for it
- Add new option also in usage
* InFileParser: Move eval_encryption_type from protected to public scope and
make it static
* Evaluate encryption type with piblic static method in InFileParser

  • Participants
  • Parent commits 9f791ab

Comments (0)

Files changed (3)

src/compiler/InFileParser.cxx

 #include "InFileParser.hxx"
 
 
-lrc::EncryptionType InFileParser::eval_encryption_type(const char * p_encStr)
-{
-	DEBUG_PRINT(("Evaluating encryption string: %s\n", p_encStr))
-
-	if (strcmp("None", p_encStr) == 0) {
-		return lrc::NoneEncryption;
-	};
-
-	if (strcmp("Serpent", p_encStr) == 0) {
-		return lrc::SerpentEncryption;
-	};
-
-	return lrc::NoneEncryption;
-}
-
 unsigned char *InFileParser::get_password(const char *p_passwdStr) throw(lrcFileNotFoundException)
 {
 	char *pwdFilename;
 	return lrc::NoneCompression;
 }
 
+lrc::EncryptionType InFileParser::eval_encryption_type(const char * p_encStr)
+{
+	DEBUG_PRINT(("Evaluating encryption string: %s\n", p_encStr))
+
+	if (strcmp("None", p_encStr) == 0) {
+		return lrc::NoneEncryption;
+	};
+
+	if (strcmp("Serpent", p_encStr) == 0) {
+		return lrc::SerpentEncryption;
+	};
+
+	return lrc::NoneEncryption;
+}
+
 int InFileParser::get_internal_error(inFilePosition &p_errPos, char **errMsg)
 {
 	const int MAX_ERRMSG_LEN = 512;

src/compiler/InFileParser.hxx

  * input file for the Linux Resource Compiler
  *
  * \author Andreas Tscharner
- * \date 2012-03-23
+ * \date 2012-05-06
  */
 
 
 		int m_lastError;                              //!< Error code of last error
 		internalErrorType m_internalError;            //!< Internal error
 
-		/*! \brief Evaluate encryption type from string
-		 *
-		 * This method evaluated which encryption type should be used
-		 * defined by the given string
-		 *
-		 * \param[in] p_encStr Encryption type as string
-		 *
-		 * \retval lrc::NoneEncryption No encryption
-		 * \retavl lrc::SerpentEncryption Serpent encryption
-		 *
-		 * \remarks lrc::NoneEncryption is the default if the ginve string
-		 *          defines no other encryption type
-		 */
-		lrc::EncryptionType eval_encryption_type(const char *);
-
 		/*! \brief Get password
 		 *
 		 * This method gets the password, either directly from the .rc or
 		 *          defines no other compression type
 		 */
 		static lrc::CompressionType eval_compression_type(const char *);
+		/*! \brief Evaluate encryption type from string
+		 *
+		 * This method evaluated which encryption type should be used
+		 * defined by the given string
+		 *
+		 * \param[in] p_encStr Encryption type as string
+		 *
+		 * \retval lrc::NoneEncryption No encryption
+		 * \retavl lrc::SerpentEncryption Serpent encryption
+		 *
+		 * \remarks lrc::NoneEncryption is the default if the ginve string
+		 *          defines no other encryption type
+		 */
+		static lrc::EncryptionType eval_encryption_type(const char *);
 
 		/*! \brief Parses the file
 		 *

src/compiler/lrc.cxx

  * and then the collector which creates the .rdf file
  *
  * \author Andreas Tscharner
- * \date 2012-03-25
+ * \date 2012-05-06
  */
 
 
 #include <iostream>
 #include <cstring>
 #include "include/CompressDecompress.hxx"
+#include "include/EncryptDecrypt.hxx"
 #include "../lrcExceptions.hxx"
 #include "../Utils.hxx"
 #include "InFileParser.hxx"
 {
 	std::cout << "lrc - Linux Resource Compiler\n";
 	std::cout << "A resource compiler for Linux (Version " << VERSION << ")\n\n";
-	std::cout << "Usage:\n" << argv[0] << " [-d] [-o <rdfFile>] [-c <compression type>] <RCFile>\n";
+	std::cout << "Usage:\n" << argv[0] << " [-d] [-o <rdfFile>] [-c <compression type>] [-e <encryption type>] <RCFile>\n";
 	std::cout << "\t-h\t\t\tShow this help screen\n";
 	std::cout << "\t-d\t\t\tDeny overwriting (optional)\n";
 	std::cout << "\t-o <rdfFile>\t\tDefine final resource data file (optional)\n";
 	std::cout << "\t-c <compression type>\tDefine compression type for the whole file\n";
+	std::cout << "\t-e <encryption type>\tDefine encryption type for the whole file\n";
 	std::cout << "\t<RCFile>\t\tInput file in RC format (mandatory)\n";
 }
 
 	char *inputFile = nullptr;
 	char *rdfFile = nullptr;
 	char *compressType = nullptr;
+	char *encryptType = nullptr;
 	bool allowOverwrite = true;
 	lrc::CompressionType complCompress = lrc::NoneCompression;
+	lrc::EncryptionType complEncrypt = lrc::NoneEncryption;
 
 
 	if (argc < 2) {
 		return -1;
 	};
 
-	while ((optRet = getopt(argc, argv, "dho:c:")) != -1) {
+	while ((optRet = getopt(argc, argv, "dho:c:e:")) != -1) {
 		switch (optRet) {
 			case 'o' :
 				rdfFile = new char[strlen(optarg)+1];
 				strncpy(compressType, optarg, (strlen(optarg)));
 				break;
 
+			case 'e' :
+				encryptType = new char[strlen(optarg)+1];
+				memset(encryptType, 0, (strlen(optarg)+1));
+				strncpy(encryptType, optarg, (strlen(optarg)));
+				break;
+
 			case 'd' :
 				allowOverwrite = false;
 				break;
 		complCompress = InFileParser::eval_compression_type(compressType);
 	};
 
+	if (encryptType) {
+		if (strlen(encryptType) == 0) {
+			std::cout << "An encryption type must be defined with option -e\n";
+			return -1;
+		};
+		complEncrypt = InFileParser::eval_encryption_type(encryptType);
+	};
+
 	inputFile = new char[strlen(argv[optind])+1];
 	strncpy(inputFile, argv[optind], (strlen(argv[optind])));