Skip to content

Commit 722f09b

Browse files
movhdiPietfried
andauthored
Fix bug in handleGetInstalledCertificateIdsRequest (#449)
* Fix bug in handleGetInstalledCertificateIdsRequest to prevent populating response with empty certificateHashData Signed-off-by: Mahdi Movahedi <m.movahedimonfared@gmail.com> Signed-off-by: pietfried <pietgoempel@gmail.com> Co-authored-by: pietfried <pietgoempel@gmail.com>
1 parent 38943d4 commit 722f09b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/ocpp/v16/charge_point_impl.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -2258,19 +2258,20 @@ void ChargePointImpl::handleGetInstalledCertificateIdsRequest(ocpp::Call<GetInst
22582258
if (call.msg.certificateType == CertificateUseEnumType::ManufacturerRootCertificate) {
22592259
certificate_types.push_back(ocpp::CertificateType::MFRootCertificate);
22602260
}
2261-
22622261
// this is common CertificateHashDataChain
22632262
const auto certificate_hash_data_chains = this->evse_security->get_installed_certificates(certificate_types);
2264-
// convert ocpp::CertificateHashData to v16::CertificateHashData
2265-
std::optional<std::vector<CertificateHashDataType>> certificate_hash_data_16_vec_opt;
2266-
std::vector<CertificateHashDataType> certificate_hash_data_16_vec;
2267-
for (const auto certificate_hash_data_chain_entry : certificate_hash_data_chains) {
2268-
certificate_hash_data_16_vec.push_back(
2269-
CertificateHashDataType(json(certificate_hash_data_chain_entry.certificateHashData)));
2270-
}
2271-
certificate_hash_data_16_vec_opt.emplace(certificate_hash_data_16_vec);
2272-
response.certificateHashData = certificate_hash_data_16_vec_opt;
2273-
response.status = GetInstalledCertificateStatusEnumType::Accepted;
2263+
if (!certificate_hash_data_chains.empty()) {
2264+
// convert ocpp::CertificateHashData to v16::CertificateHashData
2265+
std::optional<std::vector<CertificateHashDataType>> certificate_hash_data_16_vec_opt;
2266+
std::vector<CertificateHashDataType> certificate_hash_data_16_vec;
2267+
for (const auto certificate_hash_data_chain_entry : certificate_hash_data_chains) {
2268+
certificate_hash_data_16_vec.push_back(
2269+
CertificateHashDataType(json(certificate_hash_data_chain_entry.certificateHashData)));
2270+
}
2271+
certificate_hash_data_16_vec_opt.emplace(certificate_hash_data_16_vec);
2272+
response.certificateHashData = certificate_hash_data_16_vec_opt;
2273+
response.status = GetInstalledCertificateStatusEnumType::Accepted;
2274+
}
22742275

22752276
ocpp::CallResult<GetInstalledCertificateIdsResponse> call_result(response, call.uniqueId);
22762277
this->send<GetInstalledCertificateIdsResponse>(call_result);

0 commit comments

Comments
 (0)