1 // Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "get_cert_request_handler.hh"
9 #include "database/cert_get_db_handler.hh"
10 #include "parcelable_factory.hh"
11 #include "utils/logging.hh"
13 #include "pkgmgrinfo_debug.h"
15 namespace pcp = pkgmgr_common::parcel;
16 namespace psd = pkgmgr_server::database;
18 namespace pkgmgr_server {
19 namespace request_handler {
21 bool GetCertRequestHandler::HandleRequest(const unsigned char* data, int size,
22 const std::string& locale) {
23 auto abstract_parcel =
24 pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
26 if (abstract_parcel == nullptr ||
27 abstract_parcel->GetType() != pcp::ParcelableType::CertInfo) {
28 LOG(ERROR) << "Invalid parcel or type";
29 result_ = std::make_shared<pcp::CertInfoParcelable>(
30 PMINFO_R_ERROR, nullptr);
34 auto* parcel = dynamic_cast<pcp::CertInfoParcelable*>(abstract_parcel.get());
35 if (parcel == nullptr) {
36 LOG(ERROR) << "Parcel is empty";
37 result_ = std::make_shared<pcp::CertInfoParcelable>(
38 PMINFO_R_ERROR, nullptr);
42 psd::CertGetDBHandler db(parcel->GetUid(), GetPID());
44 db.SetPkgID(parcel->GetPkgId());
46 int ret = db.Execute();
48 result_ = std::make_shared<pcp::CertInfoParcelable>(ret, db.GetCertHandle());
53 std::vector<uint8_t> GetCertRequestHandler::ExtractResult() {
54 tizen_base::Parcel parcel;
56 parcel.WriteParcelable(*result_);
57 std::vector<uint8_t> raw = parcel.GetRaw();
64 } // namespace request_handler
65 } // namespace pkgmgr_server