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 const std::string& FullWallet::GetPan() { |
| 128 if (pan_.empty()) |
| 129 DecryptCardInfo(); |
| 130 return pan_; |
| 131 } |
| 132 |
| 133 const std::string& FullWallet::GetCvn() { |
| 134 if (cvn_.empty()) |
| 135 DecryptCardInfo(); |
| 136 return cvn_; |
| 137 } |
| 138 |
| 139 const wallet::Address* FullWallet::GetAddress(bool is_billing) const { |
| 140 return is_billing ? billing_address() : shipping_address(); |
| 141 } |
| 142 |
| 143 string16 FullWallet::GetInfo(AutofillFieldType type, bool is_billing) { |
| 144 switch (type) { |
| 145 case CREDIT_CARD_NUMBER: |
| 146 DCHECK(is_billing); |
| 147 return UTF8ToUTF16(GetPan()); |
| 148 |
| 149 case CREDIT_CARD_NAME: |
| 150 DCHECK(is_billing); |
| 151 return billing_address()->recipient_name(); |
| 152 |
| 153 case CREDIT_CARD_VERIFICATION_CODE: |
| 154 DCHECK(is_billing); |
| 155 return UTF8ToUTF16(GetCvn()); |
| 156 |
| 157 case CREDIT_CARD_EXP_MONTH: |
| 158 DCHECK(is_billing); |
| 159 return base::IntToString16(expiration_month()); |
| 160 |
| 161 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 162 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: |
| 163 DCHECK(is_billing); |
| 164 return base::IntToString16(expiration_year()); |
| 165 |
| 166 case NAME_FULL: |
| 167 return GetAddress(is_billing)->recipient_name(); |
| 168 |
| 169 case ADDRESS_HOME_LINE1: |
| 170 return GetAddress(is_billing)->address_line_1(); |
| 171 |
| 172 case ADDRESS_HOME_LINE2: |
| 173 return GetAddress(is_billing)->address_line_2(); |
| 174 |
| 175 case ADDRESS_HOME_CITY: |
| 176 return GetAddress(is_billing)->locality_name(); |
| 177 |
| 178 case ADDRESS_HOME_STATE: |
| 179 return GetAddress(is_billing)->administrative_area_name(); |
| 180 |
| 181 case ADDRESS_HOME_ZIP: |
| 182 return GetAddress(is_billing)->postal_code_number(); |
| 183 |
| 184 case ADDRESS_HOME_COUNTRY: |
| 185 return UTF8ToUTF16(GetAddress(is_billing)->country_name_code()); |
| 186 |
| 187 case PHONE_HOME_WHOLE_NUMBER: |
| 188 return GetAddress(is_billing)->phone_number(); |
| 189 |
| 190 default: |
| 191 NOTREACHED(); |
| 192 } |
| 193 |
| 194 return string16(); |
| 195 } |
| 196 |
126 bool FullWallet::HasRequiredAction(RequiredAction action) const { | 197 bool FullWallet::HasRequiredAction(RequiredAction action) const { |
127 DCHECK(ActionAppliesToFullWallet(action)); | 198 DCHECK(ActionAppliesToFullWallet(action)); |
128 return std::find(required_actions_.begin(), | 199 return std::find(required_actions_.begin(), |
129 required_actions_.end(), | 200 required_actions_.end(), |
130 action) != required_actions_.end(); | 201 action) != required_actions_.end(); |
131 } | 202 } |
132 | 203 |
133 bool FullWallet::operator==(const FullWallet& other) const { | 204 bool FullWallet::operator==(const FullWallet& other) const { |
134 if (expiration_month_ != other.expiration_month_) | 205 if (expiration_month_ != other.expiration_month_) |
135 return false; | 206 return false; |
(...skipping 24 matching lines...) Expand all Loading... |
160 if (required_actions_ != other.required_actions_) | 231 if (required_actions_ != other.required_actions_) |
161 return false; | 232 return false; |
162 | 233 |
163 return true; | 234 return true; |
164 } | 235 } |
165 | 236 |
166 bool FullWallet::operator!=(const FullWallet& other) const { | 237 bool FullWallet::operator!=(const FullWallet& other) const { |
167 return !(*this == other); | 238 return !(*this == other); |
168 } | 239 } |
169 | 240 |
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() { | 241 void FullWallet::DecryptCardInfo() { |
183 std::vector<uint8> operating_data; | 242 std::vector<uint8> operating_data; |
184 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. | 243 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. |
185 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { | 244 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { |
186 DLOG(ERROR) << "Failed to parse encrypted rest"; | 245 DLOG(ERROR) << "Failed to parse encrypted rest"; |
187 return; | 246 return; |
188 } | 247 } |
189 | 248 |
190 // Ensure |one_time_pad_| and |encrypted_rest_| are of the same length | 249 // 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. | 250 // otherwise something has gone wrong and we can't decrypt the data. |
(...skipping 23 matching lines...) Expand all Loading... |
215 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); | 274 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
216 | 275 |
217 // Separate out the PAN from the CVN. | 276 // Separate out the PAN from the CVN. |
218 size_t split = kPanSize - kBinSize; | 277 size_t split = kPanSize - kBinSize; |
219 cvn_ = card_info.substr(split); | 278 cvn_ = card_info.substr(split); |
220 pan_ = iin_ + card_info.substr(0, split); | 279 pan_ = iin_ + card_info.substr(0, split); |
221 } | 280 } |
222 | 281 |
223 } // namespace wallet | 282 } // namespace wallet |
224 } // namespace autofill | 283 } // namespace autofill |
OLD | NEW |