diff --git a/vanetza/security/v3/secured_message.cpp b/vanetza/security/v3/secured_message.cpp index 2e00e137a..0a68fbeb2 100644 --- a/vanetza/security/v3/secured_message.cpp +++ b/vanetza/security/v3/secured_message.cpp @@ -179,24 +179,29 @@ void SecuredMessage::set_generation_location(const asn1::ThreeDLocation& locatio void SecuredMessage::set_inline_p2pcd_request(std::list requests) { if (m_struct->content->present == Vanetza_Security_Ieee1609Dot2Content_PR_signedData) { - ASN_STRUCT_FREE_CONTENTS_ONLY( - asn_DEF_Vanetza_Security_SequenceOfHashedId3, - &(m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest) - ); + assert(m_struct->content->choice.signedData); + assert(m_struct->content->choice.signedData->tbsData); + + if (m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest) { + ASN_STRUCT_RESET(asn_DEF_Vanetza_Security_SequenceOfHashedId3, + &m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest); + } + for (HashedId3 request : requests) { this->add_inline_p2pcd_request(request); } } - } -void SecuredMessage::add_inline_p2pcd_request(HashedId3 unkown_certificate_digest) +void SecuredMessage::add_inline_p2pcd_request(HashedId3 unknown_certificate_digest) { if (m_struct->content->present == Vanetza_Security_Ieee1609Dot2Content_PR_signedData) { - if (m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest == nullptr) { + if (m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest == nullptr) { m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest = asn1::allocate(); } - ASN_SEQUENCE_ADD(&(m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest), &unkown_certificate_digest); + Vanetza_Security_HashedId3_t* asn_digest = OCTET_STRING_new_fromBuf(&asn_DEF_Vanetza_Security_HashedId3, + reinterpret_cast(unknown_certificate_digest.data()), unknown_certificate_digest.size()); + ASN_SEQUENCE_ADD(m_struct->content->choice.signedData->tbsData->headerInfo.inlineP2pcdRequest, asn_digest); } }