Commit 5c3efc3e authored by garciay's avatar garciay
Browse files

Start validation of TD_AUTO_IOT_DENM_RWW_BV_01

parent 9b3966a9
......@@ -2,6 +2,8 @@
#include "CodecPer.hh"
#include <TTCN3.hh>
extern "C" {
static int asn1c_collect_encoded_data(const void *buffer, size_t size, void *application_specific_key)
{
......
#include <memory>
#include "LibItsCam_EncdecDeclarations.hh"
#include "CAMCodec.hh"
......
#include <memory>
#include "LibItsDenm_EncdecDeclarations.hh"
#include "DENMCodec.hh"
......
#include <memory>
#include "LibItsIvim_EncdecDeclarations.hh"
#include "IVIMCodec.hh"
......
#include <memory>
#include "LibItsMapemSpatem_EncdecDeclarations.hh"
#include "MapemCodec.hh"
......
#include <memory>
#include "LibItsSremSsem_EncdecDeclarations.hh"
#include "SremCodec.hh"
......
......@@ -74,8 +74,8 @@ namespace LibItsSecurity__Functions
OCTETSTRING os(r_sig.size(), r_sig.data());
// loggers::get_instance().log_to_hexa("r_sig= ", os);
// loggers::get_instance().log_to_hexa("s_sig= ", OCTETSTRING(s_sig.size(), s_sig.data());
// loggers::get_instance().log_to_hexa("sig= ", os += OCTETSTRING(s_sig.size(), s_sig.data()));
os += OCTETSTRING(s_sig.size(), s_sig.data());
// loggers::get_instance().log_to_hexa("sig= ", os);
return os;
}
......@@ -108,8 +108,8 @@ namespace LibItsSecurity__Functions
OCTETSTRING os(r_sig.size(), r_sig.data());
// loggers::get_instance().log_to_hexa("r_sig= ", os);
// loggers::get_instance().log_to_hexa("s_sig= ", OCTETSTRING(s_sig.size(), s_sig.data());
// loggers::get_instance().log_to_hexa("sig= ", os += OCTETSTRING(s_sig.size(), s_sig.data()));
os += OCTETSTRING(s_sig.size(), s_sig.data());
// loggers::get_instance().log_to_hexa("sig= ", os);
return os;
}
......@@ -140,10 +140,10 @@ namespace LibItsSecurity__Functions
std::vector<unsigned char> s_sig;
if (k.sign(hashData, r_sig, s_sig) == 0) {
OCTETSTRING os(r_sig.size(), r_sig.data());
loggers::get_instance().log_to_hexa("fx__signWithEcdsaBrainpoolp384WithSha384: r_sig= ", os);
loggers::get_instance().log_to_hexa("fx__signWithEcdsaBrainpoolp384WithSha384: s_sig= ", OCTETSTRING(s_sig.size(), s_sig.data()));
loggers::get_instance().log_to_hexa("fx__signWithEcdsaBrainpoolp384WithSha384: sig= ", os += OCTETSTRING(s_sig.size(), s_sig.data()));
//loggers::get_instance().log_to_hexa("fx__signWithEcdsaBrainpoolp384WithSha384: r_sig= ", os);
//loggers::get_instance().log_to_hexa("fx__signWithEcdsaBrainpoolp384WithSha384: s_sig= ", OCTETSTRING(s_sig.size(), s_sig.data()));
os += OCTETSTRING(s_sig.size(), s_sig.data());
//loggers::get_instance().log_to_hexa("fx__signWithEcdsaBrainpoolp384WithSha384: sig= ", os);
return os;
}
......
......@@ -10,7 +10,6 @@
*/
#pragma once
#include "loggers.hh" // TODO To be removed
#include "Params.hh"
class OCTETSTRING; //! Declare TITAN class
......@@ -35,14 +34,14 @@ public: //! \publicsection
* \brief Default constructor
* \todo Remove logs
*/
Codec() : _params(nullptr) { loggers::get_instance().log("Codec::Codec"); };
Codec() : _params(nullptr) { };
/*!
* \fn ~Codec();
* \brief Default destructor
* \virtual
* \todo Remove logs
*/
virtual ~Codec() { loggers::get_instance().log("Codec::~Codec"); };
virtual ~Codec() { };
/*!
* \fn int encode(const TPDUEnc& msg, OCTETSTRING& data);
* \brief Encode typed message into an octet string
......
#ifndef CODECOER_H
#define CODECOER_H
#include "loggers.hh" // TODO To be removed
#include "Params.hh"
class OCTETSTRING;
......
......@@ -16,7 +16,6 @@
#include <algorithm>
#include "Params.hh"
#include "loggers.hh"
class OCTETSTRING; //! Declare TITAN class
class BITSTRING; //! Declare TITAN class
......@@ -40,7 +39,7 @@ public:
* Create a new instance of the Layer class
* \todo Remove logs
*/
Layer() : upperLayers(), lowerLayers(), type(std::string("")) { loggers::get_instance().log("Layer::Layer (D)"); };
Layer() : upperLayers(), lowerLayers(), type(std::string("")) { };
/*!
* \brief Specialized constructor
......@@ -49,14 +48,13 @@ public:
* \see LayerFactory
* \todo Remove logs
*/
Layer(const std::string& p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())) { loggers::get_instance().log("Layer::Layer"); };
Layer(const std::string& p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())) { };
/*!
* \brief Default destructor
* \todo Remove logs
*/
virtual ~Layer() {
loggers::get_instance().log("Layer::~Layer");
// Double linked list, only remove layers in lowerLayers from the lowest one
std::for_each(lowerLayers.rbegin(), lowerLayers.rend(), [](Layer* it) { delete it; } );
lowerLayers.clear();
......@@ -68,7 +66,7 @@ public:
* \brief Delete this layer
* \todo Remove logs
*/
void deleteLayer() { loggers::get_instance().log("Layer::deleteLayer"); };
void deleteLayer() { };
public: //! \publicsection
/*!
......@@ -79,11 +77,8 @@ public: //! \publicsection
* \todo Remove logs
*/
inline void addUpperLayer(Layer* p_layer) {
//loggers::get_instance().log(">>> Layer::addUpperLayer");
if (p_layer != NULL) {
loggers::get_instance().log("Layer::addUpperLayer: %s is upper layer of %s", p_layer->to_string().c_str(), to_string().c_str());
upperLayers.push_back(p_layer);
loggers::get_instance().log(" Layer::addUpperLayer: %s is lower layer of %s", to_string().c_str(), p_layer->to_string().c_str());
p_layer->lowerLayers.push_back(this);
};
};
......@@ -105,7 +100,7 @@ public: //! \publicsection
* \todo Remove the logs
* \virtual
*/
virtual void sendData(OCTETSTRING& p_data, Params& p_params) { loggers::get_instance().log("Layer::sendData"); };
virtual void sendData(OCTETSTRING& p_data, Params& p_params) { };
/*!
* \virtual
......@@ -116,7 +111,7 @@ public: //! \publicsection
* \todo Remove the logs
* \virtual
*/
virtual void receiveData(OCTETSTRING& p_data, Params& p_params) { loggers::get_instance().log("Layer::receiveData"); }
virtual void receiveData(OCTETSTRING& p_data, Params& p_params) { }
/*!
* \virtual
......@@ -127,7 +122,7 @@ public: //! \publicsection
* \todo Remove the logs
* \virtual
*/
virtual OCTETSTRING trigger_ac_event(OCTETSTRING& p_data, Params& p_params) { loggers::get_instance().log("Layer::trigger_ac_event"); return int2oct(0, 2); }
//virtual OCTETSTRING trigger_ac_event(OCTETSTRING& p_data, Params& p_params) { return int2oct(0, 2); }
/*!
* \inline
......@@ -139,7 +134,6 @@ public: //! \publicsection
protected:
inline void toAllLayers(std::vector<Layer*>&layers, OCTETSTRING& data, Params& params) {
//loggers::get_instance().log(">>> Layer::toAllLayer: %d", layers.size());
for (std::vector<Layer*>::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) {
Layer * p = *it;
p->receiveData(data, params); // FIXME BUG I
......@@ -147,19 +141,15 @@ protected:
};
inline void receiveToAllLayers(OCTETSTRING& data, Params& params) {
//loggers::get_instance().log(">>> Layer::receiveToAllLayers: %d", upperLayers.size());
for (std::vector<Layer*>::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) {
Layer * p = *it;
//loggers::get_instance().log("Layer::receiveToAllLayers: call Layer::receiveData for %s", p->to_string().c_str());
p->receiveData(data, params);
} // End of 'for' statement
};
inline void sendToAllLayers(OCTETSTRING& data, Params& params) {
//loggers::get_instance().log(">>> Layer::sendToAllLayers: %d", lowerLayers.size());
for (std::vector<Layer*>::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) {
Layer * p = *it;
//loggers::get_instance().log("Layer::sendToAllLayers: call Layer::sendData for %s", p->to_string().c_str());
p->sendData(data, params);
} // End of 'for' statement
};
......
#ifndef CODECPER_H
#define CODECPER_H
#include "loggers.hh" // TODO To be removed
#include "Params.hh"
class OCTETSTRING;
class CHARSTRING;
class BITSTRING;
class TTCN_Buffer;
class TTCN_EncDec;
class TTCN_Typedescriptor_t;
struct asn_TYPE_descriptor_s;
class ASN1RecodePer
class ASN1RecodePer // FIXME Move into file ASN1RecodePer.hh
{
protected:
int ber2per (const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf);
......@@ -17,36 +20,18 @@ protected:
int recode (const asn_TYPE_descriptor_s & td, int from, int to, TTCN_Buffer & buf);
};
template<typename TPDU> class PERCodec : public ASN1RecodePer
template<typename TPDU>
class PERCodec : public ASN1RecodePer
{
public:
virtual int encode(const TPDU& msg, BITSTRING& bits) = 0;
virtual int decode(const BITSTRING& bits, TPDU& msg) = 0;
protected:
inline int _decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg) {
TTCN_Buffer buf(bit2oct(p_data));
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
int rc = per2ber (td, buf);
if (rc > 0) {
msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);
rc = buf.get_len();
}
return rc;
}
inline int _encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data) {
int rc = -1;
TTCN_Buffer buf;
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
if (buf.get_len() > 0) {
rc = ber2per (td, buf);
if (rc > 0) {
p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data()));
}
}
return rc;
}
};
int _decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg);
int _encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data);
}; // End of class PERCodec
#include "PERCodec.t.hh"
#endif
#include "CodecPer.hh"
#include <TTCN3.hh>
template<class TPDU>
int PERCodec<TPDU>::_decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg) {
TTCN_Buffer buf(bit2oct(p_data));
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
int rc = per2ber (td, buf);
if (rc > 0) {
msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);
rc = buf.get_len();
}
return rc;
}
template<class TPDU>
int PERCodec<TPDU>::_encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data) {
int rc = -1;
TTCN_Buffer buf;
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
if (buf.get_len() > 0) {
rc = ber2per (td, buf);
if (rc > 0) {
p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data()));
}
}
return rc;
}
......@@ -19,15 +19,14 @@ template <typename TPort> class TLayer : public Layer {
TPortList upperPorts;
public:
TLayer() : Layer(), upperPorts() { loggers::get_instance().log("TLayer::TLayer (D)"); };
TLayer(const std::string& p_type) : Layer(p_type), upperPorts() { loggers::get_instance().log("TLayer::TLayer"); };
TLayer() : Layer(), upperPorts() { };
TLayer(const std::string& p_type) : Layer(p_type), upperPorts() { };
void addUpperPort(TPort * p_port) { upperPorts.push_back(p_port); };
void removeUpperPort(TPort*);
protected:
template <typename TMessage>
inline void toAllUpperPorts(const TMessage& m, const Params& param) {
//loggers::get_instance().log(">>> TLayer::toAllUpperPorts: %d", upperPorts.size());
for(TPortListIterator it=upperPorts.begin(); it<upperPorts.end(); ++it){
(*it)->receiveMsg(m, param);
}
......
#pragma once
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <cctype>
#include <climits> // LONG_MAX, LLONG_MAX
#include <ctime> // time_t, struct tm, difftime, time, mktime
/*!
* \class converter
* \brief This class provide a set of metthods for types convertions
* \remark Singleton pattern
*/
class converter {
/*!
* \brief Unique static object reference of this class
*/
static converter * instance;
/*!
* \brief Default private ctor
*/
converter() {};
/*!
* \brief Default private dtor
*/
~converter() {
if (instance != NULL) {
delete instance;
instance = NULL;
}
};
public: /*! \publicsection */
/*!
* \brief Public accessor to the single object reference
*/
inline static converter & get_instance() {
if (instance == NULL) instance = new converter();
return *instance;
};
public:
/*!
* \enum endian_t
* \brief Endianess style
*/
typedef enum {
big_endian,
little_endian
} endian_t;
public:
/*!
* \brief Convert a Binary Coded Decimal value into a binary value
* \param[in] p_value The BDC value
* \return The binary value
* \inline
*/
inline uint8_t bcd_to_bin(const uint8_t p_value) {
return ((p_value / 16 * 10) + (p_value % 16));
};
/*!
* \brief Convert a binary value into a Binary Coded Decimal value
* \param[in] p_value The binary value
* \return The BCD value
* \inline
*/
inline uint8_t bin_to_bcd(const uint8_t p_value) {
return ((p_value / 10 * 16) + (p_value % 10));
};
/*!
* \brief Swap two bytes length value (e.g. 0xCAFE becomes 0xFECA)
* \param[in] p_value The value to swap
* \return The swapped value
* \inline
*/
uint16_t swap(const uint16_t p_value);
inline int16_t swap(const int16_t p_value) {
return static_cast<short>(swap(static_cast<uint16_t>(p_value)));
};
/*!
* \brief Swap four bytes length value (used for littel endian / big endian)
* \param[in] p_value The value to swap
* \return The swapped value
*/
uint32_t swap(const uint32_t p_value);
inline int32_t swap(const int32_t p_value) {
return static_cast<int>(swap(static_cast<uint32_t>(p_value)));
};
/*!
* \brief Convert a string into an hexadecimal string
* \param[in] p_value The string value
* \return The hexadecimal value
*/
std::string string_to_hexa(const std::string & p_value);
/*!
* \brief Convert a bytes array int32_t an hexadecimal string
* \param[in] p_value The bytes array value
* \return The hexadecimal value
*/
std::string bytes_to_hexa(const std::vector<uint8_t> & p_value);
/*!
* \brief Convert an hexadecimal string into a bytes array
* \param[in] p_value The hexadecimal value
* \return The bytes array value
*/
std::vector<uint8_t> hexa_to_bytes(const std::string & p_value);
/*!
* \brief Convert a time in time_t format into a string formated according to RFC 822, 1036, 1123, 2822
* \param[in] p_time The time to convert in time_t format
* \return The time string formated
* \see http://www.unixtimestamp.com/
* @code
* std::string result = time_to_string(1489755780);
* result.compare("Fri, 17 Mar 2017 13:03:00 +0000") == 0 // When time zone is set to UTC
* @endcode
* \remark Use commands 1) timedatectl to change your machine timezone (e.g. sudo timedatectl set-timezone UTC to change machine timezone to UTC, 2) timedatectl list-timezones to get the list of the timezones)
*/
std::string time_to_string(const time_t p_time);
/*!
* \brief Convert a time in struct tm format into a string formated according to RFC 822, 1036, 1123, 2822
* \param[in] p_time The time to convert in struct tm format
* \return The time string formated
* \see http://www.unixtimestamp.com/
*/
std::string time_to_string(const struct tm & p_time);
/*!
* \brief Convert a 16-bits integer (int16_t) into a bytes array
* \param[in] p_value The 16-bits integer value
* \param[in] p_endianess Endianess style. Default: big_endian
* \return The bytes array value
*/
inline std::vector<uint8_t> short_to_bytes(const int16_t p_value, const endian_t p_endianess = big_endian) const {
std::vector<uint8_t> result(sizeof(short), 0x00);
for (int i = sizeof(short) - 1; i >= 0; i--) {
int offset = (sizeof(short) - 1 - i) * 8;
result[i] = static_cast<uint8_t>((p_value >> offset) & 0xFF);
} // End of 'for' statement
return result;
}; // End of short_to_bytes
/*!
* \brief Convert a bytes array into a 16-bits integer (int16_t)
* \param[in] p_value The bytes array
* \param[in] p_endianess Endianess style. Default: big_endian
* \return The 16-bits integer on success, SHRT_MAX on error (wrong bytes array size)
*/
inline int16_t bytes_to_short(const std::vector<uint8_t> & p_value, const endian_t p_endianess = big_endian) const {
// Sanity check
if (p_value.size() > sizeof(short)) {
return SHRT_MAX;
}
int16_t value = 0;
for (size_t i = 0; i < p_value.size(); i++) {
value = (value << 8) + (p_value[i] & 0xff);
} // End of 'for' statement
return value;
}; // End of bytes_to_short
/*!
* \brief Convert a 32-bits integer (int32_t) into a bytes array
* \param[in] p_value The 32-bits integer value
* \param[in] p_endianess Endianess style. Default: big_endian
* \return The bytes array value
*/
inline std::vector<uint8_t> int_to_bytes(const int32_t p_value, const endian_t p_endianess = big_endian) const {
/*uint8_t bytes[sizeof(p_value)];
std::copy(
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)),
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)) + sizeof(p_value),
bytes
);
std::vector<uint8_t> result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t));*/
std::vector<uint8_t> result(sizeof(int), 0x00);
for (int i = sizeof(int) - 1; i >= 0; i--) {
int offset = (sizeof(int) - 1 - i) * 8;
result[i] = static_cast<uint8_t>((p_value >> offset) & 0xFF);
} // End of 'for' statement
return result;
}; // End of int_to_bytes
/*!
* \brief Convert a bytes array into a 32-bits integer (int32_t)
* \param[in] p_value The bytes array
* \param[in] p_endianess Endianess style. Default: big_endian
* \return The 32-bits integer on success, LONG_MAX on error (wrong bytes array size)
*/
inline int32_t bytes_to_int(const std::vector<uint8_t> & p_value, const endian_t p_endianess = big_endian) const {
// Sanity check
if (p_value.size() > sizeof(int)) {
return INT_MAX;
}
int32_t value = 0;
for (size_t i = 0; i < p_value.size(); i++) {
value = (value << 8) + (p_value[i] & 0xff);
} // End of 'for' statement
return value;
// return *((int *)(&p_value[0]));
}; // End of bytes_to_int
/*!
* \brief Convert a 64-bits integer (int64_t) into a bytes array
* \param[in] p_value The 64-bits integer value
* \param[in] p_endianess Endianess style. Default: big_endian
* \return The bytes array value
*/
inline std::vector<uint8_t> long_to_bytes(const int64_t p_value, const endian_t p_endianess = big_endian) const {
/*uint8_t bytes[sizeof(p_value)];
std::copy(
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)),
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)) + sizeof(p_value),
bytes
);
std::vector<uint8_t> result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t));*/
std::vector<uint8_t> result(sizeof(int64_t), 0x00);
for (int i = sizeof(int64_t) - 1; i >= 0; i--) {
int offset = (sizeof(int64_t) - 1 - i) * 8;
result[i] = static_cast<uint8_t>((p_value >> offset) & 0xFF);
} // End of 'for' statement
return result;
}; // End of long_to_bytes
/*!
* \brief Convert a bytes array into a 64-bits integer (int64_t)
* \param[in] p_value The bytes array
* \param[in] p_endianess Endianess style. Default: big_endian
* \return The 64-bits integer on success, LLONG_MAX on error (wrong bytes array size)
*/
inline int64_t bytes_to_long(const std::vector<uint8_t> & p_value, const endian_t p_endianess = big_endian) const {
// Sanity check
if (p_value.size() > sizeof(int64_t)) {
return LLONG_MAX;
}
int64_t value = 0;
for (size_t i = 0; i < p_value.size(); i++) {
value = (value << 8) + (p_value[i] & 0xff);
} // End of 'for' statement
return value;
// return *((long *)(&p_value[0]));
}; // End of bytes_to_long
/*!
* \brief Convert a float value into a bytes array
* \param[in] p_value The float value
* \return The bytes array value
*/
inline std::vector<uint8_t> float_to_bytes(const float p_value) const {
uint8_t bytes[sizeof(p_value)];
std::copy(
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)),
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)) + sizeof(p_value),
bytes
);
std::vector<uint8_t> result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t));
return result;
}; // End of float_to_long
/*!
* \brief Convert a bytes array into a float
* \param[in] p_value The bytes array
* \return The float value