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

Side by Side Diff: device/u2f/u2f_apdu_command.cc

Issue 2665493002: Add builders to APDU command class (Closed)
Patch Set: Remove unused constant Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "u2f_apdu_command.h" 5 #include "u2f_apdu_command.h"
6 6
7 namespace device { 7 namespace device {
8 8
9 scoped_refptr<U2fApduCommand> U2fApduCommand::CreateFromMessage( 9 scoped_refptr<U2fApduCommand> U2fApduCommand::CreateFromMessage(
10 const std::vector<uint8_t>& message) { 10 const std::vector<uint8_t>& message) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 std::vector<uint8_t> data) 112 std::vector<uint8_t> data)
113 : cla_(cla), 113 : cla_(cla),
114 ins_(ins), 114 ins_(ins),
115 p1_(p1), 115 p1_(p1),
116 p2_(p2), 116 p2_(p2),
117 response_length_(response_length), 117 response_length_(response_length),
118 data_(std::move(data)) {} 118 data_(std::move(data)) {}
119 119
120 U2fApduCommand::~U2fApduCommand() {} 120 U2fApduCommand::~U2fApduCommand() {}
121 121
122 // static
123 scoped_refptr<U2fApduCommand> U2fApduCommand::BuildRegisterCommand(
124 const std::vector<uint8_t>& appid_digest,
125 const std::vector<uint8_t>& challenge_digest) {
126 if (appid_digest.size() != kAppIdDigestLen ||
127 challenge_digest.size() != kChallengeDigestLen) {
128 return nullptr;
129 }
130
131 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.
132 std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
133 data.insert(data.end(), appid_digest.begin(), appid_digest.end());
134 command->set_ins(kInsU2fEnroll);
135 command->set_p1(kP1TupRequiredConsumed);
136 command->set_data(data);
137 return command;
138 }
139
140 // static
141 scoped_refptr<U2fApduCommand> U2fApduCommand::BuildGetVersionCommand() {
142 scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
143 command->set_ins(kInsU2fVersion);
144 return command;
145 }
146
147 // static
148 scoped_refptr<U2fApduCommand> U2fApduCommand::BuildGetLegacyVersionCommand() {
149 scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
150 command->set_ins(kInsU2fVersion);
151 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.
152 return command;
153 }
154
155 // static
156 scoped_refptr<U2fApduCommand> U2fApduCommand::BuildSignCommand(
157 const std::vector<uint8_t>& appid_digest,
158 const std::vector<uint8_t>& challenge_digest,
159 const std::vector<uint8_t>& key_handle) {
160 if (appid_digest.size() != kAppIdDigestLen ||
161 challenge_digest.size() != kChallengeDigestLen ||
162 key_handle.size() > kMaxKeyHandleLength) {
163 return nullptr;
164 }
165
166 scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
167 std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
168 data.insert(data.end(), appid_digest.begin(), appid_digest.end());
169 data.push_back(static_cast<uint8_t>(key_handle.size()));
170 data.insert(data.end(), key_handle.begin(), key_handle.end());
171 command->set_ins(kInsU2fSign);
172 command->set_p1(kP1TupRequiredConsumed);
173 command->set_data(data);
174 return command;
175 }
176
122 } // namespace device 177 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698