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 string16 FullWallet::GetInfo(AutofillFieldType type) { |
| 140 switch (type) { |
| 141 case CREDIT_CARD_NUMBER: |
| 142 return UTF8ToUTF16(GetPan()); |
| 143 |
| 144 case CREDIT_CARD_NAME: |
| 145 return billing_address()->recipient_name(); |
| 146 |
| 147 case CREDIT_CARD_VERIFICATION_CODE: |
| 148 return UTF8ToUTF16(GetCvn()); |
| 149 |
| 150 case CREDIT_CARD_EXP_MONTH: |
| 151 return base::IntToString16(expiration_month()); |
| 152 |
| 153 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 154 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: |
| 155 return base::IntToString16(expiration_year()); |
| 156 |
| 157 default: |
| 158 NOTREACHED(); |
| 159 } |
| 160 |
| 161 return string16(); |
| 162 } |
| 163 |
126 bool FullWallet::HasRequiredAction(RequiredAction action) const { | 164 bool FullWallet::HasRequiredAction(RequiredAction action) const { |
127 DCHECK(ActionAppliesToFullWallet(action)); | 165 DCHECK(ActionAppliesToFullWallet(action)); |
128 return std::find(required_actions_.begin(), | 166 return std::find(required_actions_.begin(), |
129 required_actions_.end(), | 167 required_actions_.end(), |
130 action) != required_actions_.end(); | 168 action) != required_actions_.end(); |
131 } | 169 } |
132 | 170 |
133 bool FullWallet::operator==(const FullWallet& other) const { | 171 bool FullWallet::operator==(const FullWallet& other) const { |
134 if (expiration_month_ != other.expiration_month_) | 172 if (expiration_month_ != other.expiration_month_) |
135 return false; | 173 return false; |
(...skipping 24 matching lines...) Expand all Loading... |
160 if (required_actions_ != other.required_actions_) | 198 if (required_actions_ != other.required_actions_) |
161 return false; | 199 return false; |
162 | 200 |
163 return true; | 201 return true; |
164 } | 202 } |
165 | 203 |
166 bool FullWallet::operator!=(const FullWallet& other) const { | 204 bool FullWallet::operator!=(const FullWallet& other) const { |
167 return !(*this == other); | 205 return !(*this == other); |
168 } | 206 } |
169 | 207 |
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() { | 208 void FullWallet::DecryptCardInfo() { |
183 std::vector<uint8> operating_data; | 209 std::vector<uint8> operating_data; |
184 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. | 210 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. |
185 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { | 211 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { |
186 DLOG(ERROR) << "Failed to parse encrypted rest"; | 212 DLOG(ERROR) << "Failed to parse encrypted rest"; |
187 return; | 213 return; |
188 } | 214 } |
189 | 215 |
190 // Ensure |one_time_pad_| and |encrypted_rest_| are of the same length | 216 // 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. | 217 // 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'); | 241 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
216 | 242 |
217 // Separate out the PAN from the CVN. | 243 // Separate out the PAN from the CVN. |
218 size_t split = kPanSize - kBinSize; | 244 size_t split = kPanSize - kBinSize; |
219 cvn_ = card_info.substr(split); | 245 cvn_ = card_info.substr(split); |
220 pan_ = iin_ + card_info.substr(0, split); | 246 pan_ = iin_ + card_info.substr(0, split); |
221 } | 247 } |
222 | 248 |
223 } // namespace wallet | 249 } // namespace wallet |
224 } // namespace autofill | 250 } // namespace autofill |
OLD | NEW |