#ifndef AUTH_H #define AUTH_H #include #include "crypto/DES.h" #define TYPE_NOTHING 0 // 无 #define TYPE_ELECTRIC 1 // 电动的 #define TYPE_CHARGED 2 // 充电的 #define TYPE_HYDRAULIC 4 // 液压的 #define TYPE_PNEUMATIC 8 // 气动的 class Auth { public: static Auth *GetInstance() { if(!m_pInstance) { m_mutex.lock(); if(!m_pInstance) { m_pInstance = new Auth(); } m_mutex.unlock(); } return m_pInstance; } Auth(const Auth&) = delete; // 拷贝构造 Auth& operator=(const Auth&) = delete; // 赋值构造 bool getIsEncrypt() { return m_isEncrypt; } // 是否加密文件,目前仅支持加密文件 void setIsEncrypt(bool isEncrypt) { m_isEncrypt = isEncrypt; } unsigned char getEncryptFlag() { return m_encryptFlag; } void setEncryptFlag(unsigned char encryptFlag) { m_encryptFlag = encryptFlag; } std::string getCompanyName() { return m_companyName; } void setComanyName(std::string companyName) { m_companyName = companyName; } unsigned char getProductType() { return m_productType; } void setProductType(unsigned char productType) { m_productType = productType; } std::string getDate() { return m_date; } void setDate(std::string date) { m_date = date; } std::string getPublishDate() { return m_publishDate; } void setPublishDate(std::string date) { m_publishDate = date; } bool getTimesFlag() { return m_bTimesFlag; } void setTimesFlag(bool timesFlag) { m_bTimesFlag = timesFlag; } int getTimes() { return m_times; } void setTimes(int times) { m_times = times; } std::string getAdvancePwd() { return m_advancePwd; } void setAdvancePwd(std::string advancePwd) { m_advancePwd = advancePwd; } bool writeFile(); bool readFile(); std::string getOriginString(); std::string toMessage(); bool checkEncryptFlag(); bool checkProductType(); bool checkDate(); bool checkTimes(); bool checkAdvancePwd(); bool bIsValidate(); private: Auth(); ~Auth(); private: static Auth *m_pInstance; static std::mutex m_mutex; private: bool m_isEncrypt; // 加密标记 unsigned char m_encryptFlag; // 加密标记字节 std::string m_companyName; // 公司名称 unsigned char m_productType; // 产品类型,0-无,其余根据组合计算 std::string m_publishDate; // 发布日期 std::string m_date; // 日期 bool m_bTimesFlag; // 次数使用标记 int m_times; // 次数 std::string m_advancePwd; // 高级设置密码 DES m_des; std::string m_cfgFileName; std::string m_desKey; std::string m_hexDesKey; private: // 垃圾回收类,它的唯一工作就是在析构函数中删除 Auth 的实例 class Garbo { public: ~Garbo() { if (Auth::m_pInstance) { // 销毁设备管理单例实例 delete Auth::m_pInstance; } } }; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数 static Garbo m_Garbo; }; #endif // AUTH_H