aboutsummaryrefslogtreecommitdiff
path: root/include/command.h
diff options
context:
space:
mode:
authorszszszsz <szszszsz@users.noreply.github.com>2016-11-26 19:51:11 +0100
committerGitHub <noreply@github.com>2016-11-26 19:51:11 +0100
commitf60f2cf0144a91769a5fc00fac1314d2e00cdf0d (patch)
treead2a4513b1ad01b225a519ac10cafa3e583a26a1 /include/command.h
parentd841239bc9ece1ce969c293783219cceb001fc67 (diff)
parentcdd16f3f184b2745094da39de3f815aea6633fdb (diff)
downloadlibnitrokey-f60f2cf0144a91769a5fc00fac1314d2e00cdf0d.tar.gz
libnitrokey-f60f2cf0144a91769a5fc00fac1314d2e00cdf0d.tar.bz2
Merge pull request #52 from Nitrokey/14-storage_commands
Support Nitrokey Storage
Diffstat (limited to 'include/command.h')
-rw-r--r--include/command.h84
1 files changed, 71 insertions, 13 deletions
diff --git a/include/command.h b/include/command.h
index 715902d..0a875e4 100644
--- a/include/command.h
+++ b/include/command.h
@@ -5,19 +5,77 @@
#include "cxx_semantics.h"
namespace nitrokey {
-namespace proto {
-
-template <CommandID cmd_id>
-class Command : semantics::non_constructible {
- public:
- constexpr static CommandID command_id() { return cmd_id; }
-
- template <typename T>
- static std::string dissect(const T &) {
- return std::string("Payload dissection is unavailable");
- }
-};
-}
+ namespace proto {
+
+ template<CommandID cmd_id>
+ class Command : semantics::non_constructible {
+ public:
+ constexpr static CommandID command_id() { return cmd_id; }
+
+ template<typename T>
+ std::string dissect(const T &) {
+ return std::string("Payload dissection is unavailable");
+ }
+ };
+
+#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl );
+namespace stick20{
+ enum class PasswordKind : uint8_t {
+ User = 'P',
+ Admin = 'A',
+ AdminPrefixed
+ };
+
+ template<CommandID cmd_id, PasswordKind Tpassword_kind = PasswordKind::User, int password_length = 20>
+ class PasswordCommand : public Command<cmd_id> {
+ public:
+ struct CommandPayload {
+ uint8_t kind;
+ uint8_t password[password_length];
+
+ std::string dissect() const {
+ std::stringstream ss;
+ print_to_ss( kind );
+ print_to_ss(password);
+ return ss.str();
+ }
+ void set_kind_admin() {
+ kind = (uint8_t) 'A';
+ }
+ void set_kind_admin_prefixed() {
+ kind = (uint8_t) 'P';
+ }
+ void set_kind_user() {
+ kind = (uint8_t) 'P';
+ }
+
+ void set_defaults(){
+ set_kind(Tpassword_kind);
+ }
+
+ void set_kind(PasswordKind password_kind){
+ switch (password_kind){
+ case PasswordKind::Admin:
+ set_kind_admin();
+ break;
+ case PasswordKind::User:
+ set_kind_user();
+ break;
+ case PasswordKind::AdminPrefixed:
+ set_kind_admin_prefixed();
+ break;
+ }
+ };
+
+ } __packed;
+
+ typedef Transaction<Command<cmd_id>::command_id(), struct CommandPayload, struct EmptyPayload>
+ CommandTransaction;
+
+ };
+ }
+ }
}
+#undef print_to_ss
#endif