Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6055)

Unified Diff: device/u2f/u2f_apdu_command.cc

Issue 2665493002: Add builders to APDU command class (Closed)
Patch Set: Remove unused constant Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/u2f/u2f_apdu_command.cc
diff --git a/device/u2f/u2f_apdu_command.cc b/device/u2f/u2f_apdu_command.cc
index cd854825e53d8d64367ea5fe2dd4f22f385f44fa..b1964e26f6e297a58912106447d1d5f677722a45 100644
--- a/device/u2f/u2f_apdu_command.cc
+++ b/device/u2f/u2f_apdu_command.cc
@@ -119,4 +119,59 @@ U2fApduCommand::U2fApduCommand(uint8_t cla,
U2fApduCommand::~U2fApduCommand() {}
+// static
+scoped_refptr<U2fApduCommand> U2fApduCommand::BuildRegisterCommand(
+ const std::vector<uint8_t>& appid_digest,
+ const std::vector<uint8_t>& challenge_digest) {
+ if (appid_digest.size() != kAppIdDigestLen ||
+ challenge_digest.size() != kChallengeDigestLen) {
+ return nullptr;
+ }
+
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
Reilly Grant (use Gerrit) 2017/01/28 00:29:29 No "U2fApduCommand::" required here and below.
Casey Piper 2017/01/30 21:51:40 Done.
+ std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
+ data.insert(data.end(), appid_digest.begin(), appid_digest.end());
+ command->set_ins(kInsU2fEnroll);
+ command->set_p1(kP1TupRequiredConsumed);
+ command->set_data(data);
+ return command;
+}
+
+// static
+scoped_refptr<U2fApduCommand> U2fApduCommand::BuildGetVersionCommand() {
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
+ command->set_ins(kInsU2fVersion);
+ return command;
+}
+
+// static
+scoped_refptr<U2fApduCommand> U2fApduCommand::BuildGetLegacyVersionCommand() {
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
+ command->set_ins(kInsU2fVersion);
+ command->set_data(std::vector<uint8_t>(2, 0));
juanlang (chromium.org) 2017/01/28 00:08:39 Comment why two 0 bytes, please.
Casey Piper 2017/01/30 21:51:40 Done.
+ return command;
+}
+
+// static
+scoped_refptr<U2fApduCommand> U2fApduCommand::BuildSignCommand(
+ const std::vector<uint8_t>& appid_digest,
+ const std::vector<uint8_t>& challenge_digest,
+ const std::vector<uint8_t>& key_handle) {
+ if (appid_digest.size() != kAppIdDigestLen ||
+ challenge_digest.size() != kChallengeDigestLen ||
+ key_handle.size() > kMaxKeyHandleLength) {
+ return nullptr;
+ }
+
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
+ std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
+ data.insert(data.end(), appid_digest.begin(), appid_digest.end());
+ data.push_back(static_cast<uint8_t>(key_handle.size()));
+ data.insert(data.end(), key_handle.begin(), key_handle.end());
+ command->set_ins(kInsU2fSign);
+ command->set_p1(kP1TupRequiredConsumed);
+ command->set_data(data);
+ return command;
+}
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698