Skip to content

Commit 2b047dc

Browse files
Fix initialization order of storage
1 parent eaf482b commit 2b047dc

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

services/util/EchoInstantiation.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,25 @@ namespace main_
4141
services::SesameCobs cobs;
4242
services::SesameWindowed windowed{ cobs };
4343
services::EchoOnSesame echo;
44+
45+
template<std::size_t MessageSize>
46+
struct CobsStorage
47+
{
48+
static constexpr std::size_t encodedMessageSize = services::SesameWindowed::bufferSizeForMessage<MessageSize, services::SesameCobs::EncodedMessageSize>;
49+
50+
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameCobs::sendBufferSize<MessageSize>> cobsSendStorage;
51+
infra::BoundedDeque<uint8_t>::WithMaxSize<services::SesameCobs::receiveBufferSize<encodedMessageSize>> cobsReceivedMessage;
52+
};
4453
};
4554

4655
template<std::size_t MessageSize>
4756
struct EchoOnSesame::WithMessageSize
48-
: EchoOnSesame
57+
: private EchoOnSesame::CobsStorage<MessageSize>
58+
, EchoOnSesame
4959
{
5060
WithMessageSize(hal::BufferedSerialCommunication& serialCommunication, services::MethodSerializerFactory& serializerFactory)
51-
: EchoOnSesame(cobsSendStorage, cobsReceivedMessage, serialCommunication, serializerFactory)
61+
: EchoOnSesame(this->cobsSendStorage, this->cobsReceivedMessage, serialCommunication, serializerFactory)
5262
{}
53-
54-
private:
55-
static constexpr std::size_t encodedMessageSize = services::SesameWindowed::bufferSizeForMessage<MessageSize, services::SesameCobs::EncodedMessageSize>;
56-
57-
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameCobs::sendBufferSize<MessageSize>> cobsSendStorage;
58-
infra::BoundedDeque<uint8_t>::WithMaxSize<services::SesameCobs::receiveBufferSize<encodedMessageSize>> cobsReceivedMessage;
5963
};
6064

6165
#ifdef EMIL_HAL_GENERIC

services/util/EchoInstantiationSecured.hpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#ifndef SERVICES_UTIL_ECHO_INSTANTIATION_SECURED_HPP
22
#define SERVICES_UTIL_ECHO_INSTANTIATION_SECURED_HPP
33

4-
#include "hal/interfaces/SerialCommunication.hpp"
4+
#include "services/util/EchoInstantiation.hpp"
55
#include "services/util/EchoPolicyDiffieHellman.hpp"
66
#include "services/util/EchoPolicySymmetricKey.hpp"
7-
#include "services/util/SesameCobs.hpp"
87
#include "services/util/SesameSecured.hpp"
9-
#include "services/util/SesameWindowed.hpp"
108

119
namespace main_
1210
{
@@ -22,6 +20,13 @@ namespace main_
2220
services::SesameWindowed windowed{ cobs };
2321
services::SesameSecured::WithCryptoMbedTls secured;
2422
services::EchoOnSesame echo;
23+
24+
template<std::size_t MessageSize>
25+
struct SecuredStorage
26+
{
27+
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameSecured::encodedMessageSize<MessageSize>> securedSendBuffer;
28+
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameSecured::encodedMessageSize<MessageSize>> securedReceiveBuffer;
29+
};
2530
};
2631

2732
struct EchoOnSesameSecuredSymmetricKey
@@ -38,19 +43,13 @@ namespace main_
3843

3944
template<std::size_t MessageSize>
4045
struct EchoOnSesameSecuredSymmetricKey::WithMessageSize
41-
: EchoOnSesameSecuredSymmetricKey
46+
: private EchoOnSesame::CobsStorage<MessageSize>
47+
, private EchoOnSesameSecured::SecuredStorage<MessageSize>
48+
, EchoOnSesameSecuredSymmetricKey
4249
{
4350
WithMessageSize(hal::BufferedSerialCommunication& serialCommunication, services::MethodSerializerFactory& serializerFactory, const services::SesameSecured::KeyMaterial& keyMaterial, hal::SynchronousRandomDataGenerator& randomDataGenerator)
44-
: EchoOnSesameSecuredSymmetricKey(cobsSendStorage, cobsReceivedMessage, securedSendBuffer, securedReceiveBuffer, serialCommunication, serializerFactory, keyMaterial, randomDataGenerator)
51+
: EchoOnSesameSecuredSymmetricKey(this->cobsSendStorage, this->cobsReceivedMessage, this->securedSendBuffer, this->securedReceiveBuffer, serialCommunication, serializerFactory, keyMaterial, randomDataGenerator)
4552
{}
46-
47-
private:
48-
static constexpr std::size_t encodedMessageSize = services::SesameWindowed::bufferSizeForMessage<MessageSize, services::SesameCobs::EncodedMessageSize>;
49-
50-
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameCobs::sendBufferSize<MessageSize>> cobsSendStorage;
51-
infra::BoundedDeque<uint8_t>::WithMaxSize<services::SesameCobs::receiveBufferSize<encodedMessageSize>> cobsReceivedMessage;
52-
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameSecured::encodedMessageSize<MessageSize>> securedSendBuffer;
53-
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameSecured::encodedMessageSize<MessageSize>> securedReceiveBuffer;
5453
};
5554

5655
struct EchoOnSesameSecuredDiffieHellman
@@ -71,19 +70,13 @@ namespace main_
7170

7271
template<std::size_t MessageSize>
7372
struct EchoOnSesameSecuredDiffieHellman::WithMessageSize
74-
: EchoOnSesameSecuredDiffieHellman
73+
: private EchoOnSesame::CobsStorage<MessageSize>
74+
, private EchoOnSesameSecured::SecuredStorage<MessageSize>
75+
, EchoOnSesameSecuredDiffieHellman
7576
{
7677
WithMessageSize(hal::BufferedSerialCommunication& serialCommunication, services::MethodSerializerFactory& serializerFactory, infra::ConstByteRange dsaCertificate, infra::ConstByteRange dsaCertificatePrivateKey, infra::ConstByteRange rootCaCertificate, hal::SynchronousRandomDataGenerator& randomDataGenerator)
77-
: EchoOnSesameSecuredDiffieHellman(cobsSendStorage, cobsReceivedMessage, securedSendBuffer, securedReceiveBuffer, serialCommunication, serializerFactory, dsaCertificatePrivateKey, dsaCertificate, rootCaCertificate, randomDataGenerator)
78+
: EchoOnSesameSecuredDiffieHellman(this->cobsSendStorage, this->cobsReceivedMessage, this->securedSendBuffer, this->securedReceiveBuffer, serialCommunication, serializerFactory, dsaCertificatePrivateKey, dsaCertificate, rootCaCertificate, randomDataGenerator)
7879
{}
79-
80-
private:
81-
static constexpr std::size_t encodedMessageSize = services::SesameWindowed::bufferSizeForMessage<MessageSize, services::SesameCobs::EncodedMessageSize>;
82-
83-
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameCobs::sendBufferSize<MessageSize>> cobsSendStorage;
84-
infra::BoundedDeque<uint8_t>::WithMaxSize<services::SesameCobs::receiveBufferSize<encodedMessageSize>> cobsReceivedMessage;
85-
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameSecured::encodedMessageSize<MessageSize>> securedSendBuffer;
86-
infra::BoundedVector<uint8_t>::WithMaxSize<services::SesameSecured::encodedMessageSize<MessageSize>> securedReceiveBuffer;
8780
};
8881
}
8982

0 commit comments

Comments
 (0)