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

Side by Side Diff: components/autofill/browser/wallet/full_wallet.cc

Issue 12815002: requestAutocomplete: Fill |form_structure_| from Online Wallet data (including (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/autofill/browser/wallet/full_wallet.h" 5 #include "components/autofill/browser/wallet/full_wallet.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 11
11 namespace { 12 namespace {
12 13
13 const size_t kPanSize = 16; 14 const size_t kPanSize = 16;
14 const size_t kBinSize = 6; 15 const size_t kBinSize = 6;
15 const size_t kCvnSize = 3; 16 const size_t kCvnSize = 3;
16 17
17 } // anonymous namespace 18 } // anonymous namespace
18 19
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 117
117 return scoped_ptr<FullWallet>(new FullWallet(expiration_month, 118 return scoped_ptr<FullWallet>(new FullWallet(expiration_month,
118 expiration_year, 119 expiration_year,
119 iin, 120 iin,
120 encrypted_rest, 121 encrypted_rest,
121 billing_address.Pass(), 122 billing_address.Pass(),
122 shipping_address.Pass(), 123 shipping_address.Pass(),
123 required_actions)); 124 required_actions));
124 } 125 }
125 126
127 string16 FullWallet::GetInfo(AutofillFieldType type) {
128 switch (type) {
129 case CREDIT_CARD_NUMBER:
130 return UTF8ToUTF16(GetPan());
131
132 case CREDIT_CARD_NAME:
133 return billing_address()->recipient_name();
134
135 case CREDIT_CARD_VERIFICATION_CODE:
136 return UTF8ToUTF16(GetCvn());
137
138 case CREDIT_CARD_EXP_MONTH:
139 return base::IntToString16(expiration_month());
140
141 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
142 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR:
Ilya Sherman 2013/03/14 21:59:08 As I mentioned in the other CL, this isn't how EXP
Dan Beam 2013/03/15 02:10:58 Delorted.
143 return base::IntToString16(expiration_year());
144
145 default:
146 NOTREACHED();
147 }
148
149 return string16();
150 }
151
126 bool FullWallet::HasRequiredAction(RequiredAction action) const { 152 bool FullWallet::HasRequiredAction(RequiredAction action) const {
127 DCHECK(ActionAppliesToFullWallet(action)); 153 DCHECK(ActionAppliesToFullWallet(action));
128 return std::find(required_actions_.begin(), 154 return std::find(required_actions_.begin(),
129 required_actions_.end(), 155 required_actions_.end(),
130 action) != required_actions_.end(); 156 action) != required_actions_.end();
131 } 157 }
132 158
133 bool FullWallet::operator==(const FullWallet& other) const { 159 bool FullWallet::operator==(const FullWallet& other) const {
134 if (expiration_month_ != other.expiration_month_) 160 if (expiration_month_ != other.expiration_month_)
135 return false; 161 return false;
(...skipping 24 matching lines...) Expand all
160 if (required_actions_ != other.required_actions_) 186 if (required_actions_ != other.required_actions_)
161 return false; 187 return false;
162 188
163 return true; 189 return true;
164 } 190 }
165 191
166 bool FullWallet::operator!=(const FullWallet& other) const { 192 bool FullWallet::operator!=(const FullWallet& other) const {
167 return !(*this == other); 193 return !(*this == other);
168 } 194 }
169 195
170 const std::string& FullWallet::GetPan() {
171 if (pan_.empty())
172 DecryptCardInfo();
173 return pan_;
174 }
175
176 const std::string& FullWallet::GetCvn() {
177 if (cvn_.empty())
178 DecryptCardInfo();
179 return cvn_;
180 }
181
182 void FullWallet::DecryptCardInfo() { 196 void FullWallet::DecryptCardInfo() {
183 std::vector<uint8> operating_data; 197 std::vector<uint8> operating_data;
184 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. 198 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|.
185 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { 199 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) {
186 DLOG(ERROR) << "Failed to parse encrypted rest"; 200 DLOG(ERROR) << "Failed to parse encrypted rest";
187 return; 201 return;
188 } 202 }
189 203
190 // Ensure |one_time_pad_| and |encrypted_rest_| are of the same length 204 // Ensure |one_time_pad_| and |encrypted_rest_| are of the same length
191 // otherwise something has gone wrong and we can't decrypt the data. 205 // otherwise something has gone wrong and we can't decrypt the data.
(...skipping 21 matching lines...) Expand all
213 // to be padded with 0's until it is. 227 // to be padded with 0's until it is.
214 if (card_info.size() != padded_length) 228 if (card_info.size() != padded_length)
215 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); 229 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0');
216 230
217 // Separate out the PAN from the CVN. 231 // Separate out the PAN from the CVN.
218 size_t split = kPanSize - kBinSize; 232 size_t split = kPanSize - kBinSize;
219 cvn_ = card_info.substr(split); 233 cvn_ = card_info.substr(split);
220 pan_ = iin_ + card_info.substr(0, split); 234 pan_ = iin_ + card_info.substr(0, split);
221 } 235 }
222 236
237 const std::string& FullWallet::GetPan() {
238 if (pan_.empty())
239 DecryptCardInfo();
240 return pan_;
241 }
242
243 const std::string& FullWallet::GetCvn() {
244 if (cvn_.empty())
245 DecryptCardInfo();
246 return cvn_;
247 }
248
223 } // namespace wallet 249 } // namespace wallet
224 } // namespace autofill 250 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698