forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdToken.cpp
More file actions
73 lines (60 loc) · 1.58 KB
/
Copy pathIdToken.cpp
File metadata and controls
73 lines (60 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Version.h>
#if MO_ENABLE_V201
#include <MicroOcpp/Model/Authorization/IdToken.h>
#include <string.h>
#include <stdio.h>
#include <MicroOcpp/Debug.h>
using namespace MicroOcpp;
IdToken::IdToken() {
idToken[0] = '\0';
}
IdToken::IdToken(const char *token, Type type) : type(type) {
auto ret = snprintf(idToken, MO_IDTOKEN_LEN_MAX + 1, "%s", token);
if (ret < 0 || ret >= MO_IDTOKEN_LEN_MAX + 1) {
MO_DBG_ERR("invalid token");
*idToken = '\0';
}
}
const char *IdToken::get() const {
return *idToken ? idToken : nullptr;;
}
const char *IdToken::getTypeCstr() const {
const char *res = nullptr;
switch (type) {
case Type::Central:
res = "Central";
break;
case Type::eMAID:
res = "eMAID";
break;
case Type::ISO14443:
res = "ISO14443";
break;
case Type::ISO15693:
res = "ISO15693";
break;
case Type::KeyCode:
res = "KeyCode";
break;
case Type::Local:
res = "Local";
break;
case Type::MacAddress:
res = "MacAddress";
break;
case Type::NoAuthorization:
res = "NoAuthorization";
break;
}
if (!res) {
MO_DBG_ERR("internal error");
}
return res ? res : "";
}
bool IdToken::equals(const IdToken& other) {
return type == other.type && !strcmp(idToken, other.idToken);
}
#endif // MO_ENABLE_V201