1 #ifndef ASN1_MESSAGE_H_
2 #define ASN1_MESSAGE_H_
3 #include <boost/intrusive_ptr.hpp>
5 #include "AKIpUptaneMes.h"
6 #include "AKTlsConfig.h"
13 Asn1Sub(boost::intrusive_ptr<Asn1Message> root, T* me) : root_(std::move(root)), me_(me) {}
15 T& operator*()
const {
16 assert(me_ !=
nullptr);
20 T* operator->()
const {
21 assert(me_ !=
nullptr);
26 boost::intrusive_ptr<Asn1Message> root_;
36 using Ptr = boost::intrusive_ptr<Asn1Message>;
55 ~
Asn1Message() { ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_AKIpUptaneMes, &
msg_); }
56 friend void intrusive_ptr_add_ref(
Asn1Message* m) { m->ref_count_++; }
58 if (--m->ref_count_ == 0) {
63 AKIpUptaneMes_PR present()
const {
return msg_.present; }
65 msg_.present = present;
69 #define ASN1_MESSAGE_DEFINE_ACCESSOR(MessageType, FieldName) \
70 SubPtr<MessageType> FieldName() { \
71 return Asn1Sub<MessageType>(this, &msg_.choice.FieldName); \
74 ASN1_MESSAGE_DEFINE_ACCESSOR(AKGetInfoReqMes_t, getInfoReq);
75 ASN1_MESSAGE_DEFINE_ACCESSOR(AKGetInfoRespMes_t, getInfoResp);
76 ASN1_MESSAGE_DEFINE_ACCESSOR(AKManifestReqMes_t, manifestReq);
77 ASN1_MESSAGE_DEFINE_ACCESSOR(AKManifestRespMes_t, manifestResp);
78 ASN1_MESSAGE_DEFINE_ACCESSOR(AKPutMetaReqMes_t, putMetaReq);
79 ASN1_MESSAGE_DEFINE_ACCESSOR(AKPutMetaRespMes_t, putMetaResp);
80 ASN1_MESSAGE_DEFINE_ACCESSOR(AKSendFirmwareReqMes_t, sendFirmwareReq);
81 ASN1_MESSAGE_DEFINE_ACCESSOR(AKSendFirmwareRespMes_t, sendFirmwareResp);
82 ASN1_MESSAGE_DEFINE_ACCESSOR(AKInstallReqMes_t, installReq);
83 ASN1_MESSAGE_DEFINE_ACCESSOR(AKInstallRespMes_t, installResp);
85 ASN1_MESSAGE_DEFINE_ACCESSOR(AKUploadDataReqMes_t, uploadDataReq);
86 ASN1_MESSAGE_DEFINE_ACCESSOR(AKUploadDataRespMes_t, uploadDataResp);
87 ASN1_MESSAGE_DEFINE_ACCESSOR(AKDownloadOstreeRevReqMes_t, downloadOstreeRevReq);
88 ASN1_MESSAGE_DEFINE_ACCESSOR(AKDownloadOstreeRevRespMes_t, downloadOstreeRevResp);
89 ASN1_MESSAGE_DEFINE_ACCESSOR(AKPutMetaReq2Mes_t, putMetaReq2);
90 ASN1_MESSAGE_DEFINE_ACCESSOR(AKPutMetaResp2Mes_t, putMetaResp2);
91 ASN1_MESSAGE_DEFINE_ACCESSOR(AKInstallResp2Mes_t, installResp2);
92 ASN1_MESSAGE_DEFINE_ACCESSOR(AKVersionReqMes_t, versionReq);
93 ASN1_MESSAGE_DEFINE_ACCESSOR(AKVersionRespMes_t, versionResp);
95 #define ASN1_MESSAGE_DEFINE_STR_NAME(MessageID) \
102 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_NOTHING);
103 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_getInfoReq);
104 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_getInfoResp);
105 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_manifestReq);
106 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_manifestResp);
107 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_putMetaReq);
108 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_putMetaResp);
109 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_sendFirmwareReq);
110 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_sendFirmwareResp);
111 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_installReq);
112 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_installResp);
114 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_uploadDataReq);
115 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_uploadDataResp);
116 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_downloadOstreeRevReq);
117 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_downloadOstreeRevResp);
118 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_putMetaReq2);
119 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_putMetaResp2);
120 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_installResp2);
121 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_versionReq);
122 ASN1_MESSAGE_DEFINE_STR_NAME(AKIpUptaneMes_PR_versionResp);
140 if (msg !=
nullptr && *msg !=
nullptr) {
141 memmove(&
msg_, *msg,
sizeof(AKIpUptaneMes_t));
151 int Asn1StringAppendCallback(
const void* buffer,
size_t size,
void* priv);
157 int Asn1SocketWriteCallback(
const void* buffer,
size_t size,
void* priv);
162 std::string ToString(
const OCTET_STRING_t& octet_str);
164 void SetString(OCTET_STRING_t* dest,
const std::string& str);
170 Asn1Message::Ptr Asn1Rpc(
const Asn1Message::Ptr& tx,
int con_fd);
171 Asn1Message::Ptr Asn1Rpc(
const Asn1Message::Ptr& tx,
const std::pair<std::string, uint16_t>& addr);
177 template <
typename T>
178 T* Asn1Allocation() {
179 auto ptr =
static_cast<T*
>(calloc(1,
sizeof(T)));
181 throw std::bad_alloc();
186 #endif // ASN1_MESSAGE_H_