Commit 0036857c58a17351a96ddbd4832e90a005e2e75b
Exists in
master
implementação dos metodos de criptografia
Showing
4 changed files
with
114 additions
and
28 deletions
Show diff stats
cacic-teste/testcacic.cpp
... | ... | @@ -14,8 +14,8 @@ CTestCacic::CTestCacic(QObject *parent) : |
14 | 14 | "1", |
15 | 15 | "0", |
16 | 16 | "0", |
17 | - "YwpgjzZ86/eCsjvOki1KkQ==__CRYPTED__", | |
18 | - "8PT6U445MPNr3S7WHFa20ge/8NJSspSYE/UL3zf[[MAIS]]wkEfNZ7p1B/2o6i89gTZ44Ok__CRYPTED__", | |
17 | + /*QDir::currentPath(), */"YwpgjzZ86/eCsjvOki1KkQ==__CRYPTED__", | |
18 | + /*QTest::currentAppName(), */"8PT6U445MPNr3S7WHFa20ge/8NJSspSYE/UL3zf[[MAIS]]wkEfNZ7p1B/2o6i89gTZ44Ok__CRYPTED__", | |
19 | 19 | "wshPlZWvLPhbUEQFQ1aQmA==__CRYPTED__", |
20 | 20 | "E9aKtVz/OSmGv7v1xW4FwaFukOob3qQ/HFDIz916K3ys82qfX9vBDz[[MAIS]]M2cdoYedhNkXt[[MAIS]]UVb10nD[[MAIS]]tOfbn7mlOlTDoGzUl9CgdPCsb[[MAIS]]Qa4wzuCrMw0BcCuaKfr62E3b8vh6Ug4JJbOgBo3ohG3x5O7Ap0D94GKtAWjMuTXRBbhGxPrRS4M6AhzvaN5P8pWd9FikrCLWuMs4ebnRlftef3RmVKScBDQ5zmK6sKxYNmX[[MAIS]]kKn/Gi2[[MAIS]]HftZ7HD9JLvZBpYhp4yjqShblQ67d6PlWgrRWXxwDseIiJe3NlF70zrCPBBelkeAhVDXMXnsYtLms3ElsLzxa3c5vpWzTfgyE[[MAIS]]hvALy4ivew7zaxEwrg2KY1T7GOSWZ7vljIvbhVZJgtzbnYiulFjJTtm5W4uJMKLuUJNzB0rxMkzToIE9/kDmeO2OKiwFbIfbe2Wdq0VpllOkjKtj9WM676iBSpYAXG0MsmLMj9CZ/sNi06hGF[[MAIS]]rXxiOSk66M0Hq[[MAIS]]OeUBh4z3Ra6f9yPJn0K9hIQyT[[MAIS]]Dr/QW/QdJIOkLTW8ZyyAF4DW9ojiTlUdySvB5EB1jyZ5nNTpzyE38qIdg7uM1tdWdm9FZGYxMdHwi1tS2dBeIWkDfWEjih01xiVt2dmdRgo0zIZvmmYDJ9LhCU3XPDlwdeQ8[[MAIS]]F7fnxDfxGqZQjZJ[[MAIS]]Y/Q8bdLpgbhcd3gt3SzjMLE0M[[MAIS]]hTmHG1KP2CzCibZ7grFAN3Y3jSPjmEj5Fzs26tdhdjNzSIt1FCueea8P2c4NmxPYkJCg0D1mgNrkH3L5svsO[[MAIS]]6YYrl3df4s[[MAIS]]fcK/to9s/pnkKfBKrAPF6Z4s2WPsALUPBDS5ty7RC2vqXRvH6hPR4o7xhXzQOQ/1xytr/RoEWEVeZ2wgHVVbbtFsALul/IDc7B45wmwxBx9iZHVwpQJVlNZZUBtwKqKhnXz5pM[[MAIS]]7yUAkfhMcO09pPd5kB2MBdRJs[[MAIS]]2FIk0GRUw05IHkc1rZEX5Ow==__CRYPTED__", |
21 | 21 | "Yot8BeM9lOh431SB7dYQXw==__CRYPTED__", |
... | ... | @@ -23,8 +23,26 @@ CTestCacic::CTestCacic(QObject *parent) : |
23 | 23 | "2.5.1.1.256.32", |
24 | 24 | "2.8.1.7", |
25 | 25 | "2.8.1.6"); |
26 | + testPath = QDir::currentPath() + "/teste"; | |
27 | + testIniPath = testPath + "/teste.ini"; | |
26 | 28 | } |
27 | 29 | |
30 | +void CTestCacic::testCreateFolder() | |
31 | +{ | |
32 | + QVERIFY(OCacic.createFolder(testPath)); | |
33 | +} | |
34 | + | |
35 | +void CTestCacic::testGetAndSetValueFromFile() | |
36 | +{ | |
37 | + OCacic.setValueToFile("Teste", "teste", "Valor de teste", testIniPath); | |
38 | + QVERIFY( OCacic.getValueFromFile("Teste", "teste", testIniPath) == "Valor de teste"); | |
39 | +} | |
40 | + | |
41 | +void CTestCacic::testGetValueFromTags() | |
42 | +{ | |
43 | + QString value = "blablab[teste]Valor de teste[/teste]feihgj"; | |
44 | + QVERIFY(OCacic.getValueFromTags(value, "teste") == "Valor de teste"); | |
45 | +} | |
28 | 46 | |
29 | 47 | void CTestCacic::testCommStatus() |
30 | 48 | { |
... | ... | @@ -33,23 +51,20 @@ void CTestCacic::testCommStatus() |
33 | 51 | |
34 | 52 | void CTestCacic::testComm() |
35 | 53 | { |
36 | - if (OCacicComm.commStatus()) | |
37 | - QVERIFY(OCacicComm.comm("/ws/get/test") != QString("")); | |
38 | - else | |
54 | + if (OCacicComm.commStatus()){ | |
55 | + QVERIFY(OCacic.getValueFromTags(OCacicComm.comm("/ws/get/test"), "Comm_Status", "<>") == QString("OK")); | |
56 | + } else | |
39 | 57 | QSKIP("Teste de comunicação negativo!"); |
40 | 58 | } |
41 | 59 | |
42 | -void CTestCacic::testGetValueFromFile() | |
60 | +void CTestCacic::testDeleteFile() | |
43 | 61 | { |
44 | - QVERIFY( OCacic.getValueFromFile("Teste", "teste","E:/teste.txt") == "Valor de teste"); | |
62 | + QVERIFY(OCacic.deleteFile(testIniPath)); | |
45 | 63 | } |
46 | 64 | |
47 | -void CTestCacic::testGetValueFromTags() | |
65 | +void CTestCacic::testDeleteFolder() | |
48 | 66 | { |
49 | - QString value = "blablab[teste]Valor de teste[/teste]feihgj"; | |
50 | - QString retorno = OCacic.getValueFromTags(value, "teste"); | |
51 | - qDebug(retorno.toLocal8Bit()); | |
52 | - QVERIFY(retorno == "Valor de teste"); | |
67 | + QVERIFY(OCacic.deleteFolder(testPath)); | |
53 | 68 | } |
54 | 69 | |
55 | 70 | void CTestCacic::testEnCrypt(){ | ... | ... |
cacic-teste/testcacic.h
... | ... | @@ -14,6 +14,8 @@ public: |
14 | 14 | private: |
15 | 15 | CacicComm OCacicComm; |
16 | 16 | CCacic OCacic; |
17 | + QString testPath; | |
18 | + QString testIniPath; | |
17 | 19 | |
18 | 20 | signals: |
19 | 21 | |
... | ... | @@ -22,10 +24,13 @@ public slots: |
22 | 24 | private slots: |
23 | 25 | void testCommStatus(); |
24 | 26 | void testComm(); |
25 | - void testGetValueFromFile(); | |
27 | + void testGetAndSetValueFromFile(); | |
26 | 28 | void testGetValueFromTags(); |
27 | 29 | void testEnCrypt(); |
28 | 30 | void testDeCrypt(); |
31 | + void testCreateFolder(); | |
32 | + void testDeleteFolder(); | |
33 | + void testDeleteFile(); | |
29 | 34 | }; |
30 | 35 | |
31 | 36 | #endif // TESTINSTALLCACIC_H | ... | ... |
src/ccacic.cpp
... | ... | @@ -4,35 +4,62 @@ CCacic::CCacic(QObject *parent) : |
4 | 4 | QObject(parent) |
5 | 5 | { |
6 | 6 | } |
7 | - | |
7 | +/* getValueFromFile | |
8 | + * Pega valor específico dentro de um arquivo | |
9 | + * @parameter QString sectionName: nome da seção onde estará a key) | |
10 | + * @parameter QString keyName: nome da key que está o valor) | |
11 | + * @parameter QString filePath: caminho do arquivo que será aberto; | |
12 | + * | |
13 | + * @return QString: "" (vazio) Caso não encontre, | |
14 | + * "0" caso não seja possível abrir o arquivo; | |
15 | + */ | |
8 | 16 | QString CCacic::getValueFromFile(QString sectionName, QString keyName, QString filePath) |
9 | 17 | { |
10 | 18 | QFile file(filePath); |
11 | - sectionName = "<" + sectionName + ">"; | |
19 | + QString line = ""; | |
20 | + sectionName = "[" + sectionName + "]"; | |
12 | 21 | keyName = keyName + "="; |
13 | 22 | int sizeKeyName = keyName.size(); |
14 | 23 | |
15 | 24 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
16 | 25 | return "0"; |
17 | 26 | |
18 | - QString line = file.readLine(); | |
19 | - while (!file.atEnd()) { | |
20 | - if (line.contains(sectionName, Qt::CaseInsensitive)) { | |
21 | - line = file.readLine(); | |
22 | - while (!file.atEnd()){ | |
23 | - if (line.contains(keyName, Qt::CaseInsensitive)) { | |
24 | - file.close(); | |
25 | - return line.mid(sizeKeyName).trimmed(); | |
26 | - } | |
27 | - } | |
28 | - } else { | |
29 | - line = file.readLine(); | |
30 | - } | |
27 | + while (!file.atEnd()){ | |
28 | + line = file.readLine(); | |
29 | + if (line.contains(sectionName, Qt::CaseInsensitive)) { | |
30 | + do { | |
31 | + line = file.readLine(); | |
32 | + if (line.contains(keyName, Qt::CaseInsensitive)) { | |
33 | + file.close(); | |
34 | + return line.mid(sizeKeyName).trimmed(); | |
35 | + } | |
36 | + } while (!file.atEnd()); | |
37 | + } | |
31 | 38 | } |
32 | 39 | file.close(); |
33 | 40 | return ""; |
34 | 41 | } |
42 | +/*getValueFromTags | |
43 | + * @parameter QString sectionName: Grupo onde está a chave; | |
44 | + * @parameter QString keyName: chave que queremos para colocar o valor; | |
45 | + * @parameter QString value: valor para colocar dentro da chave; | |
46 | + * @parameter QString filePath: Local do arquivo; | |
47 | + */ | |
48 | +void CCacic::setValueToFile(QString sectionName, QString keyName, QString value, QString filePath) | |
49 | +{ | |
50 | + QSettings settings(filePath, QSettings::IniFormat); | |
51 | + settings.beginGroup(sectionName); | |
52 | + settings.setValue(keyName, value); | |
53 | + settings.endGroup(); | |
54 | +} | |
35 | 55 | |
56 | +/*getValueFromTags | |
57 | + * @parameter QString fullString: string onde será pesquisado o valor desejado; | |
58 | + * @parameter QString tag: nome da tag onde estará o valor; | |
59 | + * @parameter QString tagType: padrão "[]", tipo da tag; | |
60 | + * | |
61 | + * @return: QString: valor entre as tags. | |
62 | + */ | |
36 | 63 | QString CCacic::getValueFromTags(QString fullString, QString tag, QString tagType) { |
37 | 64 | QString tagFim = tagType.mid(0,1) + "/" + tag + tagType.mid(1); |
38 | 65 | int tagSize; |
... | ... | @@ -41,6 +68,39 @@ QString CCacic::getValueFromTags(QString fullString, QString tag, QString tagTyp |
41 | 68 | return fullString.mid(fullString.indexOf(tag) + tagSize, |
42 | 69 | fullString.indexOf(tagFim) - (fullString.indexOf(tag) + tagSize)).trimmed(); |
43 | 70 | } |
71 | +/*createFolder | |
72 | + * @parameter QString path: caminho onde será criado o diretório, sendo criado toda a árvore se necessário. | |
73 | + * @return bool: true se conseguir ou já existir, false se não. | |
74 | + */ | |
75 | +bool CCacic::createFolder(QString path) | |
76 | +{ | |
77 | + QDir folder(path); | |
78 | + return folder.mkpath(path); | |
79 | +} | |
80 | +/*deleteFolder | |
81 | + * @parameter QString path: caminho do diretório; | |
82 | + * @return bool: true se conseguir ou já não existir, false se não conseguir. | |
83 | + */ | |
84 | +bool CCacic::deleteFolder(QString path) | |
85 | +{ | |
86 | + QDir folder(path); | |
87 | + if (folder.exists()) | |
88 | + return folder.removeRecursively(); | |
89 | + else | |
90 | + return true; | |
91 | +} | |
92 | +/*deleteFile | |
93 | + * @parameter QString path: caminho do arquivo; | |
94 | + * @return bool: true se conseguir ou já não existir, false se não conseguir. | |
95 | + */ | |
96 | +bool CCacic::deleteFile(QString path) | |
97 | +{ | |
98 | + QDir folder(path); | |
99 | + if (folder.exists()) | |
100 | + return folder.remove(path); | |
101 | + else | |
102 | + return true; | |
103 | +} | |
44 | 104 | |
45 | 105 | std::string CCacic::enCrypt(QString str_in, QString key, QString iv) |
46 | 106 | { | ... | ... |
src/ccacic.h
... | ... | @@ -13,6 +13,8 @@ |
13 | 13 | #include <crypto++/hex.h> |
14 | 14 | #include <crypto++/sha.h> |
15 | 15 | #include <crypto++/md5.h> |
16 | +#include <QSettings> | |
17 | +#include <QDir> | |
16 | 18 | |
17 | 19 | class CCacic : public QObject |
18 | 20 | { |
... | ... | @@ -20,9 +22,13 @@ class CCacic : public QObject |
20 | 22 | public: |
21 | 23 | explicit CCacic(QObject *parent = 0); |
22 | 24 | QString getValueFromFile(QString sectionName, QString keyName, QString filePath); |
25 | + void setValueToFile(QString sectionName, QString keyName, QString value, QString filePath); | |
23 | 26 | QString getValueFromTags(QString fullString, QString tag, QString tagType = "[]"); |
24 | 27 | std::string enCrypt(QString str_in, QString key, QString iv); |
25 | 28 | std::string deCrypt(QString str_in, QString key, QString iv); |
29 | + bool createFolder(QString path); | |
30 | + bool deleteFolder(QString path); | |
31 | + bool deleteFile(QString path); | |
26 | 32 | |
27 | 33 | //Geters/seters: |
28 | 34 | ... | ... |