aboutsummaryrefslogtreecommitdiff
path: root/include/device_proto.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/device_proto.h')
-rw-r--r--include/device_proto.h24
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);
}