From a8c8d96fedb52f6232f7f5ecbf185bf920c1d53c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 5 Aug 2016 21:51:56 +0200 Subject: Clear incoming packets as soon they meet their lifetime end Signed-off-by: Szczepan Zalega --- include/device_proto.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/device_proto.h b/include/device_proto.h index f28b5b9..f0d26c0 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -133,6 +133,24 @@ struct EmptyPayload { std::string dissect() const { return std::string("Empty Payload."); } } __packed; +template +class ClearingProxy{ +public: + ClearingProxy(command_payload &p){ + payload = p; + bzero(&p, sizeof(p)); + } + ~ClearingProxy(){ + bzero(&payload, sizeof(payload)); + } + + command_payload & data(){ + return payload; + } + + command_payload payload; +}; + template class Transaction : semantics::non_constructible { public: @@ -167,11 +185,11 @@ class Transaction : semantics::non_constructible { } - static response_payload run(device::Device &dev, + static ClearingProxy run(device::Device &dev, const command_payload &payload) { using namespace ::nitrokey::device; using namespace ::nitrokey::log; - using namespace std::chrono_literals; + using namespace std::chrono_literals; Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); @@ -234,7 +252,7 @@ class Transaction : semantics::non_constructible { return resp.payload; } - static response_payload run(device::Device &dev) { + static ClearingProxy run(device::Device &dev) { command_payload empty_payload; return run(dev, empty_payload); } -- cgit v1.2.3