4 #define DEVICEID_BINLEN 12
5 #define DEVICEID_STRLEN 24
7 struct DeviceId_Bin_t {
8 DeviceId_Bin_t() : _data{} {}
9 void fromString(
const char * other);
10 String toString()
const;
11 uint8_t _data[DEVICEID_BINLEN];
14 void DeviceId_Bin_t::fromString(
const char* other) {
16 bool _isValid = (sscanf(other,
"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%c",
17 &_data[11], &_data[10], &_data[9], &_data[8], &_data[7], &_data[6], &_data[5], &_data[4],
18 &_data[3], &_data[2], &_data[1], &_data[0],
20 ) ==
sizeof(_data)) && (strlen(other) == DEVICEID_STRLEN);
21 if (!_isValid) memset((
void*) &_data, 0,
sizeof(_data));
24 String DeviceId_Bin_t::toString()
const {
25 char temp[DEVICEID_STRLEN+1];
26 sprintf(temp,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
27 _data[11], _data[10], _data[9], _data[8], _data[7], _data[6], _data[5], _data[4],
28 _data[3], _data[2], _data[1], _data[0]
34 #define APPKEY_BINLEN 16
35 #define APPKEY_STRLEN 36
38 AppKey_Bin_t() : _data{} {}
39 void fromString(
const char * other);
40 String toString()
const;
41 uint8_t _data[APPKEY_BINLEN];
44 void AppKey_Bin_t::fromString(
const char* other) {
46 bool _isValid = (sscanf(other,
"%2hhx%2hhx%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%c",
47 &_data[15], &_data[14], &_data[13], &_data[12], &_data[11], &_data[10], &_data[9], &_data[8],
48 &_data[7], &_data[6], &_data[5], &_data[4], &_data[3], &_data[2], &_data[1], &_data[0],
50 ) ==
sizeof(_data)) && (strlen(other) == APPKEY_STRLEN);
51 if (!_isValid) memset((
void*) &_data, 0,
sizeof(_data));
54 String AppKey_Bin_t::toString()
const {
55 char temp[APPKEY_STRLEN+1];
56 sprintf(temp,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
57 _data[15], _data[14], _data[13], _data[12], _data[11], _data[10], _data[9], _data[8],
58 _data[7], _data[6], _data[5], _data[4], _data[3], _data[2], _data[1], _data[0]
63 #define APPSECRET_BINLEN 32
64 #define APPSECRET_STRLEN 73
66 struct AppSecret_Bin_t {
67 AppSecret_Bin_t() : _data{} {}
68 void fromString(
const char * other);
69 String toString()
const;
70 uint8_t _data[APPSECRET_BINLEN];
73 void AppSecret_Bin_t::fromString(
const char* other) {
75 bool _isValid = (sscanf(other,
"%2hhx%2hhx%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%c",
76 &_data[31], &_data[30], &_data[29], &_data[28], &_data[27], &_data[26], &_data[25], &_data[24],
77 &_data[23], &_data[22], &_data[21], &_data[20], &_data[19], &_data[18], &_data[17], &_data[16],
78 &_data[15], &_data[14], &_data[13], &_data[12], &_data[11], &_data[10], &_data[ 9], &_data[ 8],
79 &_data[ 7], &_data[ 6], &_data[ 5], &_data[ 4], &_data[ 3], &_data[ 2], &_data[ 1], &_data[ 0],
81 ) ==
sizeof(_data)) && (strlen(other) == APPSECRET_STRLEN);
82 if (!_isValid) memset((
void*) &_data, 0,
sizeof(_data));
85 String AppSecret_Bin_t::toString()
const {
86 char temp[APPSECRET_STRLEN+1];
87 sprintf(temp,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
88 _data[31], _data[30], _data[29], _data[28], _data[27], _data[26], _data[25], _data[24],
89 _data[23], _data[22], _data[21], _data[20], _data[19], _data[18], _data[17], _data[16],
90 _data[15], _data[14], _data[13], _data[12], _data[11], _data[10], _data[ 9], _data[ 8],
91 _data[ 7], _data[ 6], _data[ 5], _data[ 4], _data[ 3], _data[ 2], _data[ 1], _data[ 0]
99 SinricProId() : _data() {};
100 SinricProId(
const char* other) { _data.fromString(other); }
101 SinricProId(
const String &other) { _data.fromString(other.c_str()); }
102 SinricProId(
const SinricProId &other) { copy(other); }
103 SinricProId(
const T &other) { copy(other); }
104 SinricProId(
const uint8_t other[],
size_t size) { copy(other, size); }
106 SinricProId operator=(
const SinricProId &other) { copy(other);
return *
this; }
107 SinricProId operator=(
const char* other) { fromString(other);
return *
this; }
108 SinricProId operator=(
const String &other) { fromString(other.c_str());
return *
this; }
109 SinricProId operator=(
const T &other) { copy(other); }
111 bool operator==(
const SinricProId &other)
const {
return compare(other); }
112 bool operator==(
const char* other)
const {
return compare((SinricProId) other); }
113 bool operator==(
const String& other)
const {
return compare((SinricProId) other); }
114 bool operator==(
const T &other)
const {
return compare((SinricProId) other); }
116 bool operator!=(
const SinricProId &other)
const {
return !compare(other); }
117 bool operator!=(
const char* other)
const {
return !compare(other); }
118 bool operator!=(
const String &other)
const {
return !compare(other); }
119 bool operator!=(
const T &other)
const {
return !compare(other); }
121 operator bool()
const {
return isValid(); }
122 operator String()
const {
return _data.toString(); }
124 String toString()
const {
return _data.toString(); };
125 const char* c_str()
const {
static String str = _data.toString();
return str.c_str(); }
126 bool isValid()
const {
return !compare(SinricProId<T>()); }
129 void fromString(
const char * other) { _data.fromString(other); }
130 void copy(
const SinricProId &other) { memcpy(_data._data, other._data._data,
sizeof(_data._data)); }
131 void copy(
const T &other) { memcpy(_data, other,
sizeof(_data)); }
132 void copy(
const uint8_t other[],
size_t size) { memcpy(_data._data, other, min(
sizeof(_data._data), size)); }
133 bool compare(
const SinricProId &other)
const {
return memcmp(_data._data, other._data._data,
sizeof(_data._data)) == 0;}
137 typedef SinricProId<DeviceId_Bin_t> DeviceId;
138 typedef SinricProId<AppKey_Bin_t> AppKey;
139 typedef SinricProId<AppSecret_Bin_t> AppSecret;