OLD | NEW |
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 Loading... |
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 return base::IntToString16(expiration_year()); |
| 143 |
| 144 default: |
| 145 NOTREACHED(); |
| 146 } |
| 147 |
| 148 return string16(); |
| 149 } |
| 150 |
126 bool FullWallet::HasRequiredAction(RequiredAction action) const { | 151 bool FullWallet::HasRequiredAction(RequiredAction action) const { |
127 DCHECK(ActionAppliesToFullWallet(action)); | 152 DCHECK(ActionAppliesToFullWallet(action)); |
128 return std::find(required_actions_.begin(), | 153 return std::find(required_actions_.begin(), |
129 required_actions_.end(), | 154 required_actions_.end(), |
130 action) != required_actions_.end(); | 155 action) != required_actions_.end(); |
131 } | 156 } |
132 | 157 |
133 bool FullWallet::operator==(const FullWallet& other) const { | 158 bool FullWallet::operator==(const FullWallet& other) const { |
134 if (expiration_month_ != other.expiration_month_) | 159 if (expiration_month_ != other.expiration_month_) |
135 return false; | 160 return false; |
(...skipping 24 matching lines...) Expand all Loading... |
160 if (required_actions_ != other.required_actions_) | 185 if (required_actions_ != other.required_actions_) |
161 return false; | 186 return false; |
162 | 187 |
163 return true; | 188 return true; |
164 } | 189 } |
165 | 190 |
166 bool FullWallet::operator!=(const FullWallet& other) const { | 191 bool FullWallet::operator!=(const FullWallet& other) const { |
167 return !(*this == other); | 192 return !(*this == other); |
168 } | 193 } |
169 | 194 |
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() { | 195 void FullWallet::DecryptCardInfo() { |
183 std::vector<uint8> operating_data; | 196 std::vector<uint8> operating_data; |
184 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. | 197 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. |
185 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { | 198 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { |
186 DLOG(ERROR) << "Failed to parse encrypted rest"; | 199 DLOG(ERROR) << "Failed to parse encrypted rest"; |
187 return; | 200 return; |
188 } | 201 } |
189 | 202 |
190 // Ensure |one_time_pad_| and |encrypted_rest_| are of the same length | 203 // 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. | 204 // otherwise something has gone wrong and we can't decrypt the data. |
(...skipping 21 matching lines...) Expand all Loading... |
213 // to be padded with 0's until it is. | 226 // to be padded with 0's until it is. |
214 if (card_info.size() != padded_length) | 227 if (card_info.size() != padded_length) |
215 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); | 228 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
216 | 229 |
217 // Separate out the PAN from the CVN. | 230 // Separate out the PAN from the CVN. |
218 size_t split = kPanSize - kBinSize; | 231 size_t split = kPanSize - kBinSize; |
219 cvn_ = card_info.substr(split); | 232 cvn_ = card_info.substr(split); |
220 pan_ = iin_ + card_info.substr(0, split); | 233 pan_ = iin_ + card_info.substr(0, split); |
221 } | 234 } |
222 | 235 |
| 236 const std::string& FullWallet::GetPan() { |
| 237 if (pan_.empty()) |
| 238 DecryptCardInfo(); |
| 239 return pan_; |
| 240 } |
| 241 |
| 242 const std::string& FullWallet::GetCvn() { |
| 243 if (cvn_.empty()) |
| 244 DecryptCardInfo(); |
| 245 return cvn_; |
| 246 } |
| 247 |
223 } // namespace wallet | 248 } // namespace wallet |
224 } // namespace autofill | 249 } // namespace autofill |
OLD | NEW |