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

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

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes from Dane's review Created 8 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autofill/wallet/full_wallet.h"
6
7 #include "base/logging.h"
8 #include "base/string_number_conversions.h"
9 #include "base/values.h"
10
11
12 namespace {
13
14 size_t kPanSize = 16;
15 size_t kBinSize = 6;
16 size_t kCvnSize = 3;
benquan 2012/12/15 02:48:59 Are these constants always true? Some credit card
ahutter 2012/12/17 17:23:02 These are specific to our proxy cards.
17
18 } // end anonymous namespace
19
20 namespace wallet {
21
22 FullWallet::FullWallet(int expiration_month,
23 int expiration_year,
24 const std::string& iin,
25 const std::string& rest,
Raman Kakilate 2012/11/17 02:28:31 should we call out that this value is otp-crypted
ahutter 2012/11/27 00:46:12 Done.
26 Address* billing_address,
27 Address* shipping_address,
28 std::vector<std::string> required_actions)
benquan 2012/12/15 02:48:59 this should be const reference
ahutter 2012/12/17 17:23:02 It is in the most recent CL.
29 : expiration_month_(expiration_month),
30 expiration_year_(expiration_year),
31 iin_(iin),
32 rest_(rest),
33 billing_address_(billing_address),
34 shipping_address_(shipping_address),
35 required_actions_(required_actions) {}
36
37 FullWallet::~FullWallet() {
38 }
39
40 FullWallet* FullWallet::CreateFromDictionary(DictionaryValue* dictionary) {
41 DCHECK(dictionary);
42 ListValue* required_actions_list;
43 std::vector<std::string> required_actions;
44 if (dictionary->GetList("required_action", &required_actions_list)) {
45 for (size_t i = 0; i < required_actions_list->GetSize(); i++) {
46 std::string action;
47 if (required_actions_list->GetString(i, &action))
48 required_actions.push_back(action);
49 }
50 if (required_actions.size() > 0) {
51 return new FullWallet(-1, -1, "", "", NULL, NULL, required_actions);
52 }
53 } else {
54 VLOG(1) << "Response from Google wallet missing required actions";
55 }
56
57 int expiration_month;
58 if (!dictionary->GetInteger("expiration_month", &expiration_month)) {
59 LOG(ERROR) << "Response from Google wallet missing expiration month";
60 return NULL;
61 }
62 int expiration_year;
63 if (!dictionary->GetInteger("expiration_year", &expiration_year)) {
64 LOG(ERROR) << "Response from Google wallet missing expiration year";
65 return NULL;
66 }
67 std::string iin;
68 if (!dictionary->GetString("iin", &iin)) {
69 LOG(ERROR) << "Response from Google wallet missing iin";
70 return NULL;
71 }
72 std::string rest;
73 if (!dictionary->GetString("rest", &rest)) {
74 LOG(ERROR) << "Response from Google wallet missing rest";
75 return NULL;
76 }
77 DictionaryValue* billing_address_dict;
78 if (!dictionary->GetDictionary("billing_address", &billing_address_dict)) {
79 LOG(ERROR) << "Response from Google wallet missing billing address";
80 return NULL;
81 }
82 Address* billing_address =
83 Address::CreateFromIdedDictionary(billing_address_dict);
84 if (!billing_address) {
85 LOG(ERROR) << "Response from Google wallet has malformed billing address";
86 return NULL;
87 }
88
89 DictionaryValue* shipping_address_dict;
90 Address* shipping_address;
91 if (dictionary->GetDictionary("shipping_address", &shipping_address_dict)) {
92 shipping_address =
93 Address::CreateFromIdedDictionary(shipping_address_dict);
94 } else {
95 VLOG(1) << "Response from Google wallet missing shipping address";
96 }
97
98 return new FullWallet(expiration_month,
99 expiration_year,
100 iin,
101 rest,
102 billing_address,
103 shipping_address,
104 required_actions);
105 }
106
107 bool FullWallet::operator==(const FullWallet& other) const {
108 if (expiration_month_ != other.expiration_month_)
109 return false;
110 if (expiration_year_ != other.expiration_year_)
111 return false;
112 if (iin_.compare(other.iin_) != 0)
113 return false;
114 if (rest_.compare(other.rest_) != 0)
115 return false;
116 if (billing_address_.get() && other.billing_address_.get()) {
117 if (*billing_address_.get() != *other.billing_address_.get())
118 return false;
119 } else if (billing_address_.get() || other.billing_address_.get()) {
120 return false;
121 }
122 if (shipping_address_.get() && other.shipping_address_.get()) {
123 if (*shipping_address_.get() != *other.shipping_address_.get())
124 return false;
125 } else if (shipping_address_.get() || other.shipping_address_.get()) {
126 return false;
127 }
128 if (required_actions_ != other.required_actions_)
129 return false;
130 return true;
131 }
132
133 bool FullWallet::operator!=(const FullWallet& other) const {
134 return !(*this == other);
135 }
136
137 std::ostream& operator<<(std::ostream& o,
138 const FullWallet& full_wallet) {
139 o << "Expiration month : " << full_wallet.expiration_month_ << std::endl;
140 o << "Expiration year : " << full_wallet.expiration_year_ << std::endl;
141 o << "Iin : " << full_wallet.iin_ << std::endl;
142 o << "Rest : " << full_wallet.rest_ << std::endl;
143 o << "Billing address : " << full_wallet.billing_address_ << std::endl;
144 o << "Shipping address : " << full_wallet.shipping_address_ << std::endl;
145 // o << "Required actions : " << full_wallet.required_actions_ << std::endl;
146 return o;
147 }
Raman Kakilate 2012/11/17 02:28:31 Do we need this in final code ?
ahutter 2012/11/27 00:46:12 Removing.
148
149 const std::string FullWallet::GetPAN(void* otp, size_t length) const {
150 std::vector<uint8> operating_data;
151 if (!base::HexStringToBytes(rest_, &operating_data)) {
152 LOG(ERROR) << "Failed to parse rest";
153 return "";
154 }
155 CHECK_EQ(length, operating_data.size());
Raman Kakilate 2012/11/17 02:28:31 Do we have to crash chrome ?
ahutter 2012/11/27 00:46:12 Probably not.
156 char* result = new char[length];
157 char* otp_thing = (char*) otp;
Raman Kakilate 2012/11/17 02:28:31 What not just char* in param ?
ahutter 2012/11/27 00:46:12 Done.
158 for (size_t i = 0; i < length; i++)
159 result[i] = static_cast<uint8>(otp_thing[i]) ^ operating_data[i];
160 std::string hex_decrypted = base::HexEncode(result, length);
161 delete[] result;
162 int64 decrypted;
163 if (!base::HexStringToInt64(hex_decrypted, &decrypted)) {
164 LOG(ERROR) << "Failed to parse decrypted";
165 return "";
166 }
Raman Kakilate 2012/11/17 02:28:31 Extract this block of code to a private method ?..
ahutter 2012/11/27 00:46:12 Done.
167 std::string card_info = base::Int64ToString(decrypted);
168
169 size_t padded_length = (kPanSize - kBinSize + kCvnSize);
170 if (card_info.size() != padded_length)
171 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0');
172
173 size_t split = kPanSize - kBinSize;
174 return iin_ + card_info.substr(0, split);
175 }
176
177 const std::string FullWallet::GetCVN(void* otp, size_t length) const {
178 std::vector<uint8> operating_data;
179 if (!base::HexStringToBytes(rest_, &operating_data)) {
180 LOG(ERROR) << "Failed to parse rest";
181 return "";
182 }
183 CHECK_EQ(length, operating_data.size());
184 char* result = new char[length];
185 char* otp_thing = (char*) otp;
186 for (size_t i = 0; i < length; i++)
187 result[i] = static_cast<uint8>(otp_thing[i]) ^ operating_data[i];
188 std::string hex_decrypted = base::HexEncode(result, length);
189 delete[] result;
190 int64 decrypted;
191 if (!base::HexStringToInt64(hex_decrypted, &decrypted)) {
192 LOG(ERROR) << "Failed to parse decrypted";
193 return "";
194 }
195 std::string card_info = base::Int64ToString(decrypted);
196
197 size_t padded_length = (kPanSize - kBinSize + kCvnSize);
198 if (card_info.size() != padded_length)
199 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0');
200
201 size_t split = kPanSize - kBinSize;
Raman Kakilate 2012/11/17 02:28:31 Why do we do this in a getter ? GetPAN and GetCVN
ahutter 2012/11/27 00:46:12 I was being lazy. Fixed.
202 return card_info.substr(split);
203 }
204
205 } // end wallet namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698