diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-05 21:51:56 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-05 21:56:07 +0200 |
commit | a8c8d96fedb52f6232f7f5ecbf185bf920c1d53c (patch) | |
tree | fafd7b7669c39443a1bc8183f96da8babea2f64c /include | |
parent | caf500394b7ba674e2fff834f2d170a0f0a909a4 (diff) | |
download | libnitrokey-0.9.tar.gz libnitrokey-0.9.tar.bz2 |
Clear incoming packets as soon they meet their lifetime endv0.9
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/device_proto.h | 24 |
1 files changed, 21 insertions, 3 deletions
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 <typename command_payload> +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 <CommandID cmd_id, typename command_payload, typename response_payload> class Transaction : semantics::non_constructible { public: @@ -167,11 +185,11 @@ class Transaction : semantics::non_constructible { } - static response_payload run(device::Device &dev, + static ClearingProxy<response_payload> 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<response_payload> run(device::Device &dev) { command_payload empty_payload; return run(dev, empty_payload); } |