Commit a8ed0785 authored by garciay's avatar garciay
Browse files

Validate secured messages codec

parent 6305bf76
......@@ -211,9 +211,14 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
* @param value to encode
* @return encoded value
****************************************************/
BITSTRING fx__enc__GnNonSecuredPacket(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& p)
BITSTRING fx__enc__GnNonSecuredPacket(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& p_gnNonSecuredPacket)
{
return int2bit(0,8);
loggers::get_instance().log_msg(">>> fx__enc__GnNonSecuredPacket: ", p_gnNonSecuredPacket);
GeoNetworkingCodec codec;
OCTETSTRING os;
codec.encode(p_gnNonSecuredPacket, os);
return oct2bit(os);
}
/****************************************************
......
......@@ -31,6 +31,28 @@ int GeoNetworkingCodec::encode (const LibItsGeoNetworking__TypesAndValues::GeoNe
return 0;
}
int GeoNetworkingCodec::encode (const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& p_gnNonSecuredPacket, OCTETSTRING& data)
{
loggers::get_instance().log_msg(">>> GeoNetworkingCodec::encode: ", (const Base_Type&)p_gnNonSecuredPacket);
TTCN_EncDec::clear_error();
TTCN_Buffer encoding_buffer;
encode_(p_gnNonSecuredPacket, *p_gnNonSecuredPacket.get_descriptor(), encoding_buffer);
data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
// Overwrite the payload length
if (_ec.length != (unsigned int)-1) {
loggers::get_instance().log("GeoNetworkingCodec::encode: length=%d - plLength_position = %d - plLength = %d", data.lengthof(), _ec.length_position, _ec.length);
unsigned char b[] = { (unsigned char)((_ec.length & 0x0000FF00) >> 8), (unsigned char)_ec.length };
OCTETSTRING rpl(sizeof(b), b);
loggers::get_instance().log_msg("GeoNetworkingCodec::encode: rpl=", rpl);
data = replace(data, _ec.length_position, rpl.lengthof(), rpl);
loggers::get_instance().log_msg("GeoNetworkingCodec::encode: after replace: ", data);
}
loggers::get_instance().log_msg("<<< GeoNetworkingCodec::encode: data=", data);
return 0;
}
int GeoNetworkingCodec::encode_ (const Base_Type& type, const TTCN_Typedescriptor_t& field_descriptor, TTCN_Buffer& encoding_buffer)
{
loggers::get_instance().log(">>> GeoNetworkingCodec::encode_: processing %s/%s", type.get_descriptor()->name, field_descriptor.name);
......
......@@ -11,6 +11,7 @@ class TTCN_Buffer;
namespace LibItsGeoNetworking__TypesAndValues {
class GeoNetworkingPdu;
class GnNonSecuredPacket;
class HeaderTST;
class ExtendedHeader;
class DecodedPayload;
......@@ -61,6 +62,8 @@ public:
virtual int encode (const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& msg, OCTETSTRING& data);
virtual int decode (const OCTETSTRING& data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& msg, Params* params = NULL);
int encode (const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& p_gnNonSecuredPacket, OCTETSTRING& data); // TODO Duplicate code with virtual encode, to be enhanced
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment