forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallCertificate.cpp
More file actions
85 lines (66 loc) · 2.56 KB
/
InstallCertificate.cpp
File metadata and controls
85 lines (66 loc) · 2.56 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
74
75
76
77
78
79
80
81
82
83
84
85
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/InstallCertificate.h>
#if MO_ENABLE_CERT_MGMT
#include <MicroOcpp/Model/Certificates/CertificateService.h>
#include <MicroOcpp/Debug.h>
using MicroOcpp::Ocpp201::InstallCertificate;
using MicroOcpp::JsonDoc;
InstallCertificate::InstallCertificate(CertificateService& certService) : MemoryManaged("v201.Operation.", "InstallCertificate"), certService(certService) {
}
void InstallCertificate::processReq(JsonObject payload) {
if (!payload.containsKey("certificateType") ||
!payload.containsKey("certificate")) {
errorCode = "FormationViolation";
return;
}
InstallCertificateType certificateType;
const char *certificateTypeCstr = payload["certificateType"] | "_Invalid";
if (!strcmp(certificateTypeCstr, "V2GRootCertificate")) {
certificateType = InstallCertificateType_V2GRootCertificate;
} else if (!strcmp(certificateTypeCstr, "MORootCertificate")) {
certificateType = InstallCertificateType_MORootCertificate;
} else if (!strcmp(certificateTypeCstr, "CSMSRootCertificate")) {
certificateType = InstallCertificateType_CSMSRootCertificate;
} else if (!strcmp(certificateTypeCstr, "ManufacturerRootCertificate")) {
certificateType = InstallCertificateType_ManufacturerRootCertificate;
} else {
errorCode = "FormationViolation";
return;
}
if (!payload["certificate"].is<const char*>()) {
errorCode = "FormationViolation";
return;
}
const char *certificate = payload["certificate"];
auto certStore = certService.getCertificateStore();
if (!certStore) {
errorCode = "NotSupported";
return;
}
auto status = certStore->installCertificate(certificateType, certificate);
switch (status) {
case InstallCertificateStatus_Accepted:
this->status = "Accepted";
break;
case InstallCertificateStatus_Rejected:
this->status = "Rejected";
break;
case InstallCertificateStatus_Failed:
this->status = "Failed";
break;
default:
MO_DBG_ERR("internal error");
errorCode = "InternalError";
return;
}
//operation executed successfully
}
std::unique_ptr<JsonDoc> InstallCertificate::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
payload["status"] = status;
return doc;
}
#endif //MO_ENABLE_CERT_MGMT