Robin Thoni пре 7 година
родитељ
комит
54bce7eecb

+ 1
- 1
cli/cli/MainClass.cpp Прегледај датотеку

@@ -372,7 +372,7 @@ void MainClass::printPercentWrite(int done, int total)
372 372
 void MainClass::printVersion()
373 373
 {
374 374
     cout() << "LibNfc version: " << LibNfc::Core::LibNfcContext::getLibNfcVersion() << std::endl;
375
-    cout() << "Mifare-tools version: " << LibNfc::Core::LibNfcContext::getMifareToolsVersion() << std::endl;
375
+    cout() << "Mifare-tools version: " << LibNfc::Core::LibNfcContext::getLibNfcCppToolsVersion() << std::endl;
376 376
 }
377 377
 
378 378
 std::shared_ptr<LibNfc::Core::NfcDevice> MainClass::getDevice(const std::string &deviceName, std::vector<std::shared_ptr<LibNfc::Core::NfcDevice>> devices)

+ 3
- 3
libnfc_cpptools/inc/libnfc_cpptools/ArrayUtils.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 7/23/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_ARRAYUTILS_H
6
-#define MIFARE_TOOLS_ARRAYUTILS_H
5
+#ifndef LIBNFC_CPPTOOLS_ARRAYUTILS_H
6
+#define LIBNFC_CPPTOOLS_ARRAYUTILS_H
7 7
 
8 8
 
9 9
 namespace LibNfc
@@ -24,4 +24,4 @@ public:
24 24
 }; // Utils
25 25
 }; // LibNfc
26 26
 
27
-#endif //MIFARE_TOOLS_ARRAYUTILS_H
27
+#endif // LIBNFC_CPPTOOLS_ARRAYUTILS_H

+ 5
- 4
libnfc_cpptools/inc/libnfc_cpptools/FreeFareAccessBits.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 7/21/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_ACCESSBITSDBO_H
6
-#define MIFARE_TOOLS_ACCESSBITSDBO_H
5
+#ifndef LIBNFC_CPPTOOLS_ACCESSBITSDBO_H
6
+#define LIBNFC_CPPTOOLS_ACCESSBITSDBO_H
7 7
 
8 8
 
9 9
 #include <string>
@@ -21,7 +21,8 @@ public:
21 21
     static const char invertedBitPosition[4][4];
22 22
 
23 23
     FreeFareAccessBits();
24
-    FreeFareAccessBits(const std::string& bits);
24
+    explicit FreeFareAccessBits(const std::string& bits);
25
+    ~FreeFareAccessBits() = default;
25 26
 
26 27
     char getUserData() const;
27 28
     void setUserData(const char& data);
@@ -67,4 +68,4 @@ private:
67 68
 }; // FreeFare
68 69
 }; // LibNfc
69 70
 
70
-#endif //MIFARE_TOOLS_ACCESSBITSDBO_H
71
+#endif //LIBNFC_CPPTOOLS_ACCESSBITSDBO_H

+ 5
- 4
libnfc_cpptools/inc/libnfc_cpptools/FreeFareDevice.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 7/22/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_FREEFAREDEVICEBUSINESS_H
6
-#define MIFARE_TOOLS_FREEFAREDEVICEBUSINESS_H
5
+#ifndef LIBNFC_CPPTOOLS_FREEFAREDEVICEBUSINESS_H
6
+#define LIBNFC_CPPTOOLS_FREEFAREDEVICEBUSINESS_H
7 7
 
8 8
 #include "NfcDevice.h"
9 9
 #include "FreeFareTag.h"
@@ -18,7 +18,8 @@ class FreeFareDeviceInternal;
18 18
 class FreeFareDevice
19 19
 {
20 20
 public:
21
-    FreeFareDevice(std::shared_ptr<LibNfc::Core::NfcDevice> device);
21
+    explicit FreeFareDevice(std::shared_ptr<LibNfc::Core::NfcDevice> device);
22
+    ~FreeFareDevice() = default;
22 23
 
23 24
     LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTag>>> getTags() const;
24 25
 
@@ -31,4 +32,4 @@ protected:
31 32
 }; // FreeFare
32 33
 }; // LibNfc
33 34
 
34
-#endif //MIFARE_TOOLS_FREEFAREDEVICEBUSINESS_H
35
+#endif //LIBNFC_CPPTOOLS_FREEFAREDEVICEBUSINESS_H

+ 5
- 4
libnfc_cpptools/inc/libnfc_cpptools/FreeFareSector.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 7/22/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_SECTORDBO_H
6
-#define MIFARE_TOOLS_SECTORDBO_H
5
+#ifndef LIBNFC_CPPTOOLS_SECTORDBO_H
6
+#define LIBNFC_CPPTOOLS_SECTORDBO_H
7 7
 
8 8
 
9 9
 #include <string>
@@ -18,7 +18,8 @@ namespace FreeFare
18 18
 class FreeFareSector
19 19
 {
20 20
 public:
21
-    FreeFareSector(const std::string& data = "");
21
+    explicit FreeFareSector(const std::string& data = "");
22
+    ~FreeFareSector() = default;
22 23
 
23 24
     const std::string& getBlock(int block) const;
24 25
 
@@ -63,4 +64,4 @@ protected:
63 64
 }; // FreeFare
64 65
 }; // LibNfc
65 66
 
66
-#endif //MIFARE_TOOLS_SECTORDBO_H
67
+#endif //LIBNFC_CPPTOOLS_SECTORDBO_H

+ 17
- 16
libnfc_cpptools/inc/libnfc_cpptools/FreeFareTag.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 7/22/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_FREEFARETAGBUSINESS_H
6
-#define MIFARE_TOOLS_FREEFARETAGBUSINESS_H
5
+#ifndef LIBNFC_CPPTOOLS_FREEFARETAGBUSINESS_H
6
+#define LIBNFC_CPPTOOLS_FREEFARETAGBUSINESS_H
7 7
 
8 8
 
9 9
 #include <boost/shared_ptr.hpp>
@@ -34,29 +34,30 @@ public:
34 34
 
35 35
     static std::string getTagTypeString(FreeFareTagType type);
36 36
 
37
-    FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag);
37
+    explicit FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag);
38
+    ~FreeFareTag() = default;
38 39
 
39
-    LibNfc::Utils::ResultBool authenticate(int sector, std::string key, int keyType);
40
+    LibNfc::Utils::ResultBool authenticate(int sector, const std::string& key, int keyType);
40 41
 
41
-    LibNfc::Utils::Result<MappedKeys> mapKeys(std::vector<std::string> keys, std::function<void(int, int)> cb = 0);
42
+    LibNfc::Utils::Result<MappedKeys> mapKeys(const std::vector<std::string>& keys, std::function<void(int, int)> cb = nullptr);
42 43
 
43
-    LibNfc::Utils::ResultString readBlock(int sector, int block, std::string key, int keyType);
44
+    LibNfc::Utils::ResultString readBlock(int sector, int block, const std::string& key, int keyType);
44 45
 
45
-    LibNfc::Utils::Result<FreeFareSector> readSector(int sector, std::string key, int keyType);
46
+    LibNfc::Utils::Result<FreeFareSector> readSector(int sector, const std::string& key, int keyType);
46 47
 
47
-    LibNfc::Utils::Result<std::vector<FreeFareSector>> read(MappedKeys keys, std::function<void(int, int)> cb = 0);
48
+    LibNfc::Utils::Result<std::vector<FreeFareSector>> read(const MappedKeys& keys, std::function<void(int, int)> cb = nullptr);
48 49
 
49
-    LibNfc::Utils::Result<std::vector<FreeFareSector>> read(std::vector<std::string> keys, std::function<void(int, int)> mapCb = 0,
50
-                                        std::function<void(int, int)> readCb = 0);
50
+    LibNfc::Utils::Result<std::vector<FreeFareSector>> read(const std::vector<std::string>& keys, std::function<void(int, int)> mapCb = nullptr,
51
+                                        std::function<void(int, int)> readCb = nullptr);
51 52
 
52
-    LibNfc::Utils::ResultBool writeBlock(int sector, int block, std::string key, int keyType, const std::string& data);
53
+    LibNfc::Utils::ResultBool writeBlock(int sector, int block, const std::string& key, int keyType, const std::string& data);
53 54
 
54
-    LibNfc::Utils::ResultBool writeSector(int sector, std::string key, int keyType, const std::string& data);
55
+    LibNfc::Utils::ResultBool writeSector(int sector, const std::string& key, int keyType, const std::string& data);
55 56
 
56
-    LibNfc::Utils::ResultBool write(MappedKeys keys, const std::string& data, bool writeSector0, std::function<void(int, int)> cb = 0);
57
+    LibNfc::Utils::ResultBool write(const MappedKeys& keys, const std::string& data, bool writeSector0, std::function<void(int, int)> cb = nullptr);
57 58
 
58
-    LibNfc::Utils::ResultBool write(std::vector<std::string> keys, const std::string& data, bool writeSector0,
59
-                     std::function<void(int, int)> mapCb = 0, std::function<void(int, int)> writeCb = 0);
59
+    LibNfc::Utils::ResultBool write(const std::vector<std::string>& keys, const std::string& data, bool writeSector0,
60
+                     std::function<void(int, int)> mapCb = nullptr, std::function<void(int, int)> writeCb = nullptr);
60 61
 
61 62
     const std::string& getUid() const;
62 63
 
@@ -71,4 +72,4 @@ protected:
71 72
 }; // FreeFare
72 73
 }; // LibNfc
73 74
 
74
-#endif //MIFARE_TOOLS_FREEFARETAGBUSINESS_H
75
+#endif //LIBNFC_CPPTOOLS_FREEFARETAGBUSINESS_H

+ 4
- 4
libnfc_cpptools/inc/libnfc_cpptools/LibNfc.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 7/22/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_LIBNFCBUSINESS_H
6
-#define MIFARE_TOOLS_LIBNFCBUSINESS_H
5
+#ifndef LIBNFC_CPPTOOLS_LIBNFCBUSINESS_H
6
+#define LIBNFC_CPPTOOLS_LIBNFCBUSINESS_H
7 7
 
8 8
 
9 9
 #include <libnfc_cpptools/Result.h>
@@ -32,7 +32,7 @@ public:
32 32
 
33 33
     static std::string getLibNfcVersion();
34 34
 
35
-    static std::string getMifareToolsVersion();
35
+    static std::string getLibNfcCppToolsVersion();
36 36
 
37 37
 protected:
38 38
     std::shared_ptr<LibNfcInternal> _libNfc;
@@ -41,4 +41,4 @@ protected:
41 41
 }; // Core
42 42
 }; // LibNfc
43 43
 
44
-#endif //MIFARE_TOOLS_LIBNFCBUSINESS_H
44
+#endif //LIBNFC_CPPTOOLS_LIBNFCBUSINESS_H

+ 5
- 4
libnfc_cpptools/inc/libnfc_cpptools/NfcDevice.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 7/22/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_NFCDEVICEBUSINESS_H
6
-#define MIFARE_TOOLS_NFCDEVICEBUSINESS_H
5
+#ifndef LIBNFC_CPPTOOLS_NFCDEVICEBUSINESS_H
6
+#define LIBNFC_CPPTOOLS_NFCDEVICEBUSINESS_H
7 7
 
8 8
 #include <string>
9 9
 #include <memory>
@@ -20,7 +20,8 @@ class NfcDeviceInternal;
20 20
 class NfcDevice
21 21
 {
22 22
 public:
23
-    NfcDevice(std::shared_ptr<NfcDeviceInternal> device);
23
+    explicit NfcDevice(std::shared_ptr<NfcDeviceInternal> device);
24
+    ~NfcDevice() = default;
24 25
 
25 26
     LibNfc::Utils::ResultBool open();
26 27
 
@@ -39,4 +40,4 @@ protected:
39 40
 }; // Core
40 41
 }; // LibNfc
41 42
 
42
-#endif //MIFARE_TOOLS_NFCDEVICEBUSINESS_H
43
+#endif //LIBNFC_CPPTOOLS_NFCDEVICEBUSINESS_H

+ 5
- 4
libnfc_cpptools/inc/libnfc_cpptools/Result.h Прегледај датотеку

@@ -8,8 +8,8 @@
8 8
 #include <string>
9 9
 #include <vector>
10 10
 #include <iostream>
11
-#include <errno.h>
12
-#include <string.h>
11
+#include <cerrno>
12
+#include <cstring>
13 13
 
14 14
 namespace LibNfc
15 15
 {
@@ -19,6 +19,8 @@ namespace Utils
19 19
 template <class T> class Result
20 20
 {
21 21
 public:
22
+    Result();
23
+
22 24
     static const Result<T> ok(const T& data);
23 25
     static const Result<T> strerror();
24 26
     static const Result<T> error(const std::string& error);
@@ -37,8 +39,6 @@ public:
37 39
     const Result<T>& print() const;
38 40
 
39 41
 private:
40
-    Result();
41
-
42 42
     T _data;
43 43
 
44 44
     std::string _error;
@@ -63,6 +63,7 @@ typedef Result<std::string> ResultString;
63 63
 
64 64
 template<class T>
65 65
 Result<T>::Result()
66
+    : _success(false)
66 67
 {
67 68
 }
68 69
 

+ 3
- 3
libnfc_cpptools/inc/libnfc_cpptools/StringUtils.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 6/20/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_HEX_H
6
-#define MIFARE_TOOLS_HEX_H
5
+#ifndef LIBNFC_CPPTOOLS_HEX_H
6
+#define LIBNFC_CPPTOOLS_HEX_H
7 7
 
8 8
 
9 9
 #include <string>
@@ -48,4 +48,4 @@ public:
48 48
 }; // Utils
49 49
 }; // LibNfc
50 50
 
51
-#endif //MIFARE_TOOLS_HEX_H
51
+#endif //LIBNFC_CPPTOOLS_HEX_H

+ 0
- 2
libnfc_cpptools/src/freefare/FreeFareAccessBits.cpp Прегледај датотеку

@@ -145,7 +145,6 @@ bool FreeFareAccessBits::canKeyAWriteKeyATrailer() const
145 145
 {
146 146
     bool c1 = getBit(1, 3);
147 147
     bool c2 = getBit(2, 3);
148
-    bool c3 = getBit(3, 3);
149 148
     return !c1 && !c2;
150 149
 }
151 150
 
@@ -203,7 +202,6 @@ bool FreeFareAccessBits::canKeyAWriteKeyBTrailer() const
203 202
 {
204 203
     bool c1 = getBit(1, 3);
205 204
     bool c2 = getBit(2, 3);
206
-    bool c3 = getBit(3, 3);
207 205
     return !c1 && !c2;
208 206
 }
209 207
 

+ 5
- 4
libnfc_cpptools/src/freefare/FreeFareDeviceInternal.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 6/19/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_FREEFAREDEVICE_H
6
-#define MIFARE_TOOLS_FREEFAREDEVICE_H
5
+#ifndef LIBNFC_CPPTOOLS_FREEFAREDEVICE_H
6
+#define LIBNFC_CPPTOOLS_FREEFAREDEVICE_H
7 7
 
8 8
 
9 9
 #include <freefare.h>
@@ -18,7 +18,8 @@ namespace FreeFare
18 18
 class FreeFareDeviceInternal
19 19
 {
20 20
 public:
21
-    FreeFareDeviceInternal(std::shared_ptr<LibNfc::Core::NfcDeviceInternal> device);
21
+    explicit FreeFareDeviceInternal(std::shared_ptr<LibNfc::Core::NfcDeviceInternal> device);
22
+    ~FreeFareDeviceInternal() = default;
22 23
 
23 24
     LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTagInternal>>> getTags();
24 25
 
@@ -29,4 +30,4 @@ private:
29 30
 }; // FreeFare
30 31
 }; // LibNfc
31 32
 
32
-#endif //MIFARE_TOOLS_FREEFAREDEVICE_H
33
+#endif //LIBNFC_CPPTOOLS_FREEFAREDEVICE_H

+ 1
- 1
libnfc_cpptools/src/freefare/FreeFareSector.cpp Прегледај датотеку

@@ -13,7 +13,7 @@ namespace FreeFare
13 13
 FreeFareSector::FreeFareSector(const std::string &data)
14 14
 {
15 15
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
16
-    for (int i = 0; i < 4; ++i) {
16
+    for (unsigned int i = 0; i < 4; ++i) {
17 17
         _blocks[i] = d.substr(16 * i, 16);
18 18
         _haveBlocks[i] = true;
19 19
     }

+ 28
- 27
libnfc_cpptools/src/freefare/FreeFareTag.cpp Прегледај датотеку

@@ -49,28 +49,28 @@ FreeFareTag::FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag)
49 49
 {
50 50
 }
51 51
 
52
-LibNfc::Utils::ResultBool FreeFareTag::authenticate(int sector, std::string key, int keyType)
52
+LibNfc::Utils::ResultBool FreeFareTag::authenticate(int sector, const std::string& key, int keyType)
53 53
 {
54 54
     return _tag->authenticate(sector, key, keyType);
55 55
 }
56 56
 
57
-LibNfc::Utils::Result<MappedKeys> FreeFareTag::mapKeys(std::vector<std::string> keys, std::function<void(int, int)> cb)
57
+LibNfc::Utils::Result<MappedKeys> FreeFareTag::mapKeys(const std::vector<std::string>& keys, std::function<void(int, int)> cb)
58 58
 {
59 59
     MappedKeys mappedKeys;
60
-    int done = 0;
61
-    int total = 16 * keys.size();
60
+    unsigned long done = 0;
61
+    unsigned long total = 16 * keys.size();
62 62
 
63 63
     for (int i = 0; i < 16; ++i) {
64 64
         std::pair<std::string, std::string> blockKeys;
65
-        for (int k = 0; k < keys.size(); ++k) {
66
-            auto key = keys[k];
65
+        for (const auto& key : keys)
66
+        {
67 67
             if (authenticate(i, key, MFC_KEY_A)) {
68 68
                 blockKeys.first = key;
69 69
             }
70 70
             if (authenticate(i, key, MFC_KEY_B)) {
71 71
                 blockKeys.second = key;
72 72
             }
73
-            if (cb != 0) {
73
+            if (cb != nullptr) {
74 74
                 cb(++done, total);
75 75
             }
76 76
             if (!blockKeys.first.empty() && !blockKeys.second.empty()) {
@@ -79,19 +79,19 @@ LibNfc::Utils::Result<MappedKeys> FreeFareTag::mapKeys(std::vector<std::string>
79 79
         }
80 80
         mappedKeys.push_back(blockKeys);
81 81
     }
82
-    if (cb != 0 && done < total) {
82
+    if (cb != nullptr && done < total) {
83 83
         cb(total, total);
84 84
     }
85 85
 
86 86
     return LibNfc::Utils::Result<MappedKeys>::ok(mappedKeys);
87 87
 }
88 88
 
89
-LibNfc::Utils::ResultString FreeFareTag::readBlock(int sector, int block, std::string key, int keyType)
89
+LibNfc::Utils::ResultString FreeFareTag::readBlock(int sector, int block, const std::string& key, int keyType)
90 90
 {
91 91
     return _tag->readBlock(sector, block, key, keyType);
92 92
 }
93 93
 
94
-LibNfc::Utils::Result<FreeFareSector> FreeFareTag::readSector(int sector, std::string key, int keyType)
94
+LibNfc::Utils::Result<FreeFareSector> FreeFareTag::readSector(int sector, const std::string& key, int keyType)
95 95
 {
96 96
     std::string res;
97 97
     int lastBlock = _tag->getSectorBlockCount(sector);
@@ -107,7 +107,7 @@ LibNfc::Utils::Result<FreeFareSector> FreeFareTag::readSector(int sector, std::s
107 107
     return LibNfc::Utils::Result<FreeFareSector>::ok(FreeFareSector(res));
108 108
 }
109 109
 
110
-LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(MappedKeys keys, std::function<void(int, int)> cb)
110
+LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(const MappedKeys& keys, std::function<void(int, int)> cb)
111 111
 {
112 112
     if (keys.size() != 16) {
113 113
         return LibNfc::Utils::Result<std::vector<FreeFareSector>>::error("Must have 16 sectors keys");
@@ -139,13 +139,13 @@ LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(MappedKeys
139 139
                 }
140 140
             }
141 141
             sector.setBlock(b, data);
142
-            if (cb != 0) {
142
+            if (cb != nullptr) {
143 143
                 cb(++done, total);
144 144
             }
145 145
         }
146 146
         int b = 3;
147
-        std::string dataA = "";
148
-        std::string dataB = "";
147
+        std::string dataA;
148
+        std::string dataB;
149 149
         if (!sectorKey.first.empty()) {
150 150
             auto blockResult = readBlock(s, b, sectorKey.first, MFC_KEY_A);
151 151
             if (blockResult) {
@@ -160,7 +160,7 @@ LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(MappedKeys
160 160
                 keyB = true;
161 161
             }
162 162
         }
163
-        if (cb != 0) {
163
+        if (cb != nullptr) {
164 164
             cb(++done, total);
165 165
         }
166 166
 
@@ -182,15 +182,16 @@ LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(MappedKeys
182 182
 
183 183
         sectors.push_back(sector);
184 184
     }
185
-    if (cb != 0 && done < total) {
185
+    if (cb != nullptr && done < total) {
186 186
         cb(total, total);
187 187
     }
188 188
 
189 189
     return LibNfc::Utils::Result<std::vector<FreeFareSector>>::ok(sectors);
190 190
 }
191 191
 
192
-LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(std::vector<std::string> keys, std::function<void(int, int)> mapCb,
193
-                                                         std::function<void(int, int)> readCb)
192
+LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(const std::vector<std::string>& keys,
193
+                                                                     std::function<void(int, int)> mapCb,
194
+                                                                     std::function<void(int, int)> readCb)
194 195
 {
195 196
     auto mappedKeysResult = mapKeys(keys, mapCb);
196 197
     if (!mappedKeysResult) {
@@ -199,12 +200,12 @@ LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(std::vector
199 200
     return read(mappedKeysResult.getData(), readCb);
200 201
 }
201 202
 
202
-LibNfc::Utils::ResultBool FreeFareTag::writeBlock(int sector, int block, std::string key, int keyType, const std::string &data)
203
+LibNfc::Utils::ResultBool FreeFareTag::writeBlock(int sector, int block, const std::string& key, int keyType, const std::string& data)
203 204
 {
204 205
     return _tag->writeBlock(sector, block, key, keyType, LibNfc::Utils::StringUtils::ensureSize(data, 16));
205 206
 }
206 207
 
207
-LibNfc::Utils::ResultBool FreeFareTag::writeSector(int sector, std::string key, int keyType, const std::string &data)
208
+LibNfc::Utils::ResultBool FreeFareTag::writeSector(int sector, const std::string& key, int keyType, const std::string& data)
208 209
 {
209 210
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
210 211
     std::string errors;
@@ -221,23 +222,23 @@ LibNfc::Utils::ResultBool FreeFareTag::writeSector(int sector, std::string key,
221 222
     return LibNfc::Utils::ResultBool::error(errors);
222 223
 }
223 224
 
224
-LibNfc::Utils::ResultBool FreeFareTag::write(MappedKeys keys, const std::string &data, bool writeSector0, std::function<void(int, int)> cb)
225
+LibNfc::Utils::ResultBool FreeFareTag::write(const MappedKeys& keys, const std::string& data, bool writeSector0, std::function<void(int, int)> cb)
225 226
 {
226 227
     if (keys.size() != 16) {
227 228
         return LibNfc::Utils::ResultBool::error("Must have 16 sectors keys");
228 229
     }
229 230
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 1024);
230 231
     std::string errors;
231
-    int done = 0;
232
-    int total = 4 * keys.size();
233
-    for (int s = 0; s < keys.size(); ++s) {
232
+    unsigned long done = 0;
233
+    unsigned long total = 4 * keys.size();
234
+    for (unsigned long s = 0; s < keys.size(); ++s) {
234 235
         auto sectorKey = keys[s];
235 236
         for (int b = 0; b < 4; ++b) {
236 237
             if (s == 0 && b == 0 && !writeSector0) {
237 238
                 continue;
238 239
             }
239 240
             std::string blockData = d.substr((s * 64) + (b * 16), 16);
240
-            if (cb != 0 && done < total) {
241
+            if (cb != nullptr && done < total) {
241 242
                 bool keyA = false;
242 243
                 bool keyB = false;
243 244
                 std::string sectorErrors;
@@ -268,7 +269,7 @@ LibNfc::Utils::ResultBool FreeFareTag::write(MappedKeys keys, const std::string
268 269
             }
269 270
         }
270 271
     }
271
-    if (cb != 0 && done < total) {
272
+    if (cb != nullptr && done < total) {
272 273
         cb(total, total);
273 274
     }
274 275
     if (errors.empty()) {
@@ -277,7 +278,7 @@ LibNfc::Utils::ResultBool FreeFareTag::write(MappedKeys keys, const std::string
277 278
     return LibNfc::Utils::ResultBool::error(errors);
278 279
 }
279 280
 
280
-LibNfc::Utils::ResultBool FreeFareTag::write(std::vector<std::string> keys, const std::string &data, bool writeSector0,
281
+LibNfc::Utils::ResultBool FreeFareTag::write(const std::vector<std::string>& keys, const std::string& data, bool writeSector0,
281 282
                                       std::function<void(int, int)> mapCb, std::function<void(int, int)> writeCb)
282 283
 {
283 284
     auto mappedKeysResult = mapKeys(keys, mapCb);

+ 4
- 4
libnfc_cpptools/src/freefare/FreeFareTagInternal.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 6/19/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_FREEFARETAG_H
6
-#define MIFARE_TOOLS_FREEFARETAG_H
5
+#ifndef LIBNFC_CPPTOOLS_FREEFARETAG_H
6
+#define LIBNFC_CPPTOOLS_FREEFARETAG_H
7 7
 
8 8
 #include <freefare.h>
9 9
 #include <string>
@@ -18,7 +18,7 @@ class FreeFareTagInternal
18 18
 {
19 19
 public:
20 20
 
21
-    FreeFareTagInternal(FreefareTag tag);
21
+    explicit FreeFareTagInternal(FreefareTag tag);
22 22
     ~FreeFareTagInternal();
23 23
 
24 24
     LibNfc::Utils::ResultBool authenticate(int sector, std::string key, int keyType);
@@ -50,4 +50,4 @@ private:
50 50
 }; // FreeFare
51 51
 }; // LibNfc
52 52
 
53
-#endif //MIFARE_TOOLS_FREEFARETAG_H
53
+#endif //LIBNFC_CPPTOOLS_FREEFARETAG_H

+ 1
- 1
libnfc_cpptools/src/libnfc/LibNfc.cpp Прегледај датотеку

@@ -74,7 +74,7 @@ LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDevice>>> LibNfcContext::ge
74 74
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDevice>>>::ok(devicesBusiness);
75 75
 }
76 76
 
77
-std::string LibNfcContext::getMifareToolsVersion()
77
+std::string LibNfcContext::getLibNfcCppToolsVersion()
78 78
 {
79 79
     return QUOTE(GIT_REF_NAME)  "-"  QUOTE(GIT_SHA1);
80 80
 }

+ 3
- 3
libnfc_cpptools/src/libnfc/LibNfcInternal.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 6/19/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_LIBNFC_H
6
-#define MIFARE_TOOLS_LIBNFC_H
5
+#ifndef LIBNFC_CPPTOOLS_LIBNFC_H
6
+#define LIBNFC_CPPTOOLS_LIBNFC_H
7 7
 
8 8
 #include <memory>
9 9
 #include <nfc/nfc.h>
@@ -40,4 +40,4 @@ protected:
40 40
 }; // Core
41 41
 }; // LibNfc
42 42
 
43
-#endif //MIFARE_TOOLS_LIBNFC_H
43
+#endif //LIBNFC_CPPTOOLS_LIBNFC_H

+ 2
- 2
libnfc_cpptools/src/libnfc/NfcDeviceInternal.cpp Прегледај датотеку

@@ -11,7 +11,7 @@ namespace Core
11 11
 
12 12
 NfcDeviceInternal::NfcDeviceInternal(const LibNfcInternal* libNfc, const std::string& str)
13 13
     : _connStr(str)
14
-    , _device(0)
14
+    , _device(nullptr)
15 15
     , _libNfc(libNfc)
16 16
 {
17 17
 }
@@ -33,7 +33,7 @@ LibNfc::Utils::ResultBool NfcDeviceInternal::open()
33 33
 void NfcDeviceInternal::close()
34 34
 {
35 35
     nfc_close(_device);
36
-    _device = 0;
36
+    _device = nullptr;
37 37
 }
38 38
 
39 39
 nfc_device *NfcDeviceInternal::getDevice() const

+ 3
- 3
libnfc_cpptools/src/libnfc/NfcDeviceInternal.h Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 // Created by robin on 6/19/16.
3 3
 //
4 4
 
5
-#ifndef MIFARE_TOOLS_NFCDEVICEDBO_H
6
-#define MIFARE_TOOLS_NFCDEVICEDBO_H
5
+#ifndef LIBNFC_CPPTOOLS_NFCDEVICEDBO_H
6
+#define LIBNFC_CPPTOOLS_NFCDEVICEDBO_H
7 7
 
8 8
 
9 9
 #include <string>
@@ -43,4 +43,4 @@ private:
43 43
 }; // Core
44 44
 }; // LibNfc
45 45
 
46
-#endif //MIFARE_TOOLS_NFCDEVICEDBO_H
46
+#endif //LIBNFC_CPPTOOLS_NFCDEVICEDBO_H

Loading…
Откажи
Сачувај