Keep the colleague's microbu-esp32c5 tree in this repository
obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
include(UseGTest)
|
||||
configure_gtest_directory(LINK_LIBRARIES asn1)
|
||||
|
||||
add_gtest(asn1c_wrapper asn1c_wrapper.cpp)
|
||||
add_gtest(Cpm SOURCES cpm.cpp)
|
||||
add_gtest(ItsAsn1 SOURCES its.cpp)
|
||||
add_gtest(ItsAsn1Rel2 SOURCES its_r2.cpp LINK_LIBRARIES asn1_its_r2)
|
||||
add_gtest(PacketVisitor SOURCES packet_visitor.cpp LINK_LIBRARIES net)
|
||||
add_gtest(SecurityAsn1 SOURCES security.cpp LINK_LIBRARIES asn1_security)
|
||||
|
||||
add_library(asn1_smoke_test STATIC smoke.cpp)
|
||||
target_link_libraries(asn1_smoke_test PRIVATE asn1)
|
||||
@@ -0,0 +1,138 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/asn1/asn1c_wrapper.hpp>
|
||||
#include <vanetza/asn1/its/VanetzaTest.h>
|
||||
|
||||
using namespace vanetza::asn1;
|
||||
typedef vanetza::asn1::asn1c_wrapper<VanetzaTest_t> test_wrapper;
|
||||
typedef vanetza::asn1::asn1c_oer_wrapper<VanetzaTest_t> test_oer_wrapper;
|
||||
|
||||
TEST(asn1c_wrapper, create) {
|
||||
EXPECT_NO_THROW({
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
});
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, constants) {
|
||||
EXPECT_EQ(42, VanetzaTest__field_magicValue);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, size) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper->string, "1234");
|
||||
EXPECT_EQ(wrapper.size(), 5);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, oer_size) {
|
||||
test_oer_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
|
||||
OCTET_STRING_fromString(&wrapper->string, "1234");
|
||||
EXPECT_EQ(wrapper.size(), 7);
|
||||
|
||||
OCTET_STRING_fromString(&wrapper->string, "12345");
|
||||
EXPECT_EQ(wrapper.size(), 8);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, dereferencing) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
ASSERT_NE(wrapper->field, 3);
|
||||
wrapper->field = 3;
|
||||
EXPECT_EQ((*wrapper).field, 3);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, copy) {
|
||||
test_wrapper wrapper_orig(asn_DEF_VanetzaTest);
|
||||
wrapper_orig->field = 5;
|
||||
test_wrapper wrapper_copy = wrapper_orig;
|
||||
EXPECT_EQ(wrapper_copy->field, 5);
|
||||
wrapper_copy->field = 6;
|
||||
EXPECT_EQ(wrapper_orig->field, 5);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, self_assignment) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper->string, "1234");
|
||||
ASSERT_EQ(wrapper.size(), 5);
|
||||
wrapper = wrapper;
|
||||
EXPECT_EQ(wrapper.size(), 5);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, validate) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper->string, "1234");
|
||||
EXPECT_TRUE(wrapper.validate());
|
||||
OCTET_STRING_fromString(&wrapper->string, "ABCD"); // non-numerics
|
||||
EXPECT_FALSE(wrapper.validate());
|
||||
std::string msg;
|
||||
EXPECT_FALSE(wrapper.validate(msg));
|
||||
EXPECT_FALSE(msg.empty());
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, compare) {
|
||||
test_wrapper wrapper1(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper1->string, "1234");
|
||||
test_wrapper wrapper2(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper2->string, "1234");
|
||||
test_wrapper wrapper3(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper3->string, "0123");
|
||||
test_wrapper wrapper4(asn_DEF_VanetzaTest);
|
||||
wrapper4->field = 5;
|
||||
OCTET_STRING_fromString(&wrapper4->string, "1234");
|
||||
|
||||
// .compare()
|
||||
EXPECT_EQ(wrapper1.compare(wrapper1), 0);
|
||||
EXPECT_EQ(wrapper1.compare(wrapper2), 0);
|
||||
EXPECT_EQ(wrapper1.compare(wrapper3), 1);
|
||||
EXPECT_EQ(wrapper1.compare(wrapper4), -1);
|
||||
|
||||
// operators == and !=
|
||||
EXPECT_TRUE(wrapper1 == wrapper1);
|
||||
EXPECT_TRUE(wrapper1 == wrapper2);
|
||||
EXPECT_FALSE(wrapper1 == wrapper3);
|
||||
EXPECT_TRUE(wrapper1 != wrapper3);
|
||||
EXPECT_TRUE(wrapper1 != wrapper4);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, print) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper->string, "1234");
|
||||
EXPECT_EQ(wrapper.print(), 0);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, encode) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
OCTET_STRING_fromString(&wrapper->string, "1234");
|
||||
wrapper->field = 8;
|
||||
vanetza::ByteBuffer buf = wrapper.encode();
|
||||
EXPECT_EQ(wrapper.size(), buf.size());
|
||||
// No idea if this is the correct ASN.1 PER equivalent
|
||||
EXPECT_EQ(vanetza::ByteBuffer({ 0x04, 0x02, 0x11, 0xA2, 0x80 }), buf);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, decode_valid) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
const vanetza::ByteBuffer buffer { 0x04, 0x02, 0x11, 0xA2, 0x80 };
|
||||
bool result = wrapper.decode(buffer);
|
||||
ASSERT_TRUE(result);
|
||||
EXPECT_EQ(8, wrapper->field);
|
||||
ASSERT_EQ(4, wrapper->string.size);
|
||||
EXPECT_STREQ("1234", (const char*)(wrapper->string.buf));
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, decode_invalid) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
const vanetza::ByteBuffer buffer { 0x12 };
|
||||
bool result = wrapper.decode(buffer);
|
||||
// should have failed because of short buffer
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(asn1c_wrapper, decode_range) {
|
||||
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
||||
const vanetza::ByteBuffer buffer { 0xC0, 0xFF, 0xEE, 0x04, 0x02, 0x11, 0xA2, 0x80, 0x08, 0x15 };
|
||||
auto begin = std::next(buffer.begin(), 3);
|
||||
auto end = std::prev(buffer.end(), 2);
|
||||
ASSERT_TRUE(wrapper.decode(begin, end));
|
||||
EXPECT_EQ(8, wrapper->field);
|
||||
EXPECT_EQ(4, wrapper->string.size);
|
||||
EXPECT_STREQ("1234", (const char*)(wrapper->string.buf));
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/asn1/cpm.hpp>
|
||||
|
||||
using namespace vanetza;
|
||||
|
||||
TEST(Cpm, decode_plain)
|
||||
{
|
||||
// generated with https://asn1.io/asn1playground
|
||||
// contains a minimum set of fields, i.e. no optional containers
|
||||
static const ByteBuffer cpm_uper = {
|
||||
0x01, 0xff, 0x00, 0x00, 0x05, 0x39, 0x00, 0x2a, 0x00, 0x03, 0x49, 0x04,
|
||||
0x84, 0x01, 0xc7, 0x61, 0x26, 0x00, 0x7d, 0x03, 0xe8, 0xe1, 0x36, 0xee,
|
||||
0x87, 0xc0, 0xc0
|
||||
};
|
||||
|
||||
asn1::Cpm cpm;
|
||||
ASSERT_TRUE(cpm.decode(cpm_uper));
|
||||
|
||||
EXPECT_EQ(1, cpm->header.protocolVersion);
|
||||
EXPECT_EQ(255, cpm->header.messageID);
|
||||
EXPECT_EQ(1337, cpm->header.stationID);
|
||||
|
||||
EXPECT_EQ(42, cpm->cpm.generationDeltaTime);
|
||||
EXPECT_EQ(3, cpm->cpm.cpmParameters.numberOfPerceivedObjects);
|
||||
|
||||
const auto& mgmt = cpm->cpm.cpmParameters.managementContainer;
|
||||
EXPECT_EQ(1, mgmt.stationType);
|
||||
EXPECT_EQ(480000000, mgmt.referencePosition.latitude);
|
||||
EXPECT_EQ(110000000, mgmt.referencePosition.longitude);
|
||||
EXPECT_EQ(800001, mgmt.referencePosition.altitude.altitudeValue);
|
||||
EXPECT_EQ(AltitudeConfidence_unavailable, mgmt.referencePosition.altitude.altitudeConfidence);
|
||||
EXPECT_EQ(500, mgmt.referencePosition.positionConfidenceEllipse.semiMajorConfidence);
|
||||
EXPECT_EQ(250, mgmt.referencePosition.positionConfidenceEllipse.semiMinorConfidence);
|
||||
EXPECT_EQ(900, mgmt.referencePosition.positionConfidenceEllipse.semiMajorOrientation);
|
||||
}
|
||||
|
||||
TEST(Cpm, decode_one_perceived_object)
|
||||
{
|
||||
// generated with https://asn1.io/asn1playground
|
||||
// contains a single perceived object container
|
||||
static const ByteBuffer cpm_uper = {
|
||||
0x01, 0xff, 0x00, 0x00, 0x05, 0x39, 0x00, 0x2a, 0x10, 0x03, 0x49, 0x04,
|
||||
0x84, 0x01, 0xc7, 0x61, 0x26, 0x00, 0x7d, 0x03, 0xe8, 0xe1, 0x36, 0xee,
|
||||
0x87, 0xc0, 0x0c, 0x00, 0x01, 0x8e, 0x10, 0x7d, 0x0a, 0x2c, 0x9f, 0x0c,
|
||||
0x89, 0xa1, 0x21, 0x94, 0x00, 0xef, 0xd0, 0x07, 0x7f, 0x01, 0x80
|
||||
};
|
||||
|
||||
asn1::Cpm cpm;
|
||||
ASSERT_TRUE(cpm.decode(cpm_uper));
|
||||
|
||||
ASSERT_TRUE(cpm->cpm.cpmParameters.perceivedObjectContainer);
|
||||
EXPECT_EQ(1, cpm->cpm.cpmParameters.perceivedObjectContainer->list.count);
|
||||
|
||||
const PerceivedObject_t* object = cpm->cpm.cpmParameters.perceivedObjectContainer->list.array[0];
|
||||
ASSERT_TRUE(object);
|
||||
EXPECT_EQ(12, object->objectID);
|
||||
EXPECT_EQ(300, object->timeOfMeasurement);
|
||||
ASSERT_TRUE(object->objectAge);
|
||||
EXPECT_EQ(500, *object->objectAge);
|
||||
EXPECT_EQ(20, object->objectConfidence);
|
||||
EXPECT_EQ(50000, object->xDistance.value);
|
||||
EXPECT_EQ(100, object->xDistance.confidence);
|
||||
EXPECT_EQ(25000, object->yDistance.value);
|
||||
EXPECT_EQ(50, object->yDistance.confidence);
|
||||
EXPECT_FALSE(object->zDistance);
|
||||
EXPECT_EQ(15, object->xSpeed.value);
|
||||
EXPECT_EQ(127, object->xSpeed.confidence);
|
||||
EXPECT_EQ(30, object->ySpeed.value);
|
||||
EXPECT_EQ(127, object->ySpeed.confidence);
|
||||
}
|
||||
|
||||
TEST(Cpm, roundtrip)
|
||||
{
|
||||
// same payload as in decode_one_perceived_object test
|
||||
static const ByteBuffer cpm_uper = {
|
||||
0x01, 0xff, 0x00, 0x00, 0x05, 0x39, 0x00, 0x2a, 0x10, 0x03, 0x49, 0x04,
|
||||
0x84, 0x01, 0xc7, 0x61, 0x26, 0x00, 0x7d, 0x03, 0xe8, 0xe1, 0x36, 0xee,
|
||||
0x87, 0xc0, 0x0c, 0x00, 0x01, 0x8e, 0x10, 0x7d, 0x0a, 0x2c, 0x9f, 0x0c,
|
||||
0x89, 0xa1, 0x21, 0x94, 0x00, 0xef, 0xd0, 0x07, 0x7f, 0x01, 0x80
|
||||
};
|
||||
asn1::Cpm cpm;
|
||||
EXPECT_TRUE(cpm.decode(cpm_uper));
|
||||
EXPECT_EQ(cpm_uper, cpm.encode());
|
||||
}
|
||||
|
||||
TEST(Cpm, encode_one_perceived_object)
|
||||
{
|
||||
asn1::Cpm cpm;
|
||||
cpm->cpm.cpmParameters.numberOfPerceivedObjects = 1;
|
||||
cpm->cpm.cpmParameters.perceivedObjectContainer = asn1::allocate<PerceivedObjectContainer_t>();
|
||||
|
||||
auto object = asn1::allocate<PerceivedObject_t>();
|
||||
EXPECT_EQ(0, ASN_SEQUENCE_ADD(cpm->cpm.cpmParameters.perceivedObjectContainer, object));
|
||||
EXPECT_EQ(1, cpm->cpm.cpmParameters.perceivedObjectContainer->list.count);
|
||||
EXPECT_EQ(object, cpm->cpm.cpmParameters.perceivedObjectContainer->list.array[0]);
|
||||
|
||||
object->objectID = 1;
|
||||
object->timeOfMeasurement = TimeOfMeasurement_oneMilliSecond;
|
||||
object->xDistance.value = DistanceValue_oneMeter;
|
||||
object->xDistance.confidence = DistanceConfidence_unavailable;
|
||||
object->yDistance.value = DistanceValue_oneMeter;
|
||||
object->yDistance.confidence = DistanceConfidence_unavailable;
|
||||
object->xSpeed.value = SpeedValueExtended_unavailable;
|
||||
object->xSpeed.confidence = SpeedConfidence_unavailable;
|
||||
object->ySpeed.value = SpeedValueExtended_unavailable;
|
||||
object->ySpeed.confidence = SpeedConfidence_unavailable;
|
||||
|
||||
EXPECT_TRUE(cpm.validate());
|
||||
EXPECT_FALSE(cpm.encode().empty());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/asn1/asn1c_wrapper.hpp>
|
||||
#include <vanetza/asn1/cam.hpp>
|
||||
#include <vanetza/asn1/denm.hpp>
|
||||
#include <vanetza/asn1/mapem.hpp>
|
||||
#include <vanetza/asn1/spatem.hpp>
|
||||
#include <vanetza/asn1/ssem.hpp>
|
||||
#include <vanetza/asn1/srem.hpp>
|
||||
#include <vanetza/asn1/ivim.hpp>
|
||||
#include <vanetza/asn1/its/TimestampIts.h>
|
||||
|
||||
using namespace vanetza;
|
||||
|
||||
TEST(ItsAsn1, max_timestamp_roundtrip)
|
||||
{
|
||||
const std::int64_t max_timestamp = 4398046511103;
|
||||
asn1::asn1c_wrapper<TimestampIts_t> tx { asn_DEF_TimestampIts };
|
||||
asn_imax2INTEGER(&*tx, max_timestamp);
|
||||
auto buffer = tx.encode();
|
||||
EXPECT_EQ(6, buffer.size());
|
||||
asn1::asn1c_wrapper<TimestampIts_t> rx { asn_DEF_TimestampIts };
|
||||
EXPECT_TRUE(rx.decode(buffer));
|
||||
std::int64_t rx_timestamp = 0;
|
||||
asn_INTEGER2imax(&*tx, &rx_timestamp);
|
||||
EXPECT_EQ(rx_timestamp, max_timestamp);
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, encode_denm)
|
||||
{
|
||||
asn1::Denm denm;
|
||||
EXPECT_EQ(0, asn_uint642INTEGER(&denm->denm.management.detectionTime, TimestampIts_utcStartOf2004));
|
||||
EXPECT_EQ(0, asn_uint642INTEGER(&denm->denm.management.referenceTime, TimestampIts_utcStartOf2004));
|
||||
EXPECT_TRUE(denm.validate());
|
||||
vanetza::ByteBuffer buf = denm.encode();
|
||||
EXPECT_EQ(40, buf.size());
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, create_cam)
|
||||
{
|
||||
asn1::Cam cam;
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, create_denm)
|
||||
{
|
||||
asn1::Denm denm;
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, create_mapem)
|
||||
{
|
||||
asn1::Mapem mapem;
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, create_spatem)
|
||||
{
|
||||
asn1::Spatem spatem;
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, create_srem)
|
||||
{
|
||||
asn1::Srem srem;
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, create_ssem)
|
||||
{
|
||||
asn1::Ssem ssem;
|
||||
}
|
||||
|
||||
TEST(ItsAsn1, create_ivim)
|
||||
{
|
||||
asn1::Ivim ivim;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#include <vanetza/asn1/asn1c_wrapper.hpp>
|
||||
#include <vanetza/asn1/its/r2/EventHistory.h>
|
||||
#include <vanetza/asn1/its/r2/EventZone.h>
|
||||
#include <vanetza/asn1/its/r2/HeadingConfidence.h>
|
||||
#include <vanetza/asn1/its/r2/SituationContainer.h>
|
||||
#include <vanetza/asn1/its/r2/TimestampIts.h>
|
||||
#include <vanetza/asn1/vam.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace vanetza;
|
||||
|
||||
TEST(ItsAsn1, max_timestamp_roundtrip)
|
||||
{
|
||||
const std::int64_t max_timestamp = 4398046511103;
|
||||
asn1::asn1c_wrapper<Vanetza_ITS2_TimestampIts_t> tx { asn_DEF_Vanetza_ITS2_TimestampIts };
|
||||
asn_imax2INTEGER(&*tx, max_timestamp);
|
||||
auto buffer = tx.encode();
|
||||
EXPECT_EQ(6, buffer.size());
|
||||
asn1::asn1c_wrapper<Vanetza_ITS2_TimestampIts_t> rx { asn_DEF_Vanetza_ITS2_TimestampIts };
|
||||
EXPECT_TRUE(rx.decode(buffer));
|
||||
std::int64_t rx_timestamp = 0;
|
||||
asn_INTEGER2imax(&*tx, &rx_timestamp);
|
||||
EXPECT_EQ(rx_timestamp, max_timestamp);
|
||||
}
|
||||
|
||||
TEST(ItsAsn1R2, validate_vam)
|
||||
{
|
||||
asn1::r2::Vam vam;
|
||||
|
||||
vam->header.messageId = Vanetza_ITS2_MessageId_vam;
|
||||
vam->header.protocolVersion = 2;
|
||||
vam->header.stationId = 123;
|
||||
|
||||
vam->vam.generationDeltaTime = 0;
|
||||
vam->vam.vamParameters.basicContainer.referencePosition.latitude = Vanetza_ITS2_Latitude_unavailable;
|
||||
vam->vam.vamParameters.basicContainer.referencePosition.longitude = Vanetza_ITS2_Longitude_unavailable;
|
||||
vam->vam.vamParameters.basicContainer.stationType = 5;
|
||||
|
||||
vam->vam.vamParameters.vruHighFrequencyContainer.heading.value = 0;
|
||||
vam->vam.vamParameters.vruHighFrequencyContainer.heading.confidence = Vanetza_ITS2_HeadingConfidence_unavailable;
|
||||
|
||||
vam->vam.vamParameters.vruHighFrequencyContainer.speed.speedValue = 0;
|
||||
vam->vam.vamParameters.vruHighFrequencyContainer.speed.speedConfidence = Vanetza_ITS2_SpeedConfidence_unavailable;
|
||||
|
||||
EXPECT_TRUE(vam.validate());
|
||||
}
|
||||
|
||||
TEST(ItsAsn1R2, event_zone)
|
||||
{
|
||||
// just needs to compile (SituationContainer's eventZone is patched)
|
||||
Vanetza_ITS2_SituationContainer_t container {};
|
||||
container.eventZone = vanetza::asn1::allocate<Vanetza_ITS2_EventZone_t>();
|
||||
vanetza::asn1::free(asn_DEF_Vanetza_ITS2_EventZone, container.eventZone);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/asn1/asn1c_wrapper.hpp>
|
||||
#include <vanetza/asn1/packet_visitor.hpp>
|
||||
#include <vanetza/asn1/its/VanetzaTest.h>
|
||||
#include <vanetza/net/packet_variant.hpp>
|
||||
#include <boost/variant/apply_visitor.hpp>
|
||||
|
||||
using namespace vanetza;
|
||||
|
||||
class TestWrapper : public asn1::asn1c_wrapper<VanetzaTest_t>
|
||||
{
|
||||
public:
|
||||
TestWrapper() : asn1::asn1c_wrapper<VanetzaTest_t>(asn_DEF_VanetzaTest) {}
|
||||
};
|
||||
|
||||
|
||||
TEST(PacketVisitor, fresh)
|
||||
{
|
||||
asn1::PacketVisitor<TestWrapper> visitor;
|
||||
EXPECT_EQ(visitor.get_shared_wrapper(), std::shared_ptr<TestWrapper>());
|
||||
}
|
||||
|
||||
TEST(PacketVisitor, deserialize_buffer)
|
||||
{
|
||||
PacketVariant packet;
|
||||
{
|
||||
TestWrapper wrapper;
|
||||
wrapper->field = 23;
|
||||
CohesivePacket cohesive { wrapper.encode(), OsiLayer::Application };
|
||||
packet = std::move(cohesive);
|
||||
}
|
||||
|
||||
asn1::PacketVisitor<TestWrapper> visitor;
|
||||
auto result = boost::apply_visitor(visitor, packet);
|
||||
ASSERT_TRUE(result);
|
||||
EXPECT_EQ((*result)->field, 23);
|
||||
}
|
||||
|
||||
TEST(PacketVisitor, deserialize_start)
|
||||
{
|
||||
PacketVariant packet;
|
||||
{
|
||||
TestWrapper wrapper;
|
||||
wrapper->field = 23;
|
||||
CohesivePacket cohesive { wrapper.encode(), OsiLayer::Session };
|
||||
packet = std::move(cohesive);
|
||||
}
|
||||
|
||||
asn1::PacketVisitor<TestWrapper> visitor;
|
||||
EXPECT_TRUE(boost::apply_visitor(visitor, packet));
|
||||
visitor.start_deserialization_at(OsiLayer::Application);
|
||||
EXPECT_FALSE(boost::apply_visitor(visitor, packet));
|
||||
}
|
||||
|
||||
TEST(PacketVisitor, cast_chunk)
|
||||
{
|
||||
PacketVariant packet;
|
||||
const VanetzaTest_t* ptr = nullptr;
|
||||
{
|
||||
ChunkPacket chunk;
|
||||
TestWrapper wrapper;
|
||||
wrapper->field = 42;
|
||||
ptr = &(*wrapper);
|
||||
chunk[OsiLayer::Application] = std::move(wrapper);
|
||||
packet = std::move(chunk);
|
||||
}
|
||||
|
||||
asn1::PacketVisitor<TestWrapper> visitor;
|
||||
auto result = boost::apply_visitor(visitor, packet);
|
||||
ASSERT_TRUE(result);
|
||||
EXPECT_EQ(&(**result), ptr);
|
||||
EXPECT_EQ((*result)->field, 42);
|
||||
}
|
||||
|
||||
TEST(PacketVisitor, deserialize_chunk)
|
||||
{
|
||||
PacketVariant packet;
|
||||
{
|
||||
ChunkPacket chunk;
|
||||
TestWrapper wrapper;
|
||||
wrapper->field = 123;
|
||||
chunk[OsiLayer::Application] = wrapper.encode();
|
||||
packet = std::move(chunk);
|
||||
}
|
||||
|
||||
asn1::PacketVisitor<TestWrapper> visitor;
|
||||
visitor.allow_chunk_deserialization(false);
|
||||
EXPECT_FALSE(boost::apply_visitor(visitor, packet));
|
||||
|
||||
visitor.allow_chunk_deserialization(true);
|
||||
EXPECT_TRUE(boost::apply_visitor(visitor, packet));
|
||||
}
|
||||
|
||||
TEST(PacketVisitor, failed)
|
||||
{
|
||||
asn1::PacketVisitor<TestWrapper> visitor;
|
||||
PacketVariant packet { ChunkPacket {} };
|
||||
auto result = boost::apply_visitor(visitor, packet);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_FALSE(visitor.get_shared_wrapper());
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/asn1/asn1c_wrapper.hpp>
|
||||
#include <vanetza/asn1/security_profile.hpp>
|
||||
#include VANETZA_ASN1_SECURITY_HEADER(Time64.h)
|
||||
#include VANETZA_ASN1_SECURITY_HEADER(Uint64.h)
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
#ifdef VANETZA_WITH_PQC
|
||||
#include VANETZA_ASN1_SECURITY_HEADER(PublicVerificationKey.h)
|
||||
#include VANETZA_ASN1_SECURITY_HEADER(Signature.h)
|
||||
#include VANETZA_ASN1_SECURITY_HEADER(ToBeSignedCertificate.h)
|
||||
#endif
|
||||
|
||||
using namespace vanetza::asn1;
|
||||
|
||||
TEST(SecurityAsn1, Time64)
|
||||
{
|
||||
asn1c_wrapper<Vanetza_Security_Time64_t> time { asn_DEF_Vanetza_Security_Time64 };
|
||||
EXPECT_EQ(0, asn_umax2INTEGER(&*time, std::numeric_limits<std::uint64_t>::max()));
|
||||
|
||||
std::uint64_t tmp = 0;
|
||||
asn_INTEGER2umax(&*time, &tmp);
|
||||
EXPECT_EQ(tmp, std::numeric_limits<std::uint64_t>::max());
|
||||
|
||||
time.encode();
|
||||
EXPECT_EQ(8, time.size());
|
||||
}
|
||||
|
||||
TEST(SecuriyAsn1, Uint64)
|
||||
{
|
||||
asn1c_wrapper<Vanetza_Security_Uint64_t> uint { asn_DEF_Vanetza_Security_Uint64 };
|
||||
EXPECT_EQ(0, asn_umax2INTEGER(&*uint, std::numeric_limits<std::uint64_t>::max()));
|
||||
|
||||
std::uint64_t tmp = 0;
|
||||
asn_INTEGER2umax(&*uint, &tmp);
|
||||
EXPECT_EQ(tmp, std::numeric_limits<std::uint64_t>::max());
|
||||
|
||||
uint.encode();
|
||||
EXPECT_EQ(8, uint.size());
|
||||
}
|
||||
|
||||
TEST(SecurityAsn1, Uint64_roundtrip_max_value)
|
||||
{
|
||||
asn1c_wrapper<Vanetza_Security_Uint64_t> tx { asn_DEF_Vanetza_Security_Uint64 };
|
||||
EXPECT_EQ(0, asn_umax2INTEGER(&*tx, std::numeric_limits<std::uint64_t>::max()));
|
||||
const vanetza::ByteBuffer buffer = tx.encode();
|
||||
EXPECT_EQ(8, buffer.size());
|
||||
EXPECT_TRUE(std::all_of(buffer.begin(), buffer.end(),
|
||||
[](std::uint8_t c) { return c == 0xff; }));
|
||||
|
||||
asn1c_wrapper<Vanetza_Security_Uint64_t> rx { asn_DEF_Vanetza_Security_Uint64 };
|
||||
EXPECT_TRUE(rx.decode(buffer));
|
||||
std::uint64_t value = 0;
|
||||
EXPECT_EQ(0, asn_INTEGER2umax(&*rx, &value));
|
||||
EXPECT_EQ(value, std::numeric_limits<std::uint64_t>::max());
|
||||
}
|
||||
|
||||
#ifdef VANETZA_WITH_PQC
|
||||
TEST(SecurityAsn1, HybridPqcExtensions)
|
||||
{
|
||||
std::array<char, 897> public_key_bytes {{}};
|
||||
asn1c_oer_wrapper<Vanetza_Security_PublicVerificationKey_t> public_key {
|
||||
asn_DEF_Vanetza_Security_PublicVerificationKey
|
||||
};
|
||||
public_key->present = Vanetza_Security_PublicVerificationKey_PR_fnDsa512;
|
||||
ASSERT_EQ(0, OCTET_STRING_fromBuf(
|
||||
&public_key->choice.fnDsa512, public_key_bytes.data(), public_key_bytes.size()));
|
||||
ASSERT_TRUE(public_key.validate());
|
||||
|
||||
const auto encoded_public_key = public_key.encode();
|
||||
asn1c_oer_wrapper<Vanetza_Security_PublicVerificationKey_t> decoded_public_key {
|
||||
asn_DEF_Vanetza_Security_PublicVerificationKey
|
||||
};
|
||||
ASSERT_TRUE(decoded_public_key.decode(encoded_public_key));
|
||||
EXPECT_EQ(Vanetza_Security_PublicVerificationKey_PR_fnDsa512, decoded_public_key->present);
|
||||
EXPECT_EQ(public_key_bytes.size(), decoded_public_key->choice.fnDsa512.size);
|
||||
|
||||
std::array<char, 666> signature_bytes {{}};
|
||||
asn1c_oer_wrapper<Vanetza_Security_Signature_t> signature {
|
||||
asn_DEF_Vanetza_Security_Signature
|
||||
};
|
||||
signature->present = Vanetza_Security_Signature_PR_fnDsa512Signature;
|
||||
ASSERT_EQ(0, OCTET_STRING_fromBuf(
|
||||
&signature->choice.fnDsa512Signature, signature_bytes.data(), signature_bytes.size()));
|
||||
ASSERT_TRUE(signature.validate());
|
||||
|
||||
const auto encoded_signature = signature.encode();
|
||||
asn1c_oer_wrapper<Vanetza_Security_Signature_t> decoded_signature {
|
||||
asn_DEF_Vanetza_Security_Signature
|
||||
};
|
||||
ASSERT_TRUE(decoded_signature.decode(encoded_signature));
|
||||
EXPECT_EQ(Vanetza_Security_Signature_PR_fnDsa512Signature, decoded_signature->present);
|
||||
EXPECT_EQ(signature_bytes.size(), decoded_signature->choice.fnDsa512Signature.size);
|
||||
|
||||
Vanetza_Security_ToBeSignedCertificate_t certificate {{}};
|
||||
EXPECT_EQ(nullptr, certificate.altVerificationKey);
|
||||
EXPECT_EQ(nullptr, certificate.altSignatureValue);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <vanetza/asn1/cam.hpp>
|
||||
#include <vanetza/asn1/cpm.hpp>
|
||||
#include <vanetza/asn1/denm.hpp>
|
||||
#include <vanetza/asn1/ivim.hpp>
|
||||
#include <vanetza/asn1/mapem.hpp>
|
||||
#include <vanetza/asn1/rtcmem.hpp>
|
||||
#include <vanetza/asn1/spatem.hpp>
|
||||
#include <vanetza/asn1/srem.hpp>
|
||||
#include <vanetza/asn1/ssem.hpp>
|
||||
#include <vanetza/asn1/vam.hpp>
|
||||
|
||||
// just make sure wrappers are compilable
|
||||
static vanetza::asn1::Cam cam;
|
||||
static vanetza::asn1::Cpm cpm;
|
||||
static vanetza::asn1::Denm denm;
|
||||
static vanetza::asn1::Ivim ivim;
|
||||
static vanetza::asn1::Mapem mapem;
|
||||
static vanetza::asn1::Rtcmem rtcmem;
|
||||
static vanetza::asn1::Spatem spatem;
|
||||
static vanetza::asn1::Srem srem;
|
||||
static vanetza::asn1::Ssem ssem;
|
||||
static vanetza::asn1::r2::Vam vam;
|
||||
|
||||
Reference in New Issue
Block a user