@digitalshieldfe/react-native-backup-card-sdk 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -25
- package/android/build.gradle +49 -4
- package/android/consumer-rules.pro +0 -0
- package/android/proguard-rules.pro +21 -0
- package/android/src/main/AndroidManifest.xml +4 -1
- package/android/src/main/java/com/ziancube/backupcardsdk/BackupCardSdk.kt +478 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/GPChannelNatives.java +41 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/listener/ApiAsyncListener.java +13 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ApiNfc.java +173 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ImplNfc.java +39 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/NfcComm.java +115 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/ApduParam.java +67 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/CommList.java +41 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/Utils.java +109 -0
- package/android/src/main/java/com/ziancube/reactnativebackupcardsdk/BackupCardSdkModule.kt +49 -81
- package/android/src/main/jni/CMakeLists.txt +60 -0
- package/android/src/main/jni/GPChannel/include/GPChannelSDK.h +306 -0
- package/android/src/main/jni/GPChannel/include/context/BaseContext.h +56 -0
- package/android/src/main/jni/GPChannel/include/device/ApduBuilder.hpp +72 -0
- package/android/src/main/jni/GPChannel/include/utility/Apdu.hpp +166 -0
- package/android/src/main/jni/GPChannel/include/utility/Debug.hpp +59 -0
- package/android/src/main/jni/GPChannel/include/utility/Singleton.h +34 -0
- package/android/src/main/jni/GPChannel/include/utility/mutex.h +24 -0
- package/android/src/main/jni/GPChannel/include/utility/trim.hpp +155 -0
- package/android/src/main/jni/GPChannel/include/utility/util.h +104 -0
- package/android/src/main/jni/GPChannel/include/utility/xFactory.hpp +26 -0
- package/android/src/main/jni/GPChannel/include/utility/xManager.hpp +84 -0
- package/android/src/main/jni/GPChannel/src/arm64-v8a/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/arm64-v8a/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/GPChannel/src/armeabi-v7a/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/armeabi-v7a/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/GPChannel/src/x86/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/x86/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/src/implJni.cpp +313 -0
- package/android/src/main/jni/src/implJni.h +9 -0
- package/android/src/main/jni/utils/jsoncpp/AUTHORS +111 -0
- package/android/src/main/jni/utils/jsoncpp/CMakeLists.txt +159 -0
- package/android/src/main/jni/utils/jsoncpp/LICENSE +55 -0
- package/android/src/main/jni/utils/jsoncpp/README.md +135 -0
- package/android/src/main/jni/utils/jsoncpp/amalgamate.py +155 -0
- package/android/src/main/jni/utils/jsoncpp/appveyor.yml +22 -0
- package/android/src/main/jni/utils/jsoncpp/dev.makefile +35 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/__init__.py +6 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmw7.json +33 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmxp.json +26 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/antglob.py +205 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/batchbuild.py +278 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/fixeol.py +70 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/licenseupdater.py +94 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/tarball.py +52 -0
- package/android/src/main/jni/utils/jsoncpp/doxybuild.py +189 -0
- package/android/src/main/jni/utils/jsoncpp/include/CMakeLists.txt +2 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/allocator.h +98 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/assertions.h +54 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/autolink.h +25 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/config.h +187 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/features.h +61 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/forwards.h +37 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/json.h +15 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/reader.h +411 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/value.h +888 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/version.h +20 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/writer.h +357 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/jsontest.vcproj +119 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/lib_json.vcproj +205 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/test_lib_json.vcproj +130 -0
- package/android/src/main/jni/utils/jsoncpp/makerelease.py +390 -0
- package/android/src/main/jni/utils/jsoncpp/meson.build +103 -0
- package/android/src/main/jni/utils/jsoncpp/pkg-config/jsoncpp.pc.in +9 -0
- package/android/src/main/jni/utils/jsoncpp/src/CMakeLists.txt +5 -0
- package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/CMakeLists.txt +25 -0
- package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/main.cpp +333 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_tool.h +114 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_value.cpp +1661 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/version.h.in +20 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/CMakeLists.txt +38 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.cpp +457 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.h +286 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/main.cpp +2606 -0
- package/android/src/main/jni/utils/jsoncpp/travis.sh +23 -0
- package/android/src/main/jni/utils/jsoncpp/version +1 -0
- package/android/src/main/jni/utils/jsoncpp/version.in +1 -0
- package/android/src/main/jni/utils/logUtils.cpp +108 -0
- package/android/src/main/jni/utils/logUtils.h +87 -0
- package/android/src/main/jni/utils/mSIGNA/stdutils/uchar_vector.h +614 -0
- package/package.json +2 -3
- package/android/libs/backupcardsdk-1.0.0.aar +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef __Apdu__
|
|
3
|
+
#define __Apdu__
|
|
4
|
+
|
|
5
|
+
#include "GPChannelSDK.h"
|
|
6
|
+
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace jub {
|
|
10
|
+
|
|
11
|
+
class APDU {
|
|
12
|
+
|
|
13
|
+
public:
|
|
14
|
+
APDU() {
|
|
15
|
+
cla = 0;
|
|
16
|
+
ins = 0;
|
|
17
|
+
p1 = 0;
|
|
18
|
+
p2 = 0;
|
|
19
|
+
lc = 0;
|
|
20
|
+
le = 0;
|
|
21
|
+
data.clear();
|
|
22
|
+
}
|
|
23
|
+
APDU(JUB_ULONG ncla,
|
|
24
|
+
JUB_ULONG nins,
|
|
25
|
+
JUB_ULONG np1,
|
|
26
|
+
JUB_ULONG np2,
|
|
27
|
+
JUB_ULONG nlc,
|
|
28
|
+
const JUB_BYTE* pData = nullptr,
|
|
29
|
+
JUB_ULONG nle = 0) :
|
|
30
|
+
cla(ncla),
|
|
31
|
+
ins(nins),
|
|
32
|
+
p1(np1),
|
|
33
|
+
p2(np2),
|
|
34
|
+
lc(nlc),
|
|
35
|
+
le(nle) {
|
|
36
|
+
if ( 0 != lc
|
|
37
|
+
&& nullptr != pData
|
|
38
|
+
) {
|
|
39
|
+
SetData(pData, lc);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
data.clear();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
~APDU() {}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
JUB_ULONG cla, ins, p1, p2, lc, le;
|
|
49
|
+
std::vector<JUB_BYTE> data;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
void SetApdu(JUB_ULONG ncla,
|
|
53
|
+
JUB_ULONG nins,
|
|
54
|
+
JUB_ULONG np1,
|
|
55
|
+
JUB_ULONG np2,
|
|
56
|
+
JUB_ULONG nlc,
|
|
57
|
+
JUB_BYTE* pData = nullptr,
|
|
58
|
+
JUB_ULONG nle = 0) {
|
|
59
|
+
cla = ncla;
|
|
60
|
+
ins = nins;
|
|
61
|
+
p1 = np1;
|
|
62
|
+
p2 = np2;
|
|
63
|
+
lc = nlc;
|
|
64
|
+
le = nle;
|
|
65
|
+
if ( 0 != lc
|
|
66
|
+
&& nullptr != pData
|
|
67
|
+
) {
|
|
68
|
+
SetData(pData, lc);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
data.clear();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
void SetData(const JUB_BYTE* pData, JUB_ULONG ulDataSize) {
|
|
75
|
+
// assert(ulDataSize == lc);
|
|
76
|
+
data.clear();
|
|
77
|
+
// data.resize(ulDataSize);
|
|
78
|
+
data.insert(data.begin(), pData, pData + ulDataSize);
|
|
79
|
+
}
|
|
80
|
+
}; // class APDU end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ResponseAPDU {
|
|
84
|
+
|
|
85
|
+
public:
|
|
86
|
+
ResponseAPDU() {
|
|
87
|
+
raw.clear();
|
|
88
|
+
clear();
|
|
89
|
+
}
|
|
90
|
+
ResponseAPDU(std::vector<JUB_BYTE> raw)
|
|
91
|
+
: raw(raw) {
|
|
92
|
+
clear();
|
|
93
|
+
}
|
|
94
|
+
ResponseAPDU(JUB_BYTE_PTR ret, JUB_ULONG retLen) {
|
|
95
|
+
raw.insert(raw.end(), ret, ret+retLen);
|
|
96
|
+
clear();
|
|
97
|
+
}
|
|
98
|
+
~ResponseAPDU() {
|
|
99
|
+
raw.clear();
|
|
100
|
+
clear();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void clear() {
|
|
104
|
+
data.clear();
|
|
105
|
+
cmac.clear();
|
|
106
|
+
SW1 = 0;
|
|
107
|
+
SW2 = 0;
|
|
108
|
+
}
|
|
109
|
+
bool empty() {
|
|
110
|
+
return ( data.empty()
|
|
111
|
+
&& cmac.empty()
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
bool decode(bool hasMac=true) {
|
|
116
|
+
if (raw.empty()) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if ( CMAC_LEN > raw.size()
|
|
121
|
+
&& SW_LEN != raw.size()
|
|
122
|
+
) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
clear();
|
|
127
|
+
|
|
128
|
+
// parse SW
|
|
129
|
+
int swIndex1 = (int)raw.size() - SW_LEN;
|
|
130
|
+
int swIndex2 = (int)raw.size() - 1;
|
|
131
|
+
SW1 = raw[swIndex1];
|
|
132
|
+
SW2 = raw[swIndex2];
|
|
133
|
+
if (SW_LEN == raw.size()) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
int cmacLen = 0;
|
|
138
|
+
if (hasMac) {
|
|
139
|
+
cmacLen = CMAC_LEN;
|
|
140
|
+
}
|
|
141
|
+
int cmacIndex = (int)raw.size() - SW_LEN - cmacLen;
|
|
142
|
+
data.insert(data.end(), raw.begin(), raw.begin()+cmacIndex);
|
|
143
|
+
if (hasMac) {
|
|
144
|
+
cmac.insert(cmac.end(), raw.begin()+cmacIndex, raw.begin()+swIndex1);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public:
|
|
151
|
+
const int CMAC_LEN = 8;
|
|
152
|
+
const int SW_LEN = 2;
|
|
153
|
+
|
|
154
|
+
std::vector<JUB_BYTE> data;
|
|
155
|
+
std::vector<JUB_BYTE> cmac;
|
|
156
|
+
JUB_BYTE SW1;
|
|
157
|
+
JUB_BYTE SW2;
|
|
158
|
+
|
|
159
|
+
private:
|
|
160
|
+
std::vector<JUB_BYTE> raw;
|
|
161
|
+
}; // class ResponseAPDU end
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
} // namespace jub end
|
|
165
|
+
|
|
166
|
+
#endif // __Apdu__
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef __DEBUG_H__
|
|
3
|
+
#define __DEBUG_H__
|
|
4
|
+
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
#ifdef ANDROID
|
|
8
|
+
#include <android/log.h>
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
namespace jub {
|
|
12
|
+
|
|
13
|
+
#define DEBUG_LEVEL 1
|
|
14
|
+
|
|
15
|
+
#define JUB_DebugLevel(level, ...) \
|
|
16
|
+
{ \
|
|
17
|
+
if (DEBUG_LEVEL >= level) { \
|
|
18
|
+
JUB_DebugLog(__VA_ARGS__); \
|
|
19
|
+
} \
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#define JUB_Debug(level, STR) \
|
|
23
|
+
{ \
|
|
24
|
+
if (DEBUG_LEVEL >= level) { \
|
|
25
|
+
JUB_DebugLog(STR); \
|
|
26
|
+
} \
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#ifdef ANDROID
|
|
30
|
+
void JUB_DebugLog(android_LogPriority logPriority, const char *format, ...);
|
|
31
|
+
void JUB_DebugLog(android_LogPriority logPriority, const std::string &log);
|
|
32
|
+
#else
|
|
33
|
+
void JUB_DebugLog(const char *format, ...);
|
|
34
|
+
void JUB_DebugLog(const std::string &log);
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
#if defined(DEBUG) || defined(_DEBUG)
|
|
38
|
+
#ifdef ANDROID
|
|
39
|
+
#define DEBUG_LOG(...) jub::JUB_DebugLog(ANDROID_LOG_DEBUG, __VA_ARGS__)
|
|
40
|
+
#define DEBUG_ERR(...) jub::JUB_DebugLog(ANDROID_LOG_ERROR, __VA_ARGS__)
|
|
41
|
+
#else
|
|
42
|
+
#define DEBUG_LOG(...) jub::JUB_DebugLog(__VA_ARGS__)
|
|
43
|
+
#define DEBUG_ERR(...) jub::JUB_DebugLog(__VA_ARGS__)
|
|
44
|
+
#endif
|
|
45
|
+
#else
|
|
46
|
+
#define DEBUG_LOG(...)
|
|
47
|
+
#define DEBUG_ERR(...)
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
enum {
|
|
51
|
+
BA2S_AA_BB, //01 01 03 04
|
|
52
|
+
BA2S_0XAA_0XBB, //0x01 0x02 0x03 0x04
|
|
53
|
+
BA2S_AABB, //01020304
|
|
54
|
+
}; // enum end
|
|
55
|
+
|
|
56
|
+
std::string ByteArray2String(const uint8_t* buf, uint32_t len, uint8_t type = BA2S_AABB);
|
|
57
|
+
} // namespace jub end
|
|
58
|
+
|
|
59
|
+
#endif // __DEBUG_H__
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#ifndef COINPASS_SINGLETON_HPP
|
|
3
|
+
#define COINPASS_SINGLETON_HPP
|
|
4
|
+
|
|
5
|
+
template<typename T>
|
|
6
|
+
class Singleton {
|
|
7
|
+
|
|
8
|
+
public:
|
|
9
|
+
template<typename... Args>
|
|
10
|
+
static T* GetInstance(Args&&... args) {
|
|
11
|
+
if (nullptr == _pInstance) {
|
|
12
|
+
_pInstance = new T(std::forward<Args>(args)...);
|
|
13
|
+
}
|
|
14
|
+
return _pInstance;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static void DestroyInstance() {
|
|
18
|
+
delete _pInstance;
|
|
19
|
+
_pInstance = nullptr;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private:
|
|
23
|
+
Singleton(void);
|
|
24
|
+
virtual ~Singleton(void);
|
|
25
|
+
Singleton(const Singleton&);
|
|
26
|
+
Singleton& operator = (const Singleton&);
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
static T* _pInstance;
|
|
30
|
+
}; // class Singleton end
|
|
31
|
+
|
|
32
|
+
template <class T> T* Singleton<T>::_pInstance = nullptr;
|
|
33
|
+
|
|
34
|
+
#endif
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* To change this license header, choose License Headers in Project Properties.
|
|
3
|
+
* To change this template file, choose Tools | Templates
|
|
4
|
+
* and open the template in the editor.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* File: mutex.h
|
|
9
|
+
* Author: zxc_work
|
|
10
|
+
*
|
|
11
|
+
* Created on 2020年2月22日, 下午2:08
|
|
12
|
+
*/
|
|
13
|
+
#pragma once
|
|
14
|
+
|
|
15
|
+
#ifndef MUTEX_H
|
|
16
|
+
#define MUTEX_H
|
|
17
|
+
#include <mutex>
|
|
18
|
+
|
|
19
|
+
extern std::mutex _mutex;
|
|
20
|
+
|
|
21
|
+
#define CREATE_THREAD_LOCK_GUARD std::lock_guard<std::mutex> lck(_mutex);
|
|
22
|
+
|
|
23
|
+
#endif /* MUTEX_H */
|
|
24
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//
|
|
2
|
+
// trim.hpp
|
|
3
|
+
// JubSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by panmin on 2019/9/26.
|
|
6
|
+
// Copyright © 2019 JuBiter. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef trim_h
|
|
10
|
+
#define trim_h
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <vector>
|
|
14
|
+
#include <algorithm>
|
|
15
|
+
#include <sstream>
|
|
16
|
+
#include <iostream>
|
|
17
|
+
#include <functional>
|
|
18
|
+
|
|
19
|
+
namespace jub {
|
|
20
|
+
namespace algorithm {
|
|
21
|
+
|
|
22
|
+
namespace detail {
|
|
23
|
+
// template< typename ForwardIteratorT, typename PredicateT >
|
|
24
|
+
// inline ForwardIteratorT trim_end_iter_select(
|
|
25
|
+
// ForwardIteratorT InBegin,
|
|
26
|
+
// ForwardIteratorT InEnd,
|
|
27
|
+
// PredicateT IsSpace,
|
|
28
|
+
// std::forward_iterator_tag )
|
|
29
|
+
// {
|
|
30
|
+
// ForwardIteratorT TrimIt=InBegin;
|
|
31
|
+
//
|
|
32
|
+
// for( ForwardIteratorT It=InBegin; It!=InEnd; ++It )
|
|
33
|
+
// {
|
|
34
|
+
// if ( !IsSpace(*It) )
|
|
35
|
+
// {
|
|
36
|
+
// TrimIt=It;
|
|
37
|
+
// ++TrimIt;
|
|
38
|
+
// }
|
|
39
|
+
// }
|
|
40
|
+
//
|
|
41
|
+
// return TrimIt;
|
|
42
|
+
// }
|
|
43
|
+
//
|
|
44
|
+
// template< typename ForwardIteratorT, typename PredicateT >
|
|
45
|
+
// inline ForwardIteratorT trim_end_iter_select(
|
|
46
|
+
// ForwardIteratorT InBegin,
|
|
47
|
+
// ForwardIteratorT InEnd,
|
|
48
|
+
// PredicateT IsSpace,
|
|
49
|
+
// std::bidirectional_iterator_tag )
|
|
50
|
+
// {
|
|
51
|
+
// for( ForwardIteratorT It=InEnd; It!=InBegin; )
|
|
52
|
+
// {
|
|
53
|
+
// if ( !IsSpace(*(--It)) )
|
|
54
|
+
// return ++It;
|
|
55
|
+
// }
|
|
56
|
+
//
|
|
57
|
+
// return InBegin;
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
template< typename ForwardIteratorT, typename PredicateT >
|
|
61
|
+
inline ForwardIteratorT eTrim_iter_select(ForwardIteratorT InBegin,
|
|
62
|
+
ForwardIteratorT InEnd,
|
|
63
|
+
PredicateT IsSpace,
|
|
64
|
+
std::forward_iterator_tag ) {
|
|
65
|
+
ForwardIteratorT TrimIt=InBegin;
|
|
66
|
+
|
|
67
|
+
for( ForwardIteratorT It=InBegin; It!=InEnd; ++It )
|
|
68
|
+
{
|
|
69
|
+
if ( !IsSpace(*It) )
|
|
70
|
+
{
|
|
71
|
+
TrimIt=It;
|
|
72
|
+
++TrimIt;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return TrimIt;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// // Search for first non matching character from the beginning of the sequence
|
|
80
|
+
// template< typename ForwardIteratorT, typename PredicateT >
|
|
81
|
+
// inline ForwardIteratorT trim_begin(
|
|
82
|
+
// ForwardIteratorT InBegin,
|
|
83
|
+
// ForwardIteratorT InEnd,
|
|
84
|
+
// PredicateT IsSpace )
|
|
85
|
+
// {
|
|
86
|
+
// ForwardIteratorT It=InBegin;
|
|
87
|
+
// for(; It!=InEnd; ++It )
|
|
88
|
+
// {
|
|
89
|
+
// if (!IsSpace(*It))
|
|
90
|
+
// return It;
|
|
91
|
+
// }
|
|
92
|
+
//
|
|
93
|
+
// return It;
|
|
94
|
+
// }
|
|
95
|
+
template< typename ForwardIteratorT, typename PredicateT >
|
|
96
|
+
inline ForwardIteratorT eTrim(ForwardIteratorT InBegin,
|
|
97
|
+
ForwardIteratorT InEnd,
|
|
98
|
+
PredicateT IsSpace ) {
|
|
99
|
+
typename std::iterator_traits<ForwardIteratorT>::iterator_category category;
|
|
100
|
+
return eTrim_iter_select(InBegin, InEnd, IsSpace, category);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
} // namespace detail end
|
|
104
|
+
|
|
105
|
+
template<typename SequenceT>
|
|
106
|
+
inline SequenceT& lTrim(SequenceT &Input) {
|
|
107
|
+
auto p = find_if(Input.begin(), Input.end(), std::not1(std::function<bool(char)>(isspace)));
|
|
108
|
+
Input.erase(Input.begin(), p);
|
|
109
|
+
return Input;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//template<typename SequenceT, typename PredicateT>
|
|
113
|
+
//inline void trim_right_if(SequenceT& Input, PredicateT IsSpace)
|
|
114
|
+
//{
|
|
115
|
+
// Input.erase(
|
|
116
|
+
// ::boost::algorithm::detail::trim_end(
|
|
117
|
+
// ::boost::begin(Input),
|
|
118
|
+
// ::boost::end(Input),
|
|
119
|
+
// IsSpace ),
|
|
120
|
+
// ::boost::end(Input)
|
|
121
|
+
// );
|
|
122
|
+
//}
|
|
123
|
+
template<typename SequenceT, typename PredicateT>
|
|
124
|
+
inline void rTrim_if(SequenceT& Input, PredicateT IsSpace) {
|
|
125
|
+
Input.erase(detail::eTrim(Input.begin(),
|
|
126
|
+
Input.end(),
|
|
127
|
+
IsSpace),
|
|
128
|
+
Input.end());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//boost::algorithm::trim_right
|
|
132
|
+
//template<typename SequenceT>
|
|
133
|
+
//inline void trim_right(SequenceT& Input, const std::locale& Loc=std::locale())
|
|
134
|
+
//{
|
|
135
|
+
// ::boost::algorithm::trim_right_if(
|
|
136
|
+
// Input,
|
|
137
|
+
// is_space(Loc) );
|
|
138
|
+
//}
|
|
139
|
+
template<typename SequenceT>
|
|
140
|
+
inline SequenceT& rTrim(SequenceT &Input, const std::locale& Loc=std::locale()) {
|
|
141
|
+
|
|
142
|
+
auto p = find_if(Input.rbegin(), Input.rend(), std::not1(std::function<bool(char)>(isspace)));
|
|
143
|
+
Input.erase(p.base(), Input.end());
|
|
144
|
+
return Input;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
template<typename SequenceT>
|
|
148
|
+
inline SequenceT& trim(SequenceT &st) {
|
|
149
|
+
lTrim(rTrim(st));
|
|
150
|
+
return st;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
} // namespace algorithm end
|
|
154
|
+
} // namespace jub end
|
|
155
|
+
#endif /* trim_h */
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#ifndef COINPASS_BIO_UTIL_HPP
|
|
3
|
+
#define COINPASS_BIO_UTIL_HPP
|
|
4
|
+
|
|
5
|
+
#include <assert.h>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
#include <algorithm>
|
|
10
|
+
#include <sstream>
|
|
11
|
+
#include <iostream>
|
|
12
|
+
#include <cstring>
|
|
13
|
+
#include "mSIGNA/stdutils/uchar_vector.h"
|
|
14
|
+
//#include "Data.h"
|
|
15
|
+
|
|
16
|
+
namespace jub {
|
|
17
|
+
|
|
18
|
+
#define JUB_VERIFY_RET(x, r) \
|
|
19
|
+
do { \
|
|
20
|
+
if (!(x)) { \
|
|
21
|
+
return (r); \
|
|
22
|
+
} \
|
|
23
|
+
} while (0)
|
|
24
|
+
|
|
25
|
+
#define JUB_VERIFY_RV(x) \
|
|
26
|
+
do { \
|
|
27
|
+
JUB_RV r = (x); \
|
|
28
|
+
if (JUBR_OK != r) { \
|
|
29
|
+
return r; \
|
|
30
|
+
} \
|
|
31
|
+
} while (0)
|
|
32
|
+
|
|
33
|
+
#define JUB_CHECK_NULL(x) \
|
|
34
|
+
do { \
|
|
35
|
+
if (!x) { \
|
|
36
|
+
assert(false); \
|
|
37
|
+
return JUBR_MEMORY_NULL_PTR; \
|
|
38
|
+
} \
|
|
39
|
+
} while (0)
|
|
40
|
+
|
|
41
|
+
#define JUB_UNREFERENCED_PARAMETER(P) (P)
|
|
42
|
+
|
|
43
|
+
//template <class _Ty, size_t _Size>
|
|
44
|
+
//constexpr size_t array_size(const _Ty (&)[_Size]) noexcept {
|
|
45
|
+
// return (_Size);
|
|
46
|
+
//}
|
|
47
|
+
//
|
|
48
|
+
/*
|
|
49
|
+
* String splitting function
|
|
50
|
+
*/
|
|
51
|
+
//std::vector<std::string> Split(std::string str, std::string pattern);
|
|
52
|
+
/*
|
|
53
|
+
* Merge string function
|
|
54
|
+
*//*
|
|
55
|
+
std::string Join(std::vector<std::string> v, std::string pattern);
|
|
56
|
+
*/
|
|
57
|
+
/*
|
|
58
|
+
* Decimal string conversion -> Hexadecimal string
|
|
59
|
+
*/
|
|
60
|
+
//std::string DecStringToHexString(std::string str);
|
|
61
|
+
//
|
|
62
|
+
//std::string numberToHexString(unsigned int val);
|
|
63
|
+
//
|
|
64
|
+
/*
|
|
65
|
+
* char array<uint8_t, 32> -> Hexadecimal string conversion
|
|
66
|
+
*//*
|
|
67
|
+
std::string CharArray2HexStr(std::array<uint8_t, 32> v);
|
|
68
|
+
*/
|
|
69
|
+
/*
|
|
70
|
+
* Hexadecimal string conversion -> char array<uint8_t, 32>
|
|
71
|
+
*//*
|
|
72
|
+
std::array<uint8_t, 32> HexStr2CharArray(std::string str);
|
|
73
|
+
*/
|
|
74
|
+
/*
|
|
75
|
+
* std::vector<unsigned char> -> Hexadecimal string conversion
|
|
76
|
+
*/
|
|
77
|
+
//std::string CharPtr2HexStr(std::vector<unsigned char> v);
|
|
78
|
+
//
|
|
79
|
+
/*
|
|
80
|
+
* Hexadecimal string conversion -> std::vector<unsigned char>
|
|
81
|
+
*/
|
|
82
|
+
//std::vector<unsigned char> HexStr2CharPtr(std::string str);
|
|
83
|
+
/*
|
|
84
|
+
// Put an array of strings into a vector
|
|
85
|
+
std::vector<std::string> CharPtrArr2StrVector(const char* Arr[]);
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
//#define ETH_PRDFIX "0x"
|
|
89
|
+
/*
|
|
90
|
+
* std::vector<unsigned char> -> Hexadecimal string conversion
|
|
91
|
+
*//*
|
|
92
|
+
std::string ETHCharPtr2HexStr(std::vector<unsigned char> v);
|
|
93
|
+
*/
|
|
94
|
+
/*
|
|
95
|
+
* Hexadecimal string conversion -> std::vector<unsigned char>
|
|
96
|
+
*/
|
|
97
|
+
//std::vector<unsigned char> ETHHexStr2CharPtr(std::string str);
|
|
98
|
+
//
|
|
99
|
+
//TW::Data ToTlv(uint8_t tag, const TW::Data &data);
|
|
100
|
+
//std::vector<TW::Data> ParseTlv(const TW::Data &data);
|
|
101
|
+
//TW::Data Tollv(const std::string& strData);
|
|
102
|
+
} // namespace jub
|
|
103
|
+
|
|
104
|
+
#endif
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <map>
|
|
3
|
+
|
|
4
|
+
template<typename pI, typename T, typename F>
|
|
5
|
+
class xFactory {
|
|
6
|
+
|
|
7
|
+
protected:
|
|
8
|
+
typedef std::map<T, F> FactoryMap;
|
|
9
|
+
FactoryMap m_FactoryMap;
|
|
10
|
+
|
|
11
|
+
public:
|
|
12
|
+
~xFactory() { m_FactoryMap.clear(); }
|
|
13
|
+
|
|
14
|
+
void Register(const T & name, F pfnCreate) {
|
|
15
|
+
m_FactoryMap[name] = pfnCreate;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
template<typename... Args>
|
|
19
|
+
pI Create(const T &name, Args&&... args) {
|
|
20
|
+
auto it = m_FactoryMap.find(name);
|
|
21
|
+
if (it != m_FactoryMap.end()) {
|
|
22
|
+
return it->second(std::forward<Args>(args)...);
|
|
23
|
+
}
|
|
24
|
+
return nullptr;
|
|
25
|
+
}
|
|
26
|
+
}; // class xFactory end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#ifndef __xManager__
|
|
3
|
+
#define __xManager__
|
|
4
|
+
|
|
5
|
+
#include "JUB_SDK.h"
|
|
6
|
+
|
|
7
|
+
#include <map>
|
|
8
|
+
|
|
9
|
+
template <class T>
|
|
10
|
+
class xManager {
|
|
11
|
+
public:
|
|
12
|
+
xManager() {
|
|
13
|
+
_ID = 0;
|
|
14
|
+
_last = nullptr;
|
|
15
|
+
};
|
|
16
|
+
~xManager() {
|
|
17
|
+
ClearAll();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
JUB_UINT16 AddOne(T* x) {
|
|
21
|
+
//srand((unsigned int)(time(NULL)));
|
|
22
|
+
//JUB_UINT16 ID = rand();
|
|
23
|
+
if (65535 == _ID) {
|
|
24
|
+
_ID = 0;
|
|
25
|
+
}
|
|
26
|
+
//JUB_UINT16 ID = ++_ID;
|
|
27
|
+
|
|
28
|
+
//std::cout << "Add ID:" << ID << std::endl;
|
|
29
|
+
_mapList.insert(std::make_pair(++_ID, x));
|
|
30
|
+
return _ID;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
JUB_UINT16 AddOne(JUB_UINT16 ID, T* x) {
|
|
34
|
+
_mapList.insert(std::make_pair(ID, x));
|
|
35
|
+
|
|
36
|
+
return ID;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
T* GetLast() {
|
|
40
|
+
return _last;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
void ClearLast() { _last = nullptr; };
|
|
44
|
+
|
|
45
|
+
void ClearOne(JUB_UINT16 ID) {
|
|
46
|
+
//std::cout << "Clear ID:" << ID << std::endl;
|
|
47
|
+
auto it = _mapList.find(ID);
|
|
48
|
+
if (it != _mapList.end()) {
|
|
49
|
+
delete it->second;
|
|
50
|
+
_mapList.erase(it);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void ClearAll() {
|
|
55
|
+
for (auto it : _mapList) {
|
|
56
|
+
delete it.second;
|
|
57
|
+
}
|
|
58
|
+
_mapList.clear();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
T* GetOne(JUB_UINT16 ID) {
|
|
62
|
+
auto it = _mapList.find(ID);
|
|
63
|
+
if (it != _mapList.end()) {
|
|
64
|
+
_last = it->second;
|
|
65
|
+
return it->second;
|
|
66
|
+
}
|
|
67
|
+
return nullptr;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
std::vector<JUB_UINT16> GetHandleList() {
|
|
71
|
+
std::vector<JUB_UINT16> vHandleList;
|
|
72
|
+
for (auto it : _mapList) {
|
|
73
|
+
vHandleList.push_back(it.first);
|
|
74
|
+
}
|
|
75
|
+
return vHandleList;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected:
|
|
79
|
+
std::map<JUB_UINT16, T*> _mapList;
|
|
80
|
+
T* _last;
|
|
81
|
+
JUB_UINT16 _ID;
|
|
82
|
+
}; // class xManager end
|
|
83
|
+
|
|
84
|
+
#endif
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|